Skip to content

Commit

Permalink
feat(post): recognize and parse blocked post
Browse files Browse the repository at this point in the history
Closes #160
  • Loading branch information
realth000 committed Jan 14, 2025
1 parent a28cee2 commit 3fd9a40
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 4 additions & 0 deletions lib/i18n/zh-CN.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,10 @@
"title": "仅对作者可见",
"detail(rich)": "该部分内容仅对$author可见",
"detailAuthor": "作者"
},
"blocked": {
"title": "内容被屏蔽",
"detail": "此楼层已被管理员或版主屏蔽"
}
},
"rateCard": {
Expand Down
4 changes: 4 additions & 0 deletions lib/i18n/zh-TW.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,10 @@
"title": "僅對作者可見",
"detail(rich)": "該部分內容僅對$author可見",
"detailAuthor": "作者"
},
"blocked": {
"title": "內容被屏蔽",
"detail": "此樓層已被管理員或版主封鎖"
}
},
"rateCard": {
Expand Down
18 changes: 17 additions & 1 deletion lib/shared/models/locked.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ sealed class _LockedInfo extends Equatable {

const factory _LockedInfo.author() = _LockedWithAuthor;

const factory _LockedInfo.banned() = _LockedWithBlocked;

@override
List<Object?> get props => [];
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions lib/widgets/card/lock_card/locked_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ class _LockedCardState extends State<LockedCard> {
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',
Expand Down

0 comments on commit 3fd9a40

Please sign in to comment.