From 6fd1b9f309649696b15e123fc4c00efd5bdac4d4 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sat, 15 May 2021 00:53:28 +0300 Subject: [PATCH] Message List: Fixes for detecting unread messages --- src/api/gramjs/apiBuilders/chats.ts | 1 + src/modules/selectors/messages.ts | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/api/gramjs/apiBuilders/chats.ts b/src/api/gramjs/apiBuilders/chats.ts index fa595c368..cb0ab9de5 100644 --- a/src/api/gramjs/apiBuilders/chats.ts +++ b/src/api/gramjs/apiBuilders/chats.ts @@ -126,6 +126,7 @@ function buildApiChatRestrictions(peerEntity: GramJs.TypeUser | GramJs.TypeChat) && peerEntity.restrictionReason.some((reason) => reason.platform === 'all'); return { + // `left` is weirdly set to `true` on all channels never joined before isNotJoined: peerEntity.left, isRestricted, restrictionReason: buildApiChatRestrictionReason(peerEntity.restrictionReason), diff --git a/src/modules/selectors/messages.ts b/src/modules/selectors/messages.ts index c08785694..0950eaeb1 100644 --- a/src/modules/selectors/messages.ts +++ b/src/modules/selectors/messages.ts @@ -499,8 +499,9 @@ export function selectRealLastReadId(global: GlobalState, chatId: number, thread } export function selectFirstUnreadId(global: GlobalState, chatId: number, threadId: number) { + const chat = selectChat(global, chatId); + if (threadId === MAIN_THREAD_ID) { - const chat = selectChat(global, chatId); if (!chat) { return undefined; } @@ -519,12 +520,12 @@ export function selectFirstUnreadId(global: GlobalState, chatId: number, threadI } const lastReadId = selectRealLastReadId(global, chatId, threadId); - if (!lastReadId) { + if (!lastReadId && chat && chat.isNotJoined) { return undefined; } if (outlyingIds) { - const found = outlyingIds.find((id) => { + const found = !lastReadId ? outlyingIds[0] : outlyingIds.find((id) => { return id > lastReadId && byId[id] && (!byId[id].isOutgoing || byId[id].isFromScheduled); }); if (found) { @@ -533,7 +534,7 @@ export function selectFirstUnreadId(global: GlobalState, chatId: number, threadI } if (listedIds) { - const found = listedIds.find((id) => { + const found = !lastReadId ? listedIds[0] : listedIds.find((id) => { return id > lastReadId && byId[id] && (!byId[id].isOutgoing || byId[id].isFromScheduled); }); if (found) {