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