From c50d85a6a1d54b4cfbf013d3599be18dfad80be0 Mon Sep 17 00:00:00 2001 From: nyne Date: Sat, 29 Nov 2025 14:57:00 +0800 Subject: [PATCH] feat: implement comment blocking based on user-defined keywords --- lib/pages/reader/chapter_comments.dart | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/pages/reader/chapter_comments.dart b/lib/pages/reader/chapter_comments.dart index 27dab10..eef8db2 100644 --- a/lib/pages/reader/chapter_comments.dart +++ b/lib/pages/reader/chapter_comments.dart @@ -1,5 +1,18 @@ 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 { const ChapterCommentsPage({ super.key, @@ -44,8 +57,9 @@ class _ChapterCommentsPageState extends State { _loading = false; }); } else if (mounted) { + var filteredComments = res.data.where((c) => !_shouldBlockComment(c)).toList(); setState(() { - _comments = res.data; + _comments = filteredComments; _loading = false; maxPage = res.subData; }); @@ -62,8 +76,9 @@ class _ChapterCommentsPageState extends State { if (res.error) { context.showMessage(message: res.errorMessage ?? "Unknown Error"); } else { + var filteredComments = res.data.where((c) => !_shouldBlockComment(c)).toList(); setState(() { - _comments!.addAll(res.data); + _comments!.addAll(filteredComments); _page++; if (maxPage == null && res.data.isEmpty) { maxPage = _page;