From 3fd9a40c903c251f0a5aea440ba037cdd22a6c0d Mon Sep 17 00:00:00 2001 From: realth000 Date: Tue, 14 Jan 2025 23:46:04 +0800 Subject: [PATCH] feat(post): recognize and parse blocked post Closes #160 --- lib/i18n/en.i18n.json | 4 ++++ lib/i18n/zh-CN.i18n.json | 4 ++++ lib/i18n/zh-TW.i18n.json | 4 ++++ lib/shared/models/locked.dart | 18 +++++++++++++++++- lib/widgets/card/lock_card/locked_card.dart | 3 +++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/i18n/en.i18n.json b/lib/i18n/en.i18n.json index dfc8ddb1..1e3a4c36 100644 --- a/lib/i18n/en.i18n.json +++ b/lib/i18n/en.i18n.json @@ -578,6 +578,10 @@ "title": "Only visible to the thread author", "detail(rich)": "This content only visible to $author", "detailAuthor": "author" + }, + "blocked": { + "title": "Blocked content", + "detail": "This post has been blocked by administrator or moderator" } }, "rateCard": { diff --git a/lib/i18n/zh-CN.i18n.json b/lib/i18n/zh-CN.i18n.json index 8bc7d7fd..571fa9ac 100644 --- a/lib/i18n/zh-CN.i18n.json +++ b/lib/i18n/zh-CN.i18n.json @@ -578,6 +578,10 @@ "title": "仅对作者可见", "detail(rich)": "该部分内容仅对$author可见", "detailAuthor": "作者" + }, + "blocked": { + "title": "内容被屏蔽", + "detail": "此楼层已被管理员或版主屏蔽" } }, "rateCard": { diff --git a/lib/i18n/zh-TW.i18n.json b/lib/i18n/zh-TW.i18n.json index 1dc08c63..71bdf27a 100644 --- a/lib/i18n/zh-TW.i18n.json +++ b/lib/i18n/zh-TW.i18n.json @@ -578,6 +578,10 @@ "title": "僅對作者可見", "detail(rich)": "該部分內容僅對$author可見", "detailAuthor": "作者" + }, + "blocked": { + "title": "內容被屏蔽", + "detail": "此樓層已被管理員或版主封鎖" } }, "rateCard": { diff --git a/lib/shared/models/locked.dart b/lib/shared/models/locked.dart index 63dbece5..835e54d8 100644 --- a/lib/shared/models/locked.dart +++ b/lib/shared/models/locked.dart @@ -19,6 +19,8 @@ sealed class _LockedInfo extends Equatable { const factory _LockedInfo.author() = _LockedWithAuthor; + const factory _LockedInfo.banned() = _LockedWithBlocked; + @override List get props => []; } @@ -75,6 +77,11 @@ final class _LockedWithAuthor extends _LockedInfo { const _LockedWithAuthor() : super._(); } +/// This section is blocked by admin or moderator. +final class _LockedWithBlocked extends _LockedInfo { + const _LockedWithBlocked() : super._(); +} + /// Describe a locked area in `Post`. /// /// Different types may be locked with different reasons: @@ -122,6 +129,9 @@ class Locked extends Equatable { /// Is it only visible to the author and forum moderator. bool get lockedWithAuthor => _info != null && _info is _LockedWithAuthor; + /// Is it blocked by moderator. + bool get lockedWithBlocked => _info != null && _info is _LockedWithBlocked; + /// Get the tid of current locked model. String? get tid { if (_info == null) { @@ -236,6 +246,10 @@ class Locked extends Equatable { final pid = match?.namedGroup('pid'); if (tid == null || pid == null || price == null || purchasedCount == null) { + if (element.innerText.contains('该帖被管理员或版主屏蔽')) { + return const _LockedInfo.banned(); + } + if (!allowWithPoints) { // Do not allow locked area that locked with points here. return null; @@ -279,7 +293,9 @@ class Locked extends Equatable { if (_info is _LockedWithPurchase) { return _info.price > 0 && tid != null && pid != null; } - if (_info is _LockedWithPoints || _info is _LockedWithAuthor) { + if (_info is _LockedWithPoints || + _info is _LockedWithAuthor || + _info is _LockedWithBlocked) { return true; } return false; diff --git a/lib/widgets/card/lock_card/locked_card.dart b/lib/widgets/card/lock_card/locked_card.dart index 7859dc82..03f4a10c 100644 --- a/lib/widgets/card/lock_card/locked_card.dart +++ b/lib/widgets/card/lock_card/locked_card.dart @@ -216,6 +216,9 @@ class _LockedCardState extends State { style: secondaryStyle, ), ]); + } else if (widget.locked.lockedWithBlocked) { + title = Text(tr.blocked.title, style: primaryStyle); + widgets.add(Text(tr.blocked.detail)); } else { throw UnimplementedError( 'Widget for card type of locked card not implemented',