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) {
if (chat.type === 'chatTypeChannel' || chat.type === 'chatTypeSuperGroup') {
return updateChatMemberBannedRights({
chat,
user,
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,
},
untilDate: MAX_INT_32,
});
} else {
return invokeRequest(new GramJs.messages.DeleteChatUser({
chatId: buildInputChat(chat.id),
userId: buildInputUser(user.id, user.accessHash),
}), {
shouldReturnTrue: true,
});
}
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) {

View File

@ -1857,7 +1857,11 @@ addActionHandler('updateChatMemberBannedRights', async (global, actions, payload
if (!chat) return;
await callApi('updateChatMemberBannedRights', { chat, user, bannedRights });
const result = await callApi('updateChatMemberBannedRights', { chat, user, bannedRights });
if (!result) {
return;
}
global = getGlobal();
@ -1886,6 +1890,10 @@ addActionHandler('updateChatMemberBannedRights', async (global, actions, payload
kickedMembers: kickedMembers.filter((m) => m.userId !== userId),
}),
});
if (isBanned) {
global = updateChat(global, chat.id, { membersCount: Math.max(0, (chat.membersCount || 0) - 1) });
}
setGlobal(global);
});
@ -2181,7 +2189,7 @@ addActionHandler('addChatMembers', async (global, actions, payload): Promise<voi
});
addActionHandler('deleteChatMember', async (global, actions, payload): Promise<void> => {
const { chatId, userId } = payload;
const { chatId, userId, tabId = getCurrentTabId() } = payload;
const chat = selectChat(global, chatId);
const user = selectUser(global, userId);
@ -2189,6 +2197,37 @@ addActionHandler('deleteChatMember', async (global, actions, payload): Promise<v
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);
global = getGlobal();
loadFullChat(global, actions, chat);

View File

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