Support deleting service chat with Telegram (#1867)
This commit is contained in:
parent
b660b37a7b
commit
f43a2bd57f
@ -197,6 +197,7 @@ export const COUNTRIES_WITH_12H_TIME_FORMAT = new Set(['AU', 'BD', 'CA', 'CO', '
|
||||
|
||||
// MTProto constants
|
||||
export const SERVICE_NOTIFICATIONS_USER_ID = '777000';
|
||||
export const SERVICE_NOTIFICATIONS_NUMBER = '42777';
|
||||
export const REPLIES_USER_ID = '1271266957'; // TODO For Test connection ID must be equal to 708513
|
||||
export const ALL_FOLDER_ID = 0;
|
||||
export const ARCHIVED_FOLDER_ID = 1;
|
||||
|
||||
@ -15,7 +15,7 @@ import {
|
||||
CHAT_LIST_LOAD_SLICE,
|
||||
RE_TG_LINK,
|
||||
SERVICE_NOTIFICATIONS_USER_ID,
|
||||
TMP_CHAT_ID, ALL_FOLDER_ID, DEBUG,
|
||||
TMP_CHAT_ID, ALL_FOLDER_ID, DEBUG, SERVICE_NOTIFICATIONS_NUMBER,
|
||||
} from '../../../config';
|
||||
import { callApi } from '../../../api/gramjs';
|
||||
import {
|
||||
@ -1068,14 +1068,14 @@ async function loadChats(
|
||||
listType: 'active' | 'archived', offsetId?: string, offsetDate?: number, shouldReplace = false,
|
||||
) {
|
||||
let global = getGlobal();
|
||||
|
||||
const lastLocalServiceMessage = selectLastServiceNotification(global)?.message;
|
||||
const result = await callApi('fetchChats', {
|
||||
limit: CHAT_LIST_LOAD_SLICE,
|
||||
offsetDate,
|
||||
archived: listType === 'archived',
|
||||
withPinned: shouldReplace,
|
||||
serverTimeOffset: global.serverTimeOffset,
|
||||
lastLocalServiceMessage: selectLastServiceNotification(global)?.message,
|
||||
lastLocalServiceMessage,
|
||||
});
|
||||
|
||||
if (!result) {
|
||||
@ -1091,6 +1091,18 @@ async function loadChats(
|
||||
global = getGlobal();
|
||||
|
||||
if (shouldReplace && listType === 'active') {
|
||||
// Always include service notifications chat
|
||||
if (!chatIds.includes(SERVICE_NOTIFICATIONS_USER_ID)) {
|
||||
const chat = await callApi('getChatByPhoneNumber', SERVICE_NOTIFICATIONS_NUMBER);
|
||||
global = getGlobal();
|
||||
if (chat) {
|
||||
chatIds.unshift(chat.id);
|
||||
result.chats.unshift(chat);
|
||||
if (lastLocalServiceMessage) {
|
||||
chat.lastMessage = lastLocalServiceMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
const currentChat = selectCurrentChat(global);
|
||||
const visibleChats = currentChat ? [currentChat] : [];
|
||||
|
||||
|
||||
@ -4,8 +4,10 @@ import type {
|
||||
ApiChat,
|
||||
ApiMessage, ApiPollResult, ApiReactions, ApiThreadInfo,
|
||||
} from '../../../api/types';
|
||||
import type { ActiveEmojiInteraction, GlobalActions, GlobalState } from '../../types';
|
||||
import { MAIN_THREAD_ID } from '../../../api/types';
|
||||
|
||||
import { SERVICE_NOTIFICATIONS_USER_ID } from '../../../config';
|
||||
import { unique } from '../../../util/iteratees';
|
||||
import { areDeepEqual } from '../../../util/areDeepEqual';
|
||||
import { notifyAboutMessage } from '../../../util/notifications';
|
||||
@ -21,7 +23,6 @@ import {
|
||||
deleteChatScheduledMessages,
|
||||
updateThreadUnreadFromForwardedMessage,
|
||||
} from '../../reducers';
|
||||
import type { ActiveEmojiInteraction, GlobalActions, GlobalState } from '../../types';
|
||||
import {
|
||||
selectChatMessage,
|
||||
selectChatMessages,
|
||||
@ -346,9 +347,22 @@ addActionHandler('apiUpdate', (global, actions, update) => {
|
||||
case 'deleteHistory': {
|
||||
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,
|
||||
});
|
||||
}
|
||||
|
||||
if (chatMessages) {
|
||||
const ids = Object.keys(chatMessages.byId).map(Number);
|
||||
deleteMessages(chatId, ids, actions, global);
|
||||
deleteMessages(chatId, ids, actions, getGlobal());
|
||||
} else {
|
||||
actions.requestChatUpdate({ chatId });
|
||||
}
|
||||
|
||||
@ -894,7 +894,7 @@ export function selectLastServiceNotification(global: GlobalState) {
|
||||
const { serviceNotifications } = global;
|
||||
const maxId = Math.max(...serviceNotifications.map(({ id }) => id));
|
||||
|
||||
return serviceNotifications.find(({ id }) => id === maxId);
|
||||
return serviceNotifications.find(({ id, isHidden }) => !isHidden && id === maxId);
|
||||
}
|
||||
|
||||
export function selectIsMessageProtected(global: GlobalState, message?: ApiMessage) {
|
||||
|
||||
@ -122,6 +122,7 @@ export interface ServiceNotification {
|
||||
message: ApiMessage;
|
||||
version?: string;
|
||||
isUnread?: boolean;
|
||||
isHidden?: boolean;
|
||||
}
|
||||
|
||||
export type ApiLimitType = (
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user