Close chat after leaving of deleting history

This commit is contained in:
Alexander Zinchuk 2021-06-13 19:56:54 +03:00
parent 1b8c79cb76
commit f1dba27213
6 changed files with 50 additions and 39 deletions

View File

@ -585,7 +585,7 @@ export async function deleteScheduledMessages({
export async function deleteHistory({
chat, shouldDeleteForAll, maxId,
}: {
chat: ApiChat; shouldDeleteForAll?: boolean; maxId: number;
chat: ApiChat; shouldDeleteForAll?: boolean; maxId?: number;
}) {
const isChannel = getEntityTypeById(chat.id) === 'channel';
const result = await invokeRequest(

View File

@ -61,13 +61,14 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
const chatTitle = getChatTitle(lang, chat);
const handleDeleteMessageForAll = useCallback(() => {
deleteHistory({ chatId: chat.id, maxId: chat.lastMessage!.id, shouldDeleteForAll: true });
deleteHistory({ chatId: chat.id, shouldDeleteForAll: true });
onClose();
}, [deleteHistory, chat.id, chat.lastMessage, onClose]);
}, [deleteHistory, chat.id, onClose]);
const handleDeleteChat = useCallback(() => {
if (isPrivateChat || isBasicGroup) {
deleteHistory({ chatId: chat.id, maxId: chat.lastMessage!.id, shouldDeleteForAll: false });
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
} else if ((isChannel || isSuperGroup) && !chat.isCreator) {
leaveChannel({ chatId: chat.id });
} else if ((isChannel || isSuperGroup) && chat.isCreator) {
@ -80,7 +81,6 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
isChannel,
isSuperGroup,
chat.isCreator,
chat.lastMessage,
chat.id,
onClose,
deleteHistory,

View File

@ -182,7 +182,7 @@ const ManageGroup: FC<OwnProps & StateProps & DispatchProps> = ({
const handleDeleteGroup = useCallback(() => {
if (isBasicGroup) {
deleteHistory({ chatId: chat.id, maxId: chat.lastMessage!.id, shouldDeleteForAll: false });
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
} else if (!chat.isCreator) {
leaveChannel({ chatId: chat.id });
} else {
@ -192,7 +192,7 @@ const ManageGroup: FC<OwnProps & StateProps & DispatchProps> = ({
closeManagement();
openChat({ id: undefined });
}, [
isBasicGroup, chat.isCreator, chat.id, chat.lastMessage,
isBasicGroup, chat.isCreator, chat.id,
closeDeleteDialog, closeManagement, deleteHistory, leaveChannel, deleteChannel, openChat,
]);

View File

@ -117,18 +117,15 @@ const ManageUser: FC<OwnProps & StateProps & DispatchProps> = ({
}, [firstName, lastName, updateContact, userId, isNotificationsEnabled]);
const handleDeleteContact = useCallback(() => {
if (chat.lastMessage) {
deleteHistory({
chatId: chat.id,
maxId: chat.lastMessage!.id,
shouldDeleteForAll: false,
});
}
deleteHistory({
chatId: chat.id,
shouldDeleteForAll: false,
});
deleteUser({ userId });
closeDeleteDialog();
closeManagement();
openChat({ id: undefined });
}, [chat.id, chat.lastMessage, closeDeleteDialog, closeManagement, deleteHistory, deleteUser, openChat, userId]);
}, [chat.id, closeDeleteDialog, closeManagement, deleteHistory, deleteUser, openChat, userId]);
if (!user) {
return undefined;

View File

@ -223,31 +223,39 @@ addReducer('joinChannel', (global, actions, payload) => {
});
addReducer('leaveChannel', (global, actions, payload) => {
const { chatId } = payload!;
const chat = selectChat(global, chatId);
if (!chat) {
return;
}
(async () => {
const { chatId } = payload!;
const chat = selectChat(global, chatId);
if (!chat) {
return;
}
const { id: channelId, accessHash } = chat;
const { id: channelId, accessHash } = chat;
if (channelId && accessHash) {
void callApi('leaveChannel', { channelId, accessHash });
}
if (channelId && accessHash) {
await callApi('leaveChannel', { channelId, accessHash });
}
actions.openChat({ id: undefined });
})();
});
addReducer('deleteChannel', (global, actions, payload) => {
const { chatId } = payload!;
const chat = selectChat(global, chatId);
if (!chat) {
return;
}
(async () => {
const { chatId } = payload!;
const chat = selectChat(global, chatId);
if (!chat) {
return;
}
const { id: channelId, accessHash } = chat;
const { id: channelId, accessHash } = chat;
if (channelId && accessHash) {
void callApi('deleteChannel', { channelId, accessHash });
}
if (channelId && accessHash) {
await callApi('deleteChannel', { channelId, accessHash });
}
actions.openChat({ id: undefined });
})();
});
addReducer('createGroupChat', (global, actions, payload) => {

View File

@ -388,13 +388,19 @@ addReducer('deleteScheduledMessages', (global, actions, payload) => {
});
addReducer('deleteHistory', (global, actions, payload) => {
const { chatId, maxId, shouldDeleteForAll } = payload!;
const chat = selectChat(global, chatId);
if (!chat) {
return;
}
(async () => {
const { chatId, shouldDeleteForAll } = payload!;
const chat = selectChat(global, chatId);
if (!chat) {
return;
}
void callApi('deleteHistory', { chat, shouldDeleteForAll, maxId });
const maxId = chat.lastMessage && chat.lastMessage.id;
await callApi('deleteHistory', { chat, shouldDeleteForAll, maxId });
actions.openChat({ id: undefined });
})();
});
addReducer('markMessageListRead', (global, actions, payload) => {