Skip to content

Commit

Permalink
feat(notification): Support parsing new friend notices
Browse files Browse the repository at this point in the history
  • Loading branch information
realth000 committed Feb 4, 2024
1 parent de4ea01 commit bf3c251
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* 帖子右上角菜单 -> 倒序浏览/正序浏览。
- 新增支持从好友邀请参与话题的消息跳转到相应帖子。
- 新增支持筛选帖子。
- 新增支持查看新添加的好友的提醒。~~虽然加好友请求的提醒还没做~~
- 在首页和我的页面内提醒有未读的消息。
* 有提醒时显示提醒数量,只有短消息时显示红点。
* 默认开启,可在设置中关闭。
Expand Down
15 changes: 15 additions & 0 deletions lib/features/notification/models/notice.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ enum NoticeType {

/// Another user invited the current user to take part in specified thread.
invite,

/// Another user has became the friend of current user.
///
/// xxx 和您成为了好友
newFriend,
}

/// A single notice for current user.
Expand Down Expand Up @@ -137,6 +142,8 @@ class Notice extends Equatable {
noticeType = NoticeType.mention;
} else if (litNode?.attributes['href']?.contains('&tid=') ?? false) {
noticeType = NoticeType.invite;
} else if (element.querySelectorAll('dd.ntc_body > a').length == 1) {
noticeType = NoticeType.newFriend;
} else {
noticeType = NoticeType.reply;
}
Expand Down Expand Up @@ -166,6 +173,9 @@ class Notice extends Equatable {
: n?.substring(usernameBeginOffset, usernameEndOffset);
redirectUrl = a1Node?.firstHref();
quotedMessage = mentionNode!.firstEndDeepText()?.trim();
} else if (noticeType == NoticeType.newFriend) {
username = a1Node?.firstEndDeepText();
userSpaceUrl = a1Node?.attributes['href'];
} else {
noticeThreadTitle = a1Node?.firstEndDeepText();
redirectUrl = a1Node?.firstHref()?.prependHost();
Expand All @@ -190,6 +200,11 @@ class Notice extends Equatable {
);
return null;
}
} else if (noticeType == NoticeType.newFriend) {
if (username == null || userSpaceUrl == null) {
debug('failed to parse new friend notice: $username, $userSpaceUrl');
return null;
}
} else if (username == null ||
userSpaceUrl == null ||
noticeTime == null ||
Expand Down
4 changes: 3 additions & 1 deletion lib/features/notification/view/notification_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class _NoticeDetailPage extends State<NoticeDetailPage> {
NoticeType.reply => context.t.noticePage.noticeDetailPage.titleReply,
NoticeType.rate => context.t.noticePage.noticeDetailPage.titleRate,
NoticeType.mention => context.t.noticePage.noticeDetailPage.titleMention,
NoticeType.invite => '', // No detail page for invites, impossible.
NoticeType.invite ||
NoticeType.newFriend =>
'', // No detail page for invites, impossible.
};
return MultiBlocProvider(
providers: [
Expand Down
3 changes: 2 additions & 1 deletion lib/i18n/strings.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@
"replyBody": "replied in $threadTitle",
"rateBody": "scored your thread in $threadTitle $score",
"mentionBody": "mentioned you in thread",
"inviteBody": "invite you to participate in the topic $threadTitle"
"inviteBody": "invite you to participate in the topic $threadTitle",
"newFriendBody": "became your friend"
},
"messageTab": {
"title": "Messages"
Expand Down
3 changes: 2 additions & 1 deletion lib/i18n/strings_zh-CN.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@
"replyBody": "在 $threadTitle 中回复了",
"rateBody": "在 $threadTitle 中给您的帖子评分 $score",
"mentionBody": "在帖子中提到了你",
"inviteBody": "邀请您参与话题 $threadTitle"
"inviteBody": "邀请您参与话题 $threadTitle",
"newFriendBody": "和您成为了好友"
},
"messageTab": {
"title": "消息"
Expand Down
3 changes: 2 additions & 1 deletion lib/i18n/strings_zh-TW.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@
"replyBody": "在 $threadTitle 中回覆了",
"rateBody": "在 $threadTitle 中給您的帖子評分 $score",
"mentionBody": "在話題中提到了你",
"inviteBody": "邀請您參與話題 $threadTitle"
"inviteBody": "邀請您參與話題 $threadTitle",
"newFriendBody": "和您成為好友了"
},
"messageTab": {
"title": "訊息"
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/card/notice_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class NoticeCard extends StatelessWidget {
context.t.noticePage.noticeTab
.inviteBody(threadTitle: notice.noticeThreadTitle ?? ''),
),
NoticeType.newFriend =>
Text(context.t.noticePage.noticeTab.newFriendBody),
};

return Card(
Expand Down

0 comments on commit bf3c251

Please sign in to comment.