Pinned Chats: Update pinned chats after sleep (#5985)
This commit is contained in:
parent
4281b219a0
commit
39ca8ce15f
@ -2,6 +2,7 @@ import BigInt from 'big-integer';
|
|||||||
import { Api as GramJs } from '../../../lib/gramjs';
|
import { Api as GramJs } from '../../../lib/gramjs';
|
||||||
import { RPCError } from '../../../lib/gramjs/errors';
|
import { RPCError } from '../../../lib/gramjs/errors';
|
||||||
|
|
||||||
|
import type { ChatListType } from '../../../types';
|
||||||
import type {
|
import type {
|
||||||
ApiChat,
|
ApiChat,
|
||||||
ApiChatAdminRights,
|
ApiChatAdminRights,
|
||||||
@ -1081,6 +1082,29 @@ export async function fetchChatFolders() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function fetchPinnedDialogs({
|
||||||
|
listType,
|
||||||
|
}: {
|
||||||
|
listType: ChatListType;
|
||||||
|
}) {
|
||||||
|
const result = await invokeRequest(new GramJs.messages.GetPinnedDialogs({
|
||||||
|
folderId: listType === 'archived' ? ARCHIVED_FOLDER_ID : undefined,
|
||||||
|
}));
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { dialogs, messages, chats, users } = result;
|
||||||
|
|
||||||
|
return {
|
||||||
|
dialogIds: dialogs.map((dialog) => getApiChatIdFromMtpPeer(dialog.peer)),
|
||||||
|
messages: messages.map((message) => buildApiMessage(message)).filter(Boolean),
|
||||||
|
chats: chats.map((chat) => buildApiChatFromPreview(chat)).filter(Boolean),
|
||||||
|
users: users.map((user) => buildApiUser(user)).filter(Boolean),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchRecommendedChatFolders() {
|
export async function fetchRecommendedChatFolders() {
|
||||||
const results = await invokeRequest(new GramJs.messages.GetSuggestedDialogFilters());
|
const results = await invokeRequest(new GramJs.messages.GetSuggestedDialogFilters());
|
||||||
|
|
||||||
|
|||||||
@ -531,11 +531,9 @@ export function updater(update: Update) {
|
|||||||
isPinned: update.pinned || false,
|
isPinned: update.pinned || false,
|
||||||
});
|
});
|
||||||
} else if (update instanceof GramJs.UpdatePinnedDialogs) {
|
} else if (update instanceof GramJs.UpdatePinnedDialogs) {
|
||||||
const ids = update.order
|
const ids = update.order?.filter(
|
||||||
? update.order
|
(dp): dp is GramJs.DialogPeer => dp instanceof GramJs.DialogPeer)
|
||||||
.filter((dp): dp is GramJs.DialogPeer => dp instanceof GramJs.DialogPeer)
|
.map((dp) => getApiChatIdFromMtpPeer(dp.peer));
|
||||||
.map((dp) => getApiChatIdFromMtpPeer(dp.peer))
|
|
||||||
: [];
|
|
||||||
|
|
||||||
sendApiUpdate({
|
sendApiUpdate({
|
||||||
'@type': 'updatePinnedChatIds',
|
'@type': 'updatePinnedChatIds',
|
||||||
|
|||||||
@ -165,7 +165,7 @@ export type ApiUpdateChatMembers = {
|
|||||||
|
|
||||||
export type ApiUpdatePinnedChatIds = {
|
export type ApiUpdatePinnedChatIds = {
|
||||||
'@type': 'updatePinnedChatIds';
|
'@type': 'updatePinnedChatIds';
|
||||||
ids: string[];
|
ids?: string[];
|
||||||
folderId?: number;
|
folderId?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -542,6 +542,35 @@ addActionHandler('loadAllChats', async (global, actions, payload): Promise<void>
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addActionHandler('loadPinnedDialogs', async (global, actions, payload): Promise<void> => {
|
||||||
|
const {
|
||||||
|
listType,
|
||||||
|
} = payload;
|
||||||
|
|
||||||
|
const result = await callApi('fetchPinnedDialogs', { listType });
|
||||||
|
if (!result) return;
|
||||||
|
|
||||||
|
const { dialogIds, messages, chats, users } = result;
|
||||||
|
|
||||||
|
global = getGlobal();
|
||||||
|
global = updateChats(global, buildCollectionByKey(chats, 'id'));
|
||||||
|
global = updateUsers(global, buildCollectionByKey(users, 'id'));
|
||||||
|
global = replaceMessages(global, messages);
|
||||||
|
|
||||||
|
global = {
|
||||||
|
...global,
|
||||||
|
chats: {
|
||||||
|
...global.chats,
|
||||||
|
orderedPinnedIds: {
|
||||||
|
...global.chats.orderedPinnedIds,
|
||||||
|
[listType]: dialogIds.length ? dialogIds : undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
setGlobal(global);
|
||||||
|
});
|
||||||
|
|
||||||
addActionHandler('loadFullChat', (global, actions, payload): ActionReturnType => {
|
addActionHandler('loadFullChat', (global, actions, payload): ActionReturnType => {
|
||||||
const {
|
const {
|
||||||
chatId, force, withPhotos,
|
chatId, force, withPhotos,
|
||||||
|
|||||||
@ -242,6 +242,10 @@ addActionHandler('apiUpdate', (global, actions, update): ActionReturnType => {
|
|||||||
case 'updatePinnedChatIds': {
|
case 'updatePinnedChatIds': {
|
||||||
const { ids, folderId } = update;
|
const { ids, folderId } = update;
|
||||||
const listType = folderId === ARCHIVED_FOLDER_ID ? 'archived' : 'active';
|
const listType = folderId === ARCHIVED_FOLDER_ID ? 'archived' : 'active';
|
||||||
|
if (!ids) {
|
||||||
|
actions.loadPinnedDialogs({ listType });
|
||||||
|
return global;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...global,
|
...global,
|
||||||
|
|||||||
@ -345,6 +345,9 @@ export interface ActionPayloads {
|
|||||||
listType: ChatListType;
|
listType: ChatListType;
|
||||||
whenFirstBatchDone?: () => Promise<void>;
|
whenFirstBatchDone?: () => Promise<void>;
|
||||||
};
|
};
|
||||||
|
loadPinnedDialogs: {
|
||||||
|
listType: ChatListType;
|
||||||
|
};
|
||||||
openChatWithInfo: ActionPayloads['openChat'] & {
|
openChatWithInfo: ActionPayloads['openChat'] & {
|
||||||
profileTab?: ProfileTabType;
|
profileTab?: ProfileTabType;
|
||||||
forceScrollProfileTab?: boolean;
|
forceScrollProfileTab?: boolean;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user