diff --git a/src/api/gramjs/methods/messages.ts b/src/api/gramjs/methods/messages.ts index cbb9312f2..daef0d0e6 100644 --- a/src/api/gramjs/methods/messages.ts +++ b/src/api/gramjs/methods/messages.ts @@ -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({ diff --git a/src/api/gramjs/methods/reactions.ts b/src/api/gramjs/methods/reactions.ts index 0ca204aca..feb2453bc 100644 --- a/src/api/gramjs/methods/reactions.ts +++ b/src/api/gramjs/methods/reactions.ts @@ -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, + }); }); } diff --git a/src/components/middle/MessageList.tsx b/src/components/middle/MessageList.tsx index 10cd90c09..c3bc09f02 100644 --- a/src/components/middle/MessageList.tsx +++ b/src/components/middle/MessageList.tsx @@ -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; diff --git a/src/config.ts b/src/config.ts index 4ffce59a6..f6ba718e6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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; diff --git a/src/global/actions/api/messages.ts b/src/global/actions/api/messages.ts index d4b91dddb..cf0154b60 100644 --- a/src/global/actions/api/messages.ts +++ b/src/global/actions/api/messages.ts @@ -1724,7 +1724,9 @@ addActionHandler('loadMessageViews', async (global, actions, payload): Promise { + 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,