Close chat after leaving of deleting history
This commit is contained in:
parent
1b8c79cb76
commit
f1dba27213
@ -585,7 +585,7 @@ export async function deleteScheduledMessages({
|
|||||||
export async function deleteHistory({
|
export async function deleteHistory({
|
||||||
chat, shouldDeleteForAll, maxId,
|
chat, shouldDeleteForAll, maxId,
|
||||||
}: {
|
}: {
|
||||||
chat: ApiChat; shouldDeleteForAll?: boolean; maxId: number;
|
chat: ApiChat; shouldDeleteForAll?: boolean; maxId?: number;
|
||||||
}) {
|
}) {
|
||||||
const isChannel = getEntityTypeById(chat.id) === 'channel';
|
const isChannel = getEntityTypeById(chat.id) === 'channel';
|
||||||
const result = await invokeRequest(
|
const result = await invokeRequest(
|
||||||
|
|||||||
@ -61,13 +61,14 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
const chatTitle = getChatTitle(lang, chat);
|
const chatTitle = getChatTitle(lang, chat);
|
||||||
|
|
||||||
const handleDeleteMessageForAll = useCallback(() => {
|
const handleDeleteMessageForAll = useCallback(() => {
|
||||||
deleteHistory({ chatId: chat.id, maxId: chat.lastMessage!.id, shouldDeleteForAll: true });
|
deleteHistory({ chatId: chat.id, shouldDeleteForAll: true });
|
||||||
|
|
||||||
onClose();
|
onClose();
|
||||||
}, [deleteHistory, chat.id, chat.lastMessage, onClose]);
|
}, [deleteHistory, chat.id, onClose]);
|
||||||
|
|
||||||
const handleDeleteChat = useCallback(() => {
|
const handleDeleteChat = useCallback(() => {
|
||||||
if (isPrivateChat || isBasicGroup) {
|
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) {
|
} else if ((isChannel || isSuperGroup) && !chat.isCreator) {
|
||||||
leaveChannel({ chatId: chat.id });
|
leaveChannel({ chatId: chat.id });
|
||||||
} else if ((isChannel || isSuperGroup) && chat.isCreator) {
|
} else if ((isChannel || isSuperGroup) && chat.isCreator) {
|
||||||
@ -80,7 +81,6 @@ const DeleteChatModal: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
isChannel,
|
isChannel,
|
||||||
isSuperGroup,
|
isSuperGroup,
|
||||||
chat.isCreator,
|
chat.isCreator,
|
||||||
chat.lastMessage,
|
|
||||||
chat.id,
|
chat.id,
|
||||||
onClose,
|
onClose,
|
||||||
deleteHistory,
|
deleteHistory,
|
||||||
|
|||||||
@ -182,7 +182,7 @@ const ManageGroup: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
|
|
||||||
const handleDeleteGroup = useCallback(() => {
|
const handleDeleteGroup = useCallback(() => {
|
||||||
if (isBasicGroup) {
|
if (isBasicGroup) {
|
||||||
deleteHistory({ chatId: chat.id, maxId: chat.lastMessage!.id, shouldDeleteForAll: false });
|
deleteHistory({ chatId: chat.id, shouldDeleteForAll: false });
|
||||||
} else if (!chat.isCreator) {
|
} else if (!chat.isCreator) {
|
||||||
leaveChannel({ chatId: chat.id });
|
leaveChannel({ chatId: chat.id });
|
||||||
} else {
|
} else {
|
||||||
@ -192,7 +192,7 @@ const ManageGroup: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
closeManagement();
|
closeManagement();
|
||||||
openChat({ id: undefined });
|
openChat({ id: undefined });
|
||||||
}, [
|
}, [
|
||||||
isBasicGroup, chat.isCreator, chat.id, chat.lastMessage,
|
isBasicGroup, chat.isCreator, chat.id,
|
||||||
closeDeleteDialog, closeManagement, deleteHistory, leaveChannel, deleteChannel, openChat,
|
closeDeleteDialog, closeManagement, deleteHistory, leaveChannel, deleteChannel, openChat,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
@ -117,18 +117,15 @@ const ManageUser: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
}, [firstName, lastName, updateContact, userId, isNotificationsEnabled]);
|
}, [firstName, lastName, updateContact, userId, isNotificationsEnabled]);
|
||||||
|
|
||||||
const handleDeleteContact = useCallback(() => {
|
const handleDeleteContact = useCallback(() => {
|
||||||
if (chat.lastMessage) {
|
deleteHistory({
|
||||||
deleteHistory({
|
chatId: chat.id,
|
||||||
chatId: chat.id,
|
shouldDeleteForAll: false,
|
||||||
maxId: chat.lastMessage!.id,
|
});
|
||||||
shouldDeleteForAll: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
deleteUser({ userId });
|
deleteUser({ userId });
|
||||||
closeDeleteDialog();
|
closeDeleteDialog();
|
||||||
closeManagement();
|
closeManagement();
|
||||||
openChat({ id: undefined });
|
openChat({ id: undefined });
|
||||||
}, [chat.id, chat.lastMessage, closeDeleteDialog, closeManagement, deleteHistory, deleteUser, openChat, userId]);
|
}, [chat.id, closeDeleteDialog, closeManagement, deleteHistory, deleteUser, openChat, userId]);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
@ -223,31 +223,39 @@ addReducer('joinChannel', (global, actions, payload) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
addReducer('leaveChannel', (global, actions, payload) => {
|
addReducer('leaveChannel', (global, actions, payload) => {
|
||||||
const { chatId } = payload!;
|
(async () => {
|
||||||
const chat = selectChat(global, chatId);
|
const { chatId } = payload!;
|
||||||
if (!chat) {
|
const chat = selectChat(global, chatId);
|
||||||
return;
|
if (!chat) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { id: channelId, accessHash } = chat;
|
const { id: channelId, accessHash } = chat;
|
||||||
|
|
||||||
if (channelId && accessHash) {
|
if (channelId && accessHash) {
|
||||||
void callApi('leaveChannel', { channelId, accessHash });
|
await callApi('leaveChannel', { channelId, accessHash });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actions.openChat({ id: undefined });
|
||||||
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
addReducer('deleteChannel', (global, actions, payload) => {
|
addReducer('deleteChannel', (global, actions, payload) => {
|
||||||
const { chatId } = payload!;
|
(async () => {
|
||||||
const chat = selectChat(global, chatId);
|
const { chatId } = payload!;
|
||||||
if (!chat) {
|
const chat = selectChat(global, chatId);
|
||||||
return;
|
if (!chat) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { id: channelId, accessHash } = chat;
|
const { id: channelId, accessHash } = chat;
|
||||||
|
|
||||||
if (channelId && accessHash) {
|
if (channelId && accessHash) {
|
||||||
void callApi('deleteChannel', { channelId, accessHash });
|
await callApi('deleteChannel', { channelId, accessHash });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actions.openChat({ id: undefined });
|
||||||
|
})();
|
||||||
});
|
});
|
||||||
|
|
||||||
addReducer('createGroupChat', (global, actions, payload) => {
|
addReducer('createGroupChat', (global, actions, payload) => {
|
||||||
|
|||||||
@ -388,13 +388,19 @@ addReducer('deleteScheduledMessages', (global, actions, payload) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
addReducer('deleteHistory', (global, actions, payload) => {
|
addReducer('deleteHistory', (global, actions, payload) => {
|
||||||
const { chatId, maxId, shouldDeleteForAll } = payload!;
|
(async () => {
|
||||||
const chat = selectChat(global, chatId);
|
const { chatId, shouldDeleteForAll } = payload!;
|
||||||
if (!chat) {
|
const chat = selectChat(global, chatId);
|
||||||
return;
|
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) => {
|
addReducer('markMessageListRead', (global, actions, payload) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user