Follow-up

This commit is contained in:
Alexander Zinchuk 2022-09-21 01:10:41 +02:00
parent fcdfcecfed
commit 0ee0304b87
7 changed files with 19 additions and 13 deletions

View File

@ -820,7 +820,7 @@ async function loadViewportMessages(
let global = getGlobal(); let global = getGlobal();
const localMessages = chatId === SERVICE_NOTIFICATIONS_USER_ID 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 allMessages = ([] as ApiMessage[]).concat(messages, localMessages);
const byId = buildCollectionByKey(allMessages, 'id'); const byId = buildCollectionByKey(allMessages, 'id');

View File

@ -106,7 +106,7 @@ async function loadAndReplaceMessages() {
if (result && newCurrentChatId === currentChatId) { if (result && newCurrentChatId === currentChatId) {
const currentMessageListInfo = global.messages.byChatId[currentChatId]; const currentMessageListInfo = global.messages.byChatId[currentChatId];
const localMessages = currentChatId === SERVICE_NOTIFICATIONS_USER_ID 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 allMessages = ([] as ApiMessage[]).concat(result.messages, localMessages);
const byId = buildCollectionByKey(allMessages, 'id'); const byId = buildCollectionByKey(allMessages, 'id');

View File

@ -349,15 +349,12 @@ addActionHandler('apiUpdate', (global, actions, update) => {
const { chatId } = update; const { chatId } = update;
const chatMessages = global.messages.byChatId[chatId]; const chatMessages = global.messages.byChatId[chatId];
if (chatId === SERVICE_NOTIFICATIONS_USER_ID) { 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({ setGlobal({
...global, ...global,
serviceNotifications, serviceNotifications: global.serviceNotifications.map((notification) => ({
...notification,
isDeleted: true,
})),
}); });
} }

View File

@ -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; const { light: lightTheme } = cached.settings.themes;
if (lightTheme?.patternColor === 'rgba(90, 110, 70, 0.6)' || !lightTheme?.patternColor) { if (lightTheme?.patternColor === 'rgba(90, 110, 70, 0.6)' || !lightTheme?.patternColor) {
cached.settings.themes.light = { cached.settings.themes.light = {
@ -297,6 +297,13 @@ export function migrateCache(cached: GlobalState, initialState: GlobalState) {
patternColor: DEFAULT_PATTERN_COLOR, patternColor: DEFAULT_PATTERN_COLOR,
}; };
} }
cached.serviceNotifications.forEach((notification) => {
const { isHidden } = notification as any;
if (isHidden) {
notification.isDeleted = isHidden;
}
});
} }
function updateCache() { function updateCache() {

View File

@ -897,7 +897,7 @@ export function selectLastServiceNotification(global: GlobalState) {
const { serviceNotifications } = global; const { serviceNotifications } = global;
const maxId = Math.max(...serviceNotifications.map(({ id }) => id)); 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) { export function selectIsMessageProtected(global: GlobalState, message?: ApiMessage) {

View File

@ -123,7 +123,7 @@ export interface ServiceNotification {
message: ApiMessage; message: ApiMessage;
version?: string; version?: string;
isUnread?: boolean; isUnread?: boolean;
isHidden?: boolean; isDeleted?: boolean;
} }
export type ApiLimitType = ( export type ApiLimitType = (

View File

@ -427,7 +427,9 @@ function buildChatSummary(
} = chat; } = chat;
const userInfo = type === 'chatTypePrivate' && user; 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 { return {
id, id,