mirror of
https://github.com/danog/telegram-tt.git
synced 2024-11-27 12:55:11 +01:00
Fix leaving/deleting chats
This commit is contained in:
parent
ac8eee48ec
commit
7620774dc4
@ -28,6 +28,7 @@ import {
|
||||
updateChat,
|
||||
updateChatListSecondaryInfo,
|
||||
updateManagementProgress,
|
||||
leaveChat,
|
||||
} from '../../reducers';
|
||||
import {
|
||||
selectChat,
|
||||
@ -299,78 +300,78 @@ addReducer('joinChannel', (global, actions, payload) => {
|
||||
});
|
||||
|
||||
addReducer('deleteChatUser', (global, actions, payload) => {
|
||||
(async () => {
|
||||
const { chatId, userId }: { chatId: string; userId: string } = payload!;
|
||||
const chat = selectChat(global, chatId);
|
||||
const user = selectUser(global, userId);
|
||||
if (!chat || !user) {
|
||||
return;
|
||||
}
|
||||
await callApi('deleteChatUser', { chat, user });
|
||||
const { chatId, userId }: { chatId: string; userId: string } = payload!;
|
||||
const chat = selectChat(global, chatId);
|
||||
const user = selectUser(global, userId);
|
||||
if (!chat || !user) {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeChat = selectCurrentMessageList(global);
|
||||
if (activeChat && activeChat.chatId === chatId && global.currentUserId === userId) {
|
||||
actions.openChat({ id: undefined });
|
||||
}
|
||||
})();
|
||||
global = leaveChat(global, chatId);
|
||||
setGlobal(global);
|
||||
|
||||
if (selectCurrentMessageList(global)?.chatId === chatId) {
|
||||
actions.openChat({ id: undefined });
|
||||
}
|
||||
|
||||
void callApi('deleteChatUser', { chat, user });
|
||||
});
|
||||
|
||||
addReducer('deleteChat', (global, actions, payload) => {
|
||||
(async () => {
|
||||
const { chatId }: { chatId: string } = payload!;
|
||||
const chat = selectChat(global, chatId);
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
await callApi('deleteChat', { chatId: chat.id });
|
||||
const { chatId }: { chatId: string } = payload!;
|
||||
const chat = selectChat(global, chatId);
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
|
||||
const activeChat = selectCurrentMessageList(global);
|
||||
if (activeChat && activeChat.chatId === chatId) {
|
||||
actions.openChat({ id: undefined });
|
||||
}
|
||||
})();
|
||||
global = leaveChat(global, chatId);
|
||||
setGlobal(global);
|
||||
|
||||
if (selectCurrentMessageList(global)?.chatId === chatId) {
|
||||
actions.openChat({ id: undefined });
|
||||
}
|
||||
|
||||
void callApi('deleteChat', { chatId: chat.id });
|
||||
});
|
||||
|
||||
addReducer('leaveChannel', (global, actions, payload) => {
|
||||
(async () => {
|
||||
const { chatId } = payload!;
|
||||
const chat = selectChat(global, chatId);
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
const { chatId } = payload!;
|
||||
const chat = selectChat(global, chatId);
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { id: channelId, accessHash } = chat;
|
||||
global = leaveChat(global, chatId);
|
||||
setGlobal(global);
|
||||
|
||||
if (channelId && accessHash) {
|
||||
await callApi('leaveChannel', { channelId, accessHash });
|
||||
}
|
||||
if (selectCurrentMessageList(global)?.chatId === chatId) {
|
||||
actions.openChat({ id: undefined });
|
||||
}
|
||||
|
||||
const activeChannel = selectCurrentMessageList(global);
|
||||
if (activeChannel && activeChannel.chatId === chatId) {
|
||||
actions.openChat({ id: undefined });
|
||||
}
|
||||
})();
|
||||
const { id: channelId, accessHash } = chat;
|
||||
if (channelId && accessHash) {
|
||||
void callApi('leaveChannel', { channelId, accessHash });
|
||||
}
|
||||
});
|
||||
|
||||
addReducer('deleteChannel', (global, actions, payload) => {
|
||||
(async () => {
|
||||
const { chatId } = payload!;
|
||||
const chat = selectChat(global, chatId);
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
const { chatId } = payload!;
|
||||
const chat = selectChat(global, chatId);
|
||||
if (!chat) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { id: channelId, accessHash } = chat;
|
||||
global = leaveChat(global, chatId);
|
||||
setGlobal(global);
|
||||
|
||||
if (channelId && accessHash) {
|
||||
await callApi('deleteChannel', { channelId, accessHash });
|
||||
}
|
||||
if (selectCurrentMessageList(global)?.chatId === chatId) {
|
||||
actions.openChat({ id: undefined });
|
||||
}
|
||||
|
||||
const activeChannel = selectCurrentMessageList(global);
|
||||
if (activeChannel && activeChannel.chatId === chatId) {
|
||||
actions.openChat({ id: undefined });
|
||||
}
|
||||
})();
|
||||
const { id: channelId, accessHash } = chat;
|
||||
if (channelId && accessHash) {
|
||||
void callApi('deleteChannel', { channelId, accessHash });
|
||||
}
|
||||
});
|
||||
|
||||
addReducer('createGroupChat', (global, actions, payload) => {
|
||||
|
@ -8,10 +8,10 @@ import { closeMessageNotifications, showNewMessageNotification } from '../../../
|
||||
import { updateAppBadge } from '../../../util/appBadge';
|
||||
import {
|
||||
updateChat,
|
||||
replaceChatListIds,
|
||||
updateChatListIds,
|
||||
updateChatListType,
|
||||
replaceThreadParam,
|
||||
leaveChat,
|
||||
} from '../../reducers';
|
||||
import {
|
||||
selectChat,
|
||||
@ -70,19 +70,7 @@ addReducer('apiUpdate', (global, actions, update: ApiUpdate) => {
|
||||
}
|
||||
|
||||
case 'updateChatLeave': {
|
||||
const listType = selectChatListType(global, update.id);
|
||||
if (!listType) {
|
||||
break;
|
||||
}
|
||||
|
||||
const { [listType]: listIds } = global.chats.listIds;
|
||||
|
||||
if (listIds) {
|
||||
global = replaceChatListIds(global, listType, listIds.filter((listId) => listId !== update.id));
|
||||
}
|
||||
|
||||
global = updateChat(global, update.id, { isNotJoined: true });
|
||||
setGlobal(global);
|
||||
setGlobal(leaveChat(global, update.id));
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import { ApiChat, ApiPhoto } from '../../api/types';
|
||||
|
||||
import { ARCHIVED_FOLDER_ID } from '../../config';
|
||||
import { omit } from '../../util/iteratees';
|
||||
import { selectChatListType } from '../selectors';
|
||||
|
||||
export function replaceChatListIds(
|
||||
global: GlobalState,
|
||||
@ -193,3 +194,20 @@ export function updateChatListSecondaryInfo(
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function leaveChat(global: GlobalState, leftChatId: string): GlobalState {
|
||||
const listType = selectChatListType(global, leftChatId);
|
||||
if (!listType) {
|
||||
return global;
|
||||
}
|
||||
|
||||
const { [listType]: listIds } = global.chats.listIds;
|
||||
|
||||
if (listIds) {
|
||||
global = replaceChatListIds(global, listType, listIds.filter((listId) => listId !== leftChatId));
|
||||
}
|
||||
|
||||
global = updateChat(global, leftChatId, { isNotJoined: true });
|
||||
|
||||
return global;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user