diff --git a/src/global/actions/api/messages.ts b/src/global/actions/api/messages.ts index 868d646cb..efaa50745 100644 --- a/src/global/actions/api/messages.ts +++ b/src/global/actions/api/messages.ts @@ -820,7 +820,7 @@ async function loadViewportMessages( let global = getGlobal(); const localMessages = chatId === SERVICE_NOTIFICATIONS_USER_ID - ? global.serviceNotifications.filter((notification) => !notification.isHidden).map(({ message }) => message) + ? global.serviceNotifications.filter(({ isDeleted }) => !isDeleted).map(({ message }) => message) : []; const allMessages = ([] as ApiMessage[]).concat(messages, localMessages); const byId = buildCollectionByKey(allMessages, 'id'); diff --git a/src/global/actions/api/sync.ts b/src/global/actions/api/sync.ts index c093bfd44..a45ae5ba0 100644 --- a/src/global/actions/api/sync.ts +++ b/src/global/actions/api/sync.ts @@ -106,7 +106,7 @@ async function loadAndReplaceMessages() { if (result && newCurrentChatId === currentChatId) { const currentMessageListInfo = global.messages.byChatId[currentChatId]; const localMessages = currentChatId === SERVICE_NOTIFICATIONS_USER_ID - ? global.serviceNotifications.filter((notification) => !notification.isHidden).map(({ message }) => message) + ? global.serviceNotifications.filter(({ isDeleted }) => !isDeleted).map(({ message }) => message) : []; const allMessages = ([] as ApiMessage[]).concat(result.messages, localMessages); const byId = buildCollectionByKey(allMessages, 'id'); diff --git a/src/global/actions/apiUpdaters/messages.ts b/src/global/actions/apiUpdaters/messages.ts index 5e1312d9d..ef02818bc 100644 --- a/src/global/actions/apiUpdaters/messages.ts +++ b/src/global/actions/apiUpdaters/messages.ts @@ -349,15 +349,12 @@ addActionHandler('apiUpdate', (global, actions, update) => { const { chatId } = update; const chatMessages = global.messages.byChatId[chatId]; if (chatId === SERVICE_NOTIFICATIONS_USER_ID) { - const lastNotification = global.serviceNotifications.sort((a, b) => b.id - a.id)?.[0]; - const serviceNotifications = lastNotification ? [{ - ...lastNotification, - isHidden: true, - }] : []; - setGlobal({ ...global, - serviceNotifications, + serviceNotifications: global.serviceNotifications.map((notification) => ({ + ...notification, + isDeleted: true, + })), }); } diff --git a/src/global/cache.ts b/src/global/cache.ts index 744657644..a155b4b1f 100644 --- a/src/global/cache.ts +++ b/src/global/cache.ts @@ -289,7 +289,7 @@ export function migrateCache(cached: GlobalState, initialState: GlobalState) { }; } - // TODO This was re-designed but can be hardcoded in cache + // TODO Remove in Jan 2023 (this was re-designed but can be hardcoded in cache) const { light: lightTheme } = cached.settings.themes; if (lightTheme?.patternColor === 'rgba(90, 110, 70, 0.6)' || !lightTheme?.patternColor) { cached.settings.themes.light = { @@ -297,6 +297,13 @@ export function migrateCache(cached: GlobalState, initialState: GlobalState) { patternColor: DEFAULT_PATTERN_COLOR, }; } + + cached.serviceNotifications.forEach((notification) => { + const { isHidden } = notification as any; + if (isHidden) { + notification.isDeleted = isHidden; + } + }); } function updateCache() { diff --git a/src/global/selectors/messages.ts b/src/global/selectors/messages.ts index aec749cd0..675dc1eed 100644 --- a/src/global/selectors/messages.ts +++ b/src/global/selectors/messages.ts @@ -897,7 +897,7 @@ export function selectLastServiceNotification(global: GlobalState) { const { serviceNotifications } = global; const maxId = Math.max(...serviceNotifications.map(({ id }) => id)); - return serviceNotifications.find(({ id, isHidden }) => !isHidden && id === maxId); + return serviceNotifications.find(({ id, isDeleted }) => !isDeleted && id === maxId); } export function selectIsMessageProtected(global: GlobalState, message?: ApiMessage) { diff --git a/src/global/types.ts b/src/global/types.ts index a29396f49..10f396653 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -123,7 +123,7 @@ export interface ServiceNotification { message: ApiMessage; version?: string; isUnread?: boolean; - isHidden?: boolean; + isDeleted?: boolean; } export type ApiLimitType = ( diff --git a/src/util/folderManager.ts b/src/util/folderManager.ts index d2da01484..cdebe082f 100644 --- a/src/util/folderManager.ts +++ b/src/util/folderManager.ts @@ -427,7 +427,9 @@ function buildChatSummary( } = chat; const userInfo = type === 'chatTypePrivate' && user; - const shouldHideServiceChat = chat.id === SERVICE_NOTIFICATIONS_USER_ID && !chat.lastMessage; + const shouldHideServiceChat = chat.id === SERVICE_NOTIFICATIONS_USER_ID && ( + !chat.lastMessage || chat.lastMessage.content.action?.type === 'historyClear' + ); return { id,