Chat List: Fix active chat closing on leave/delete (#1249)

This commit is contained in:
Alexander Zinchuk 2021-07-07 23:14:59 +03:00
parent ca8e1f0d7a
commit 16c732879d
4 changed files with 34 additions and 17 deletions

View File

@ -476,14 +476,14 @@ export function joinChannel({
}
export function deleteChatUser({
chatId, user,
chat, user,
}: {
chatId: number; user?: ApiUser;
chat: ApiChat; user: ApiUser;
}) {
const userId = user ? buildInputEntity(user.id, user.accessHash) as GramJs.InputUser : new GramJs.InputUserSelf();
if (chat.type !== 'chatTypeBasicGroup') return undefined;
return invokeRequest(new GramJs.messages.DeleteChatUser({
chatId: buildInputEntity(chatId) as number,
userId,
chatId: buildInputEntity(chat.id, chat.accessHash) as number,
userId: buildInputEntity(user.id, user.accessHash) as GramJs.InputUser,
}), true);
}

View File

@ -37,6 +37,7 @@ type StateProps = {
isPrivateChat: boolean;
isBasicGroup: boolean;
isSuperGroup: boolean;
currentUserId: number | undefined;
canDeleteForAll?: boolean;
contactName?: string;
};
@ -51,6 +52,7 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
isChatWithSelf,
isBasicGroup,
isSuperGroup,
currentUserId,
canDeleteForAll,
contactName,
onClose,
@ -73,7 +75,7 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
if (isPrivateChat) {
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
} else if (isBasicGroup) {
deleteChatUser({ chatId: chat.id });
deleteChatUser({ chatId: chat.id, userId: currentUserId });
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
} else if ((isChannel || isSuperGroup) && !chat.isCreator) {
leaveChannel({ chatId: chat.id });
@ -86,6 +88,7 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
isBasicGroup,
isChannel,
isSuperGroup,
currentUserId,
chat.isCreator,
chat.id,
onClose,
@ -188,6 +191,7 @@ export default memo(withGlobal<OwnProps>(
isChannel: isChatChannel(chat),
isBasicGroup: isChatBasicGroup(chat),
isSuperGroup: isChatSuperGroup(chat),
currentUserId: global.currentUserId,
canDeleteForAll,
contactName,
};

View File

@ -230,16 +230,18 @@ addReducer('joinChannel', (global, actions, payload) => {
addReducer('deleteChatUser', (global, actions, payload) => {
(async () => {
const { chatId, userId } : {chatId: number; userId?: number} = payload!;
const { chatId, userId } : {chatId: number; userId: number} = payload!;
const chat = selectChat(global, chatId);
if (!chat) {
const user = selectUser(global, userId);
if (!chat || !user) {
return;
}
await callApi('deleteChatUser', { chat, user });
const user = userId !== undefined ? selectUser(global, userId) : undefined;
await callApi('deleteChatUser', { chatId: chat.id, user });
actions.openChat({ id: undefined });
const activeChat = selectCurrentMessageList(global);
if (activeChat && activeChat.chatId === chatId && global.currentUserId === userId) {
actions.openChat({ id: undefined });
}
})();
});
@ -247,13 +249,15 @@ addReducer('deleteChat', (global, actions, payload) => {
(async () => {
const { chatId } : {chatId: number } = payload!;
const chat = selectChat(global, chatId);
if (!chat) {
return;
}
await callApi('deleteChat', { chatId: chat.id });
actions.openChat({ id: undefined });
const activeChat = selectCurrentMessageList(global);
if (activeChat && activeChat.chatId === chatId) {
actions.openChat({ id: undefined });
}
})();
});
@ -271,7 +275,10 @@ addReducer('leaveChannel', (global, actions, payload) => {
await callApi('leaveChannel', { channelId, accessHash });
}
actions.openChat({ id: undefined });
const activeChannel = selectCurrentMessageList(global);
if (activeChannel && activeChannel.chatId === chatId) {
actions.openChat({ id: undefined });
}
})();
});
@ -289,7 +296,10 @@ addReducer('deleteChannel', (global, actions, payload) => {
await callApi('deleteChannel', { channelId, accessHash });
}
actions.openChat({ id: undefined });
const activeChannel = selectCurrentMessageList(global);
if (activeChannel && activeChannel.chatId === chatId) {
actions.openChat({ id: undefined });
}
})();
});

View File

@ -407,7 +407,10 @@ addReducer('deleteHistory', (global, actions, payload) => {
await callApi('deleteHistory', { chat, shouldDeleteForAll, maxId });
actions.openChat({ id: undefined });
const activeChat = selectCurrentMessageList(global);
if (activeChat && activeChat.chatId === chatId) {
actions.openChat({ id: undefined });
}
})();
});