From b1a46046536cfa42d163f26aced3c508de4602de Mon Sep 17 00:00:00 2001
From: Paul <paulmakles@gmail.com>
Date: Tue, 22 Jun 2021 18:01:03 +0100
Subject: [PATCH] Send ack PUTs for unreads.

---
 src/components/navigation/left/common.ts |  5 +++--
 src/context/revoltjs/events.ts           |  3 +--
 src/lib/ContextMenus.tsx                 | 19 ++++++++++++-------
 src/redux/reducers/unreads.ts            |  5 -----
 4 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/components/navigation/left/common.ts b/src/components/navigation/left/common.ts
index 208f795..12d8f9b 100644
--- a/src/components/navigation/left/common.ts
+++ b/src/components/navigation/left/common.ts
@@ -25,9 +25,10 @@ export function useUnreads({ channel, unreads, dispatcher }: UnreadProps, contex
                     dispatcher({
                         type: "UNREADS_MARK_READ",
                         channel: channel._id,
-                        message,
-                        request: true
+                        message
                     });
+                    
+                    ctx.client.req('PUT', `/channels/${channel._id}/ack/${message}` as '/channels/id/ack/id');
                 }
             }
         }
diff --git a/src/context/revoltjs/events.ts b/src/context/revoltjs/events.ts
index fea22e7..b6fba62 100644
--- a/src/context/revoltjs/events.ts
+++ b/src/context/revoltjs/events.ts
@@ -62,8 +62,7 @@ export function registerEvents({
                     dispatcher({
                         type: "UNREADS_MARK_READ",
                         channel: packet.id,
-                        message: packet.message_id,
-                        request: false
+                        message: packet.message_id
                     });
                     break;
                 }
diff --git a/src/lib/ContextMenus.tsx b/src/lib/ContextMenus.tsx
index 80797e2..73e5403 100644
--- a/src/lib/ContextMenus.tsx
+++ b/src/lib/ContextMenus.tsx
@@ -91,13 +91,18 @@ function ContextMenus(props: WithDispatcher) {
                     writeClipboard(document.getSelection()?.toString() ?? '');
                     break;
                 case "mark_as_read":
-                    if (data.channel.channel_type === 'SavedMessages') return;
-                    props.dispatcher({
-                        type: "UNREADS_MARK_READ",
-                        channel: data.channel._id,
-                        message: data.channel.channel_type === 'TextChannel' ? data.channel.last_message : data.channel.last_message._id,
-                        request: true
-                    });
+                    {
+                        if (data.channel.channel_type === 'SavedMessages') return;
+
+                        let message = data.channel.channel_type === 'TextChannel' ? data.channel.last_message : data.channel.last_message._id;
+                        props.dispatcher({
+                            type: "UNREADS_MARK_READ",
+                            channel: data.channel._id,
+                            message
+                        });
+
+                        client.req('PUT', `/channels/${data.channel._id}/ack/${message}` as '/channels/id/ack/id');
+                    }
                     break;
 
                 case "retry_message":
diff --git a/src/redux/reducers/unreads.ts b/src/redux/reducers/unreads.ts
index f7f640a..290afdc 100644
--- a/src/redux/reducers/unreads.ts
+++ b/src/redux/reducers/unreads.ts
@@ -10,7 +10,6 @@ export type UnreadsAction =
           type: "UNREADS_MARK_READ";
           channel: string;
           message: string;
-          request: boolean;
       }
     | {
           type: "UNREADS_SET";
@@ -28,10 +27,6 @@ export type UnreadsAction =
 export function unreads(state = {} as Unreads, action: UnreadsAction): Unreads {
     switch (action.type) {
         case "UNREADS_MARK_READ":
-            if (action.request) {
-                // client.req('PUT', `/channels/${action.channel}/ack/${action.message}` as '/channels/id/ack/id');
-            }
-
             return {
                 ...state,
                 [action.channel]: {
-- 
GitLab