From 28b86e9c24bbdb0eed8c6591a434a08b44086f2b Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Tue, 5 Apr 2022 09:00:45 -0400 Subject: [PATCH] Use delta for mark as unread (#6127) --- app/actions/websocket/posts.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/actions/websocket/posts.ts b/app/actions/websocket/posts.ts index 747baae3d..34462cd05 100644 --- a/app/actions/websocket/posts.ts +++ b/app/actions/websocket/posts.ts @@ -255,7 +255,7 @@ export async function handlePostDeleted(serverUrl: string, msg: WebSocketMessage } export async function handlePostUnread(serverUrl: string, msg: WebSocketMessage) { - const {channel_id: channelId} = msg.broadcast; + const {channel_id: channelId, team_id: teamId} = msg.broadcast; const {mention_count: mentionCount, msg_count: msgCount, last_viewed_at: lastViewedAt} = msg.data; const database = DatabaseManager.serverDatabases[serverUrl]?.database; if (!database) { @@ -264,8 +264,10 @@ export async function handlePostUnread(serverUrl: string, msg: WebSocketMessage) const myChannel = await getMyChannel(database, channelId); if (!myChannel?.manuallyUnread) { - // We used to fetch the channel to get the delta on the message count - // We just need to identify that there are unread messages, the exact number is uninportant - markChannelAsUnread(serverUrl, channelId, msgCount, mentionCount, lastViewedAt); + const {channels} = await fetchMyChannel(serverUrl, teamId, channelId, true); + const channel = channels?.[0]; + const postNumber = channel?.total_msg_count; + const delta = postNumber ? postNumber - msgCount : msgCount; + markChannelAsUnread(serverUrl, channelId, delta, mentionCount, lastViewedAt); } }