From 7e92a27a37d0c0fc78c4b790a4070cffa03cdaf4 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 16 May 2022 13:34:35 +0200 Subject: [PATCH] Management / Join Requests: Fix scroll, fix missing users (#1878) --- src/api/gramjs/methods/management.ts | 8 +++- .../right/management/ManageJoinRequests.tsx | 38 +++++++++---------- src/global/actions/api/management.ts | 28 +++++++++----- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/api/gramjs/methods/management.ts b/src/api/gramjs/methods/management.ts index c8ab6d69..32231807 100644 --- a/src/api/gramjs/methods/management.ts +++ b/src/api/gramjs/methods/management.ts @@ -5,6 +5,8 @@ import { buildInputEntity, buildInputPeer } from '../gramjsBuilders'; import { ApiChat, ApiUser, OnApiUpdate } from '../../types'; import { addEntitiesWithPhotosToLocalDb } from '../helpers'; import { buildApiExportedInvite, buildChatInviteImporter } from '../apiBuilders/chats'; +import { buildApiUser } from '../apiBuilders/users'; +import { buildCollectionByKey } from '../../../util/iteratees'; let onUpdate: OnApiUpdate; @@ -183,8 +185,12 @@ export async function fetchChatInviteImporters({ })); if (!result) return undefined; + const users = result.users.map((user) => buildApiUser(user)).filter(Boolean); addEntitiesWithPhotosToLocalDb(result.users); - return result.importers.map((importer) => buildChatInviteImporter(importer)); + return { + importers: result.importers.map((importer) => buildChatInviteImporter(importer)), + users: buildCollectionByKey(users, 'id'), + }; } export function hideChatJoinRequest({ diff --git a/src/components/right/management/ManageJoinRequests.tsx b/src/components/right/management/ManageJoinRequests.tsx index 3c2584e2..fc4fcf28 100644 --- a/src/components/right/management/ManageJoinRequests.tsx +++ b/src/components/right/management/ManageJoinRequests.tsx @@ -77,27 +77,27 @@ const ManageJoinRequests: FC = ({ return (
-
-
- {animationData && ( - +
+
+
+ {animationData && ( + + )} +
+ {Boolean(chat?.joinRequests?.length) && ( +
+ + +
)}
- {Boolean(chat?.joinRequests?.length) && ( -
- - -
- )} -
-
-
+

{!chat?.joinRequests ? lang('Loading') : chat.joinRequests.length ? lang('JoinRequests', chat.joinRequests.length) : lang('NoMemberRequests')} diff --git a/src/global/actions/api/management.ts b/src/global/actions/api/management.ts index 8791b4d1..c14637f7 100644 --- a/src/global/actions/api/management.ts +++ b/src/global/actions/api/management.ts @@ -2,7 +2,9 @@ import { addActionHandler, getGlobal, setGlobal } from '../../index'; import { ManagementProgress } from '../../../types'; import { callApi } from '../../../api/gramjs'; -import { updateChat, updateManagement, updateManagementProgress } from '../../reducers'; +import { + addUsers, updateChat, updateManagement, updateManagementProgress, +} from '../../reducers'; import { selectChat, selectCurrentMessageList, selectUser } from '../../selectors'; import { isChatBasicGroup } from '../../helpers'; @@ -234,6 +236,7 @@ addActionHandler('loadChatInviteImporters', async (global, actions, payload) => if (!result) { return; } + const { importers, users } = result; global = getGlobal(); const currentInviteInfo = global.management.byChatId[chatId]?.inviteInfo; @@ -241,12 +244,14 @@ addActionHandler('loadChatInviteImporters', async (global, actions, payload) => return; } - setGlobal(updateManagement(global, chatId, { + global = updateManagement(global, chatId, { inviteInfo: { ...currentInviteInfo, - importers: result, + importers, }, - })); + }); + global = addUsers(global, users); + setGlobal(global); }); addActionHandler('loadChatInviteRequesters', async (global, actions, payload) => { @@ -268,19 +273,21 @@ addActionHandler('loadChatInviteRequesters', async (global, actions, payload) => if (!result) { return; } + const { importers, users } = result; global = getGlobal(); const currentInviteInfo = global.management.byChatId[chatId]?.inviteInfo; if (!currentInviteInfo?.invite || currentInviteInfo.invite.link !== link) { return; } - - setGlobal(updateManagement(global, chatId, { + global = updateManagement(global, chatId, { inviteInfo: { ...currentInviteInfo, - requesters: result, + requesters: importers, }, - })); + }); + global = addUsers(global, users); + setGlobal(global); }); addActionHandler('loadChatJoinRequests', async (global, actions, payload) => { @@ -301,9 +308,12 @@ addActionHandler('loadChatJoinRequests', async (global, actions, payload) => { if (!result) { return; } + const { importers, users } = result; global = getGlobal(); - setGlobal(updateChat(global, chatId, { joinRequests: result })); + global = updateChat(global, chatId, { joinRequests: importers }); + global = addUsers(global, users); + setGlobal(global); }); addActionHandler('hideChatJoinRequest', async (global, actions, payload) => {