GramJS: Limit max id count per request for some methods (#4043)
This commit is contained in:
parent
76629db59f
commit
19d3bf6953
@ -30,6 +30,7 @@ import {
|
||||
|
||||
import {
|
||||
ALL_FOLDER_ID,
|
||||
API_GENERAL_ID_LIMIT,
|
||||
DEBUG, GIF_MIME_TYPE, MAX_INT_32, MENTION_UNREAD_SLICE,
|
||||
PINNED_MESSAGES_LIMIT, REACTION_UNREAD_SLICE,
|
||||
SUPPORTED_IMAGE_CONTENT_TYPES,
|
||||
@ -37,7 +38,7 @@ import {
|
||||
} from '../../../config';
|
||||
import { getEmojiOnlyCountForMessage } from '../../../global/helpers/getEmojiOnlyCountForMessage';
|
||||
import { fetchFile } from '../../../util/files';
|
||||
import { compact } from '../../../util/iteratees';
|
||||
import { compact, split } from '../../../util/iteratees';
|
||||
import { getServerTimeOffset } from '../../../util/serverTime';
|
||||
import { interpolateArray } from '../../../util/waveform';
|
||||
import { buildApiChatFromPreview, buildApiSendAsPeerId } from '../apiBuilders/chats';
|
||||
@ -901,16 +902,23 @@ export async function fetchMessageViews({
|
||||
ids: number[];
|
||||
shouldIncrement?: boolean;
|
||||
}) {
|
||||
const result = await invokeRequest(new GramJs.messages.GetMessagesViews({
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
id: ids,
|
||||
increment: shouldIncrement,
|
||||
}));
|
||||
const chunks = split(ids, API_GENERAL_ID_LIMIT);
|
||||
const results = await Promise.all(chunks.map((chunkIds) => (
|
||||
invokeRequest(new GramJs.messages.GetMessagesViews({
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
id: chunkIds,
|
||||
increment: shouldIncrement,
|
||||
}))
|
||||
)));
|
||||
|
||||
if (!result) return undefined;
|
||||
if (!results || results.find((result) => !result)) return undefined;
|
||||
|
||||
return ids.map((id, index) => {
|
||||
const { views, forwards, replies } = result.views[index];
|
||||
const viewsList = results.flatMap((result) => result!.views);
|
||||
const users = results.flatMap((result) => result!.users);
|
||||
const chats = results.flatMap((result) => result!.chats);
|
||||
|
||||
const viewsInfo = ids.map((id, index) => {
|
||||
const { views, forwards, replies } = viewsList[index];
|
||||
return {
|
||||
id,
|
||||
views,
|
||||
@ -921,6 +929,12 @@ export async function fetchMessageViews({
|
||||
readMaxId: replies?.readMaxId,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
viewsInfo,
|
||||
users: users.map(buildApiUser).filter(Boolean),
|
||||
chats: chats.map((c) => buildApiChatFromPreview(c)).filter(Boolean),
|
||||
};
|
||||
}
|
||||
|
||||
export async function requestThreadInfoUpdate({
|
||||
|
||||
@ -3,7 +3,13 @@ import { Api as GramJs } from '../../../lib/gramjs';
|
||||
|
||||
import type { ApiChat, ApiReaction } from '../../types';
|
||||
|
||||
import { REACTION_LIST_LIMIT, RECENT_REACTIONS_LIMIT, TOP_REACTIONS_LIMIT } from '../../../config';
|
||||
import {
|
||||
API_GENERAL_ID_LIMIT,
|
||||
REACTION_LIST_LIMIT,
|
||||
RECENT_REACTIONS_LIMIT,
|
||||
TOP_REACTIONS_LIMIT,
|
||||
} from '../../../config';
|
||||
import { split } from '../../../util/iteratees';
|
||||
import { buildApiChatFromPreview } from '../apiBuilders/chats';
|
||||
import { buildApiAvailableReaction, buildApiReaction, buildMessagePeerReaction } from '../apiBuilders/reactions';
|
||||
import { buildApiUser } from '../apiBuilders/users';
|
||||
@ -108,12 +114,15 @@ export function fetchMessageReactions({
|
||||
}: {
|
||||
ids: number[]; chat: ApiChat;
|
||||
}) {
|
||||
return invokeRequest(new GramJs.messages.GetMessagesReactions({
|
||||
id: ids,
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
abortControllerChatId: chat.id,
|
||||
const chunks = split(ids, API_GENERAL_ID_LIMIT);
|
||||
chunks.forEach((chunkIds) => {
|
||||
invokeRequest(new GramJs.messages.GetMessagesReactions({
|
||||
id: chunkIds,
|
||||
peer: buildInputPeer(chat.id, chat.accessHash),
|
||||
}), {
|
||||
shouldReturnTrue: true,
|
||||
abortControllerChatId: chat.id,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -120,8 +120,8 @@ type StateProps = {
|
||||
isServiceNotificationsChat?: boolean;
|
||||
};
|
||||
|
||||
const MESSAGE_REACTIONS_POLLING_INTERVAL = 15 * 1000;
|
||||
const MESSAGE_COMMENTS_POLLING_INTERVAL = 15 * 1000;
|
||||
const MESSAGE_REACTIONS_POLLING_INTERVAL = 20 * 1000;
|
||||
const MESSAGE_COMMENTS_POLLING_INTERVAL = 20 * 1000;
|
||||
const MESSAGE_STORY_POLLING_INTERVAL = 5 * 60 * 1000;
|
||||
const BOTTOM_THRESHOLD = 50;
|
||||
const UNREAD_DIVIDER_TOP = 10;
|
||||
|
||||
@ -89,6 +89,7 @@ export const TOPIC_LIST_SENSITIVE_AREA = 600;
|
||||
export const COMMON_CHATS_LIMIT = 100;
|
||||
export const GROUP_CALL_PARTICIPANTS_LIMIT = 100;
|
||||
export const STORY_LIST_LIMIT = 100;
|
||||
export const API_GENERAL_ID_LIMIT = 100;
|
||||
|
||||
export const STORY_VIEWS_MIN_SEARCH = 15;
|
||||
export const STORY_MIN_REACTIONS_SORT = 10;
|
||||
|
||||
@ -1724,7 +1724,9 @@ addActionHandler('loadMessageViews', async (global, actions, payload): Promise<v
|
||||
if (!result) return;
|
||||
|
||||
global = getGlobal();
|
||||
result.forEach((update) => {
|
||||
global = addUsers(global, buildCollectionByKey(result.users, 'id'));
|
||||
global = addChats(global, buildCollectionByKey(result.chats, 'id'));
|
||||
result.viewsInfo.forEach((update) => {
|
||||
global = updateChatMessage(global, chatId, update.id, {
|
||||
views: update.views,
|
||||
forwards: update.forwards,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user