Propagate userMentionId

This commit is contained in:
shilangyu 2021-02-24 22:48:19 +01:00
parent a9dc676ca8
commit 7cc928764b
1 changed files with 30 additions and 4 deletions

View File

@ -32,6 +32,7 @@ class CommentWidget extends HookWidget {
final bool wasVoted;
final bool canBeMarkedAsRead;
final bool hideOnRead;
final int userMentionId;
static const colors = [
Colors.pink,
@ -47,6 +48,7 @@ class CommentWidget extends HookWidget {
this.detached = false,
this.canBeMarkedAsRead = false,
this.hideOnRead = false,
this.userMentionId,
}) : wasVoted =
(commentTree.comment.myVote ?? VoteType.none) != VoteType.none;
@ -64,10 +66,12 @@ class CommentWidget extends HookWidget {
CommentWidget.fromUserMentionView(
UserMentionView userMentionView, {
bool hideOnRead = false,
}) : this.fromCommentView(
CommentView.fromJson(userMentionView.toJson()),
}) : this(
CommentTree(CommentView.fromJson(userMentionView.toJson())),
hideOnRead: hideOnRead,
canBeMarkedAsRead: true,
detached: true,
userMentionId: userMentionView.userMention.id,
);
_showCommentInfo(BuildContext context) {
@ -275,6 +279,7 @@ class CommentWidget extends HookWidget {
_MarkAsRead(
commentTree.comment,
onChanged: (val) => isRead.value = val,
userMentionId: userMentionId,
),
if (detached)
TileAction(
@ -406,8 +411,13 @@ class CommentWidget extends HookWidget {
class _MarkAsRead extends HookWidget {
final CommentView commentView;
final ValueChanged<bool> onChanged;
final int userMentionId;
const _MarkAsRead(this.commentView, {this.onChanged});
const _MarkAsRead(
this.commentView, {
@required this.onChanged,
@required this.userMentionId,
}) : assert(commentView != null);
@override
Widget build(BuildContext context) {
@ -434,10 +444,26 @@ class _MarkAsRead extends HookWidget {
},
);
Future<void> handleMarkMentionAsSeen() => delayedAction<UserMentionView>(
context: context,
delayedLoading: delayedRead,
instanceHost: instanceHost,
query: MarkUserMentionAsRead(
userMentionId: userMentionId,
read: !isRead.value,
auth: accStore.defaultTokenFor(instanceHost)?.raw,
),
onSuccess: (val) {
isRead.value = val.userMention.read;
onChanged?.call(isRead.value);
},
);
return TileAction(
icon: Icons.check,
delayedLoading: delayedRead,
onPressed: handleMarkAsSeen,
onPressed:
userMentionId != null ? handleMarkMentionAsSeen : handleMarkAsSeen,
iconColor: isRead.value ? Theme.of(context).accentColor : null,
tooltip: 'mark as ${isRead.value ? 'un' : ''}read',
);