Chat List: Fix active chat closing on leave/delete (#1249)
This commit is contained in:
parent
ca8e1f0d7a
commit
16c732879d
@ -476,14 +476,14 @@ export function joinChannel({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function deleteChatUser({
|
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({
|
return invokeRequest(new GramJs.messages.DeleteChatUser({
|
||||||
chatId: buildInputEntity(chatId) as number,
|
chatId: buildInputEntity(chat.id, chat.accessHash) as number,
|
||||||
userId,
|
userId: buildInputEntity(user.id, user.accessHash) as GramJs.InputUser,
|
||||||
}), true);
|
}), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,6 +37,7 @@ type StateProps = {
|
|||||||
isPrivateChat: boolean;
|
isPrivateChat: boolean;
|
||||||
isBasicGroup: boolean;
|
isBasicGroup: boolean;
|
||||||
isSuperGroup: boolean;
|
isSuperGroup: boolean;
|
||||||
|
currentUserId: number | undefined;
|
||||||
canDeleteForAll?: boolean;
|
canDeleteForAll?: boolean;
|
||||||
contactName?: string;
|
contactName?: string;
|
||||||
};
|
};
|
||||||
@ -51,6 +52,7 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
isChatWithSelf,
|
isChatWithSelf,
|
||||||
isBasicGroup,
|
isBasicGroup,
|
||||||
isSuperGroup,
|
isSuperGroup,
|
||||||
|
currentUserId,
|
||||||
canDeleteForAll,
|
canDeleteForAll,
|
||||||
contactName,
|
contactName,
|
||||||
onClose,
|
onClose,
|
||||||
@ -73,7 +75,7 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
if (isPrivateChat) {
|
if (isPrivateChat) {
|
||||||
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
|
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
|
||||||
} else if (isBasicGroup) {
|
} else if (isBasicGroup) {
|
||||||
deleteChatUser({ chatId: chat.id });
|
deleteChatUser({ chatId: chat.id, userId: currentUserId });
|
||||||
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
|
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
|
||||||
} else if ((isChannel || isSuperGroup) && !chat.isCreator) {
|
} else if ((isChannel || isSuperGroup) && !chat.isCreator) {
|
||||||
leaveChannel({ chatId: chat.id });
|
leaveChannel({ chatId: chat.id });
|
||||||
@ -86,6 +88,7 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
isBasicGroup,
|
isBasicGroup,
|
||||||
isChannel,
|
isChannel,
|
||||||
isSuperGroup,
|
isSuperGroup,
|
||||||
|
currentUserId,
|
||||||
chat.isCreator,
|
chat.isCreator,
|
||||||
chat.id,
|
chat.id,
|
||||||
onClose,
|
onClose,
|
||||||
@ -188,6 +191,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
isChannel: isChatChannel(chat),
|
isChannel: isChatChannel(chat),
|
||||||
isBasicGroup: isChatBasicGroup(chat),
|
isBasicGroup: isChatBasicGroup(chat),
|
||||||
isSuperGroup: isChatSuperGroup(chat),
|
isSuperGroup: isChatSuperGroup(chat),
|
||||||
|
currentUserId: global.currentUserId,
|
||||||
canDeleteForAll,
|
canDeleteForAll,
|
||||||
contactName,
|
contactName,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -230,16 +230,18 @@ addReducer('joinChannel', (global, actions, payload) => {
|
|||||||
|
|
||||||
addReducer('deleteChatUser', (global, actions, payload) => {
|
addReducer('deleteChatUser', (global, actions, payload) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const { chatId, userId } : {chatId: number; userId?: number} = payload!;
|
const { chatId, userId } : {chatId: number; userId: number} = payload!;
|
||||||
const chat = selectChat(global, chatId);
|
const chat = selectChat(global, chatId);
|
||||||
if (!chat) {
|
const user = selectUser(global, userId);
|
||||||
|
if (!chat || !user) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
await callApi('deleteChatUser', { chat, user });
|
||||||
|
|
||||||
const user = userId !== undefined ? selectUser(global, userId) : undefined;
|
const activeChat = selectCurrentMessageList(global);
|
||||||
await callApi('deleteChatUser', { chatId: chat.id, user });
|
if (activeChat && activeChat.chatId === chatId && global.currentUserId === userId) {
|
||||||
|
actions.openChat({ id: undefined });
|
||||||
actions.openChat({ id: undefined });
|
}
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -247,13 +249,15 @@ addReducer('deleteChat', (global, actions, payload) => {
|
|||||||
(async () => {
|
(async () => {
|
||||||
const { chatId } : {chatId: number } = payload!;
|
const { chatId } : {chatId: number } = payload!;
|
||||||
const chat = selectChat(global, chatId);
|
const chat = selectChat(global, chatId);
|
||||||
|
|
||||||
if (!chat) {
|
if (!chat) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await callApi('deleteChat', { chatId: chat.id });
|
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 });
|
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 });
|
await callApi('deleteChannel', { channelId, accessHash });
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.openChat({ id: undefined });
|
const activeChannel = selectCurrentMessageList(global);
|
||||||
|
if (activeChannel && activeChannel.chatId === chatId) {
|
||||||
|
actions.openChat({ id: undefined });
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -407,7 +407,10 @@ addReducer('deleteHistory', (global, actions, payload) => {
|
|||||||
|
|
||||||
await callApi('deleteHistory', { chat, shouldDeleteForAll, maxId });
|
await callApi('deleteHistory', { chat, shouldDeleteForAll, maxId });
|
||||||
|
|
||||||
actions.openChat({ id: undefined });
|
const activeChat = selectCurrentMessageList(global);
|
||||||
|
if (activeChat && activeChat.chatId === chatId) {
|
||||||
|
actions.openChat({ id: undefined });
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user