Use delta for mark as unread (#6127)

This commit is contained in:
Elias Nahum 2022-04-05 09:00:45 -04:00 committed by GitHub
parent 73d23ea515
commit 28b86e9c24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);
}
}