mirror of
https://github.com/venera-app/venera.git
synced 2025-12-16 07:01:16 +00:00
feat: implement comment blocking based on user-defined keywords
This commit is contained in:
@@ -1,5 +1,18 @@
|
|||||||
part of 'reader.dart';
|
part of 'reader.dart';
|
||||||
|
|
||||||
|
bool _shouldBlockComment(Comment comment) {
|
||||||
|
var blockedWords = appdata.settings["blockedCommentWords"] as List;
|
||||||
|
if (blockedWords.isEmpty) return false;
|
||||||
|
|
||||||
|
var content = comment.content.toLowerCase();
|
||||||
|
for (var word in blockedWords) {
|
||||||
|
if (content.contains(word.toString().toLowerCase())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
class ChapterCommentsPage extends StatefulWidget {
|
class ChapterCommentsPage extends StatefulWidget {
|
||||||
const ChapterCommentsPage({
|
const ChapterCommentsPage({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -44,8 +57,9 @@ class _ChapterCommentsPageState extends State<ChapterCommentsPage> {
|
|||||||
_loading = false;
|
_loading = false;
|
||||||
});
|
});
|
||||||
} else if (mounted) {
|
} else if (mounted) {
|
||||||
|
var filteredComments = res.data.where((c) => !_shouldBlockComment(c)).toList();
|
||||||
setState(() {
|
setState(() {
|
||||||
_comments = res.data;
|
_comments = filteredComments;
|
||||||
_loading = false;
|
_loading = false;
|
||||||
maxPage = res.subData;
|
maxPage = res.subData;
|
||||||
});
|
});
|
||||||
@@ -62,8 +76,9 @@ class _ChapterCommentsPageState extends State<ChapterCommentsPage> {
|
|||||||
if (res.error) {
|
if (res.error) {
|
||||||
context.showMessage(message: res.errorMessage ?? "Unknown Error");
|
context.showMessage(message: res.errorMessage ?? "Unknown Error");
|
||||||
} else {
|
} else {
|
||||||
|
var filteredComments = res.data.where((c) => !_shouldBlockComment(c)).toList();
|
||||||
setState(() {
|
setState(() {
|
||||||
_comments!.addAll(res.data);
|
_comments!.addAll(filteredComments);
|
||||||
_page++;
|
_page++;
|
||||||
if (maxPage == null && res.data.isEmpty) {
|
if (maxPage == null && res.data.isEmpty) {
|
||||||
maxPage = _page;
|
maxPage = _page;
|
||||||
|
|||||||
Reference in New Issue
Block a user