Delete Member: Fix deleteChatMember method (#6171)

This commit is contained in:
Alexander Zinchuk 2025-08-29 08:58:03 +02:00
parent b9e5d2100b
commit d42ff4566f
3 changed files with 48 additions and 39 deletions

View File

@ -1564,42 +1564,12 @@ export async function addChatMembers(chat: ApiChat, users: ApiUser[]) {
} }
export function deleteChatMember(chat: ApiChat, user: ApiUser) { export function deleteChatMember(chat: ApiChat, user: ApiUser) {
if (chat.type === 'chatTypeChannel' || chat.type === 'chatTypeSuperGroup') { return invokeRequest(new GramJs.messages.DeleteChatUser({
return updateChatMemberBannedRights({ chatId: buildInputChat(chat.id),
chat, userId: buildInputUser(user.id, user.accessHash),
user, }), {
bannedRights: { shouldReturnTrue: true,
viewMessages: true, });
sendMessages: true,
sendMedia: true,
sendStickers: true,
sendGifs: true,
sendGames: true,
sendInline: true,
embedLinks: true,
sendPolls: true,
changeInfo: true,
inviteUsers: true,
pinMessages: true,
manageTopics: true,
sendPhotos: true,
sendVideos: true,
sendRoundvideos: true,
sendAudios: true,
sendVoices: true,
sendDocs: true,
sendPlain: true,
},
untilDate: MAX_INT_32,
});
} else {
return invokeRequest(new GramJs.messages.DeleteChatUser({
chatId: buildInputChat(chat.id),
userId: buildInputUser(user.id, user.accessHash),
}), {
shouldReturnTrue: true,
});
}
} }
export function toggleJoinToSend(chat: ApiChat, isEnabled: boolean) { export function toggleJoinToSend(chat: ApiChat, isEnabled: boolean) {

View File

@ -1857,7 +1857,11 @@ addActionHandler('updateChatMemberBannedRights', async (global, actions, payload
if (!chat) return; if (!chat) return;
await callApi('updateChatMemberBannedRights', { chat, user, bannedRights }); const result = await callApi('updateChatMemberBannedRights', { chat, user, bannedRights });
if (!result) {
return;
}
global = getGlobal(); global = getGlobal();
@ -1886,6 +1890,10 @@ addActionHandler('updateChatMemberBannedRights', async (global, actions, payload
kickedMembers: kickedMembers.filter((m) => m.userId !== userId), kickedMembers: kickedMembers.filter((m) => m.userId !== userId),
}), }),
}); });
if (isBanned) {
global = updateChat(global, chat.id, { membersCount: Math.max(0, (chat.membersCount || 0) - 1) });
}
setGlobal(global); setGlobal(global);
}); });
@ -2181,7 +2189,7 @@ addActionHandler('addChatMembers', async (global, actions, payload): Promise<voi
}); });
addActionHandler('deleteChatMember', async (global, actions, payload): Promise<void> => { addActionHandler('deleteChatMember', async (global, actions, payload): Promise<void> => {
const { chatId, userId } = payload; const { chatId, userId, tabId = getCurrentTabId() } = payload;
const chat = selectChat(global, chatId); const chat = selectChat(global, chatId);
const user = selectUser(global, userId); const user = selectUser(global, userId);
@ -2189,6 +2197,37 @@ addActionHandler('deleteChatMember', async (global, actions, payload): Promise<v
return; return;
} }
if (isChatSuperGroup(chat) || isChatChannel(chat)) {
actions.updateChatMemberBannedRights({
chatId,
userId,
bannedRights: {
viewMessages: true,
sendMessages: true,
sendMedia: true,
sendStickers: true,
sendGifs: true,
sendGames: true,
sendInline: true,
embedLinks: true,
sendPolls: true,
changeInfo: true,
inviteUsers: true,
pinMessages: true,
manageTopics: true,
sendPhotos: true,
sendVideos: true,
sendRoundvideos: true,
sendAudios: true,
sendVoices: true,
sendDocs: true,
sendPlain: true,
},
tabId,
});
return;
}
await callApi('deleteChatMember', chat, user); await callApi('deleteChatMember', chat, user);
global = getGlobal(); global = getGlobal();
loadFullChat(global, actions, chat); loadFullChat(global, actions, chat);

View File

@ -334,7 +334,7 @@ export interface ActionPayloads {
deleteChatMember: { deleteChatMember: {
chatId: string; chatId: string;
userId: string; userId: string;
}; } & WithTabId;
openPreviousChat: WithTabId | undefined; openPreviousChat: WithTabId | undefined;
editChatFolders: { editChatFolders: {
chatId: string; chatId: string;