From 2b55037b084032dfd98fd4232c1b1c52b437edca Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sat, 19 Mar 2022 21:19:35 +0100 Subject: [PATCH] Update members count from full chat info --- src/api/gramjs/methods/chats.ts | 5 +++++ src/global/actions/api/chats.ts | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/api/gramjs/methods/chats.ts b/src/api/gramjs/methods/chats.ts index 546ad1949..4111eb458 100644 --- a/src/api/gramjs/methods/chats.ts +++ b/src/api/gramjs/methods/chats.ts @@ -339,6 +339,7 @@ async function getFullChatInfo(chatId: string): Promise<{ fullInfo: ApiChatFullInfo; users?: ApiUser[]; groupCall?: Partial; + membersCount?: number; } | undefined> { const result = await invokeRequest(new GramJs.messages.GetFullChat({ chatId: buildInputEntity(chatId) as BigInt.BigInteger, @@ -391,6 +392,7 @@ async function getFullChatInfo(chatId: string): Promise<{ version: 0, participants: {}, } : undefined, + membersCount: members?.length, }; } @@ -402,6 +404,7 @@ async function getFullChannelInfo( fullInfo: ApiChatFullInfo; users?: ApiUser[]; groupCall?: Partial; + membersCount?: number; } | undefined> { const result = await invokeRequest(new GramJs.channels.GetFullChannel({ channel: buildInputEntity(id, accessHash) as GramJs.InputChannel, @@ -430,6 +433,7 @@ async function getFullChannelInfo( requestsPending, recentRequesters, statsDc, + participantsCount, } = result.fullChat; const inviteLink = exportedInvite instanceof GramJs.ChatInviteExported @@ -498,6 +502,7 @@ async function getFullChannelInfo( participantsCount: 0, connectionState: 'disconnected', } : undefined, + membersCount: participantsCount, }; } diff --git a/src/global/actions/api/chats.ts b/src/global/actions/api/chats.ts index af26e8d2a..308ee0d81 100644 --- a/src/global/actions/api/chats.ts +++ b/src/global/actions/api/chats.ts @@ -1079,7 +1079,9 @@ export async function loadFullChat(chat: ApiChat) { return undefined; } - const { users, fullInfo, groupCall } = result; + const { + users, fullInfo, groupCall, membersCount, + } = result; let global = getGlobal(); if (users) { @@ -1097,7 +1099,10 @@ export async function loadFullChat(chat: ApiChat) { ); } - global = updateChat(global, chat.id, { fullInfo }); + global = updateChat(global, chat.id, { + fullInfo, + ...(membersCount && { membersCount }), + }); setGlobal(global);