From 8ec104cb762f58e83fde262ee25c23ddf49730bf Mon Sep 17 00:00:00 2001
From: Dessalines <tyhou13@gmx.com>
Date: Fri, 31 Jan 2020 22:34:08 -0500
Subject: Mostly done eliminating recurring fetches.

---
 ui/src/components/inbox.tsx | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

(limited to 'ui/src/components/inbox.tsx')

diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx
index 5585d84f..5fd9dbdc 100644
--- a/ui/src/components/inbox.tsx
+++ b/ui/src/components/inbox.tsx
@@ -421,11 +421,25 @@ export class Inbox extends Component<any, InboxState> {
       this.sendUnreadCount();
       this.setState(this.state);
     } else if (res.op == UserOperation.CreateComment) {
-      // let res: CommentResponse = msg;
-      // TODO gotta remove this
-      toast(i18n.t('reply_sent'));
-      // this.state.replies.unshift(res.comment); // TODO do this right
-      // this.setState(this.state);
+      let data = res.data as CommentResponse;
+
+      if (data.recipient_ids.includes(UserService.Instance.user.id)) {
+        this.state.replies.unshift(data.comment);
+        this.setState(this.state);
+      } else if (data.comment.creator_id == UserService.Instance.user.id) {
+        toast(i18n.t('reply_sent'));
+      }
+      this.setState(this.state);
+    } else if (res.op == UserOperation.CreatePrivateMessage) {
+      let data = res.data as PrivateMessageResponse;
+
+      if (data.message.recipient_id == UserService.Instance.user.id) {
+        this.state.messages.unshift(data.message);
+        this.setState(this.state);
+      } else if (data.message.creator_id == UserService.Instance.user.id) {
+        toast(i18n.t('message_sent'));
+      }
+      this.setState(this.state);
     } else if (res.op == UserOperation.SaveComment) {
       let data = res.data as CommentResponse;
       let found = this.state.replies.find(c => c.id == data.comment.id);
-- 
cgit v1.2.3

