]> Untitled Git - lemmy-ui.git/commitdiff
ui changes for marking comment as read on reply (#454)
authorLuna <46259660+LunaticHacker@users.noreply.github.com>
Tue, 12 Oct 2021 17:01:49 +0000 (22:31 +0530)
committerGitHub <noreply@github.com>
Tue, 12 Oct 2021 17:01:49 +0000 (13:01 -0400)
* ui changes for marking comment as read on reply

* refactor

src/shared/components/person/inbox.tsx

index 05b75ec7afd54accbed34ed092d57467d15a47cd..be9c32788aa1443735114f2c72b412448c019e59 100644 (file)
@@ -736,6 +736,37 @@ export class Inbox extends Component<any, InboxState> {
         data.comment_view.creator.id ==
         UserService.Instance.myUserInfo.local_user_view.person.id
       ) {
+        // If youre in the unread view, just remove it from the list
+        if (this.state.unreadOrAll == UnreadOrAll.Unread) {
+          this.state.replies = this.state.replies.filter(
+            r => r.comment.id !== data.comment_view.comment.parent_id
+          );
+          this.state.mentions = this.state.mentions.filter(
+            m => m.comment.id !== data.comment_view.comment.parent_id
+          );
+          this.state.combined = this.state.combined.filter(r => {
+            if (this.isMention(r.view))
+              return r.view.comment.id !== data.comment_view.comment.parent_id;
+            else return r.id !== data.comment_view.comment.parent_id;
+          });
+        } else {
+          let mention_found = this.state.mentions.find(
+            i => i.comment.id == data.comment_view.comment.parent_id
+          );
+          if (mention_found) {
+            mention_found.person_mention.read = true;
+          }
+          let reply_found = this.state.replies.find(
+            i => i.comment.id == data.comment_view.comment.parent_id
+          );
+          if (reply_found) {
+            reply_found.comment.read = true;
+          }
+          this.state.combined = this.buildCombined();
+        }
+        this.sendUnreadCount();
+        this.setState(this.state);
+        setupTippy();
         // TODO this seems wrong, you should be using form_id
         toast(i18n.t("reply_sent"));
       }
@@ -794,4 +825,8 @@ export class Inbox extends Component<any, InboxState> {
       ).length
     );
   }
+
+  isMention(view: any): view is PersonMentionView {
+    return (view as PersonMentionView).person_mention !== undefined;
+  }
 }