From 00f6b096a24e4b23ab9726a47394e137a6cfc351 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Tue, 6 Jul 2021 19:39:12 +0300 Subject: [PATCH] Revert "Chat List: Fix leaving legacy and private chats (#1235)" This reverts commit 3d0369a002c6465e6c63201c51a6a51731a99d03. --- src/api/gramjs/methods/chats.ts | 22 -------------- src/api/gramjs/methods/index.ts | 2 +- src/components/common/DeleteChatModal.tsx | 12 ++------ .../right/management/ManageGroup.tsx | 10 +++---- src/global/types.ts | 2 +- src/lib/gramjs/tl/apiTl.js | 2 -- src/lib/gramjs/tl/static/api.reduced.tl | 2 -- src/modules/actions/api/chats.ts | 29 ------------------- 8 files changed, 10 insertions(+), 71 deletions(-) diff --git a/src/api/gramjs/methods/chats.ts b/src/api/gramjs/methods/chats.ts index a645db5e..67e36599 100644 --- a/src/api/gramjs/methods/chats.ts +++ b/src/api/gramjs/methods/chats.ts @@ -475,28 +475,6 @@ export function joinChannel({ }), true); } -export function deleteChatUser({ - chatId, user, -}: { - chatId: number; user?: ApiUser; -}) { - const userId = user ? buildInputEntity(user.id, user.accessHash) as GramJs.InputUser : new GramJs.InputUserSelf(); - return invokeRequest(new GramJs.messages.DeleteChatUser({ - chatId: buildInputEntity(chatId) as number, - userId, - }), true); -} - -export function deleteChat({ - chatId, -}: { - chatId: number; -}) { - return invokeRequest(new GramJs.messages.DeleteChat({ - chatId: buildInputEntity(chatId) as number, - }), true); -} - export function leaveChannel({ channelId, accessHash, }: { diff --git a/src/api/gramjs/methods/index.ts b/src/api/gramjs/methods/index.ts index 3d994164..070018da 100644 --- a/src/api/gramjs/methods/index.ts +++ b/src/api/gramjs/methods/index.ts @@ -9,7 +9,7 @@ export { export { fetchChats, fetchFullChat, searchChats, requestChatUpdate, saveDraft, clearDraft, fetchChat, updateChatMutedState, - createChannel, joinChannel, deleteChatUser, deleteChat, leaveChannel, deleteChannel, createGroupChat, editChatPhoto, + createChannel, joinChannel, leaveChannel, deleteChannel, createGroupChat, editChatPhoto, toggleChatPinned, toggleChatArchived, toggleDialogUnread, fetchChatFolders, editChatFolder, deleteChatFolder, fetchRecommendedChatFolders, getChatByUsername, togglePreHistoryHidden, updateChatDefaultBannedRights, updateChatMemberBannedRights, diff --git a/src/components/common/DeleteChatModal.tsx b/src/components/common/DeleteChatModal.tsx index 685c3283..c9fc169f 100644 --- a/src/components/common/DeleteChatModal.tsx +++ b/src/components/common/DeleteChatModal.tsx @@ -41,7 +41,7 @@ type StateProps = { contactName?: string; }; -type DispatchProps = Pick; +type DispatchProps = Pick; const DeleteChatModal: FC = ({ isOpen, @@ -58,7 +58,6 @@ const DeleteChatModal: FC = ({ leaveChannel, deleteHistory, deleteChannel, - deleteChatUser, }) => { const lang = useLang(); const chatTitle = getChatTitle(lang, chat); @@ -70,10 +69,7 @@ const DeleteChatModal: FC = ({ }, [deleteHistory, chat.id, onClose]); const handleDeleteChat = useCallback(() => { - if (isPrivateChat) { - deleteHistory({ chatId: chat.id, shouldDeleteForAll: false }); - } else if (isBasicGroup) { - deleteChatUser({ chatId: chat.id }); + if (isPrivateChat || isBasicGroup) { deleteHistory({ chatId: chat.id, shouldDeleteForAll: false }); } else if ((isChannel || isSuperGroup) && !chat.isCreator) { leaveChannel({ chatId: chat.id }); @@ -90,7 +86,6 @@ const DeleteChatModal: FC = ({ chat.id, onClose, deleteHistory, - deleteChatUser, leaveChannel, deleteChannel, ]); @@ -192,6 +187,5 @@ export default memo(withGlobal( contactName, }; }, - (setGlobal, actions): DispatchProps => pick(actions, - ['leaveChannel', 'deleteHistory', 'deleteChannel', 'deleteChatUser']), + (setGlobal, actions): DispatchProps => pick(actions, ['leaveChannel', 'deleteHistory', 'deleteChannel']), )(DeleteChatModal)); diff --git a/src/components/right/management/ManageGroup.tsx b/src/components/right/management/ManageGroup.tsx index 78ace1e3..629c5f9c 100644 --- a/src/components/right/management/ManageGroup.tsx +++ b/src/components/right/management/ManageGroup.tsx @@ -43,7 +43,7 @@ type StateProps = { type DispatchProps = Pick; const GROUP_TITLE_EMPTY = 'Group title can\'t be empty'; @@ -63,7 +63,7 @@ const ManageGroup: FC = ({ onScreenSelect, togglePreHistoryHidden, updateChat, - deleteChat, + deleteHistory, leaveChannel, deleteChannel, closeManagement, @@ -182,7 +182,7 @@ const ManageGroup: FC = ({ const handleDeleteGroup = useCallback(() => { if (isBasicGroup) { - deleteChat({ chatId: chat.id }); + deleteHistory({ chatId: chat.id, shouldDeleteForAll: false }); } else if (!chat.isCreator) { leaveChannel({ chatId: chat.id }); } else { @@ -193,7 +193,7 @@ const ManageGroup: FC = ({ openChat({ id: undefined }); }, [ isBasicGroup, chat.isCreator, chat.id, - closeDeleteDialog, closeManagement, leaveChannel, deleteChannel, deleteChat, openChat, + closeDeleteDialog, closeManagement, deleteHistory, leaveChannel, deleteChannel, openChat, ]); if (chat.isRestricted) { @@ -325,6 +325,6 @@ export default memo(withGlobal( }, (setGlobal, actions): DispatchProps => pick(actions, [ 'togglePreHistoryHidden', 'updateChat', 'closeManagement', - 'leaveChannel', 'deleteChannel', 'deleteChat', 'openChat', + 'deleteHistory', 'leaveChannel', 'deleteChannel', 'openChat', ]), )(ManageGroup)); diff --git a/src/global/types.ts b/src/global/types.ts index e43d5f40..30c9d369 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -421,7 +421,7 @@ export type ActionTypes = ( 'editMessage' | 'deleteHistory' | 'enterMessageSelectMode' | 'toggleMessageSelection' | 'exitMessageSelectMode' | 'openTelegramLink' | 'openChatByUsername' | 'requestThreadInfoUpdate' | 'setScrollOffset' | 'unpinAllMessages' | 'setReplyingToId' | 'setEditingId' | 'editLastMessage' | 'saveDraft' | 'clearDraft' | 'loadPinnedMessages' | - 'loadMessageLink' | 'toggleMessageWebPage' | 'replyToNextMessage' | 'deleteChatUser' | 'deleteChat' | + 'loadMessageLink' | 'toggleMessageWebPage' | 'replyToNextMessage' | // scheduled messages 'loadScheduledHistory' | 'sendScheduledMessages' | 'rescheduleMessage' | 'deleteScheduledMessages' | // poll result diff --git a/src/lib/gramjs/tl/apiTl.js b/src/lib/gramjs/tl/apiTl.js index d1147c86..70b8ccd5 100644 --- a/src/lib/gramjs/tl/apiTl.js +++ b/src/lib/gramjs/tl/apiTl.js @@ -971,7 +971,6 @@ messages.getChats#3c6aa187 id:Vector = messages.Chats; messages.getFullChat#3b831c66 chat_id:int = messages.ChatFull; messages.editChatTitle#dc452855 chat_id:int title:string = Updates; messages.editChatPhoto#ca4c79d8 chat_id:int photo:InputChatPhoto = Updates; -messages.deleteChatUser#c534459a flags:# revoke_history:flags.0?true chat_id:int user_id:InputUser = Updates; messages.createChat#9cb126e users:Vector title:string = Updates; messages.getDhConfig#26cf8950 version:int random_length:int = messages.DhConfig; messages.readMessageContents#36a73f77 id:Vector = messages.AffectedMessages; @@ -1022,7 +1021,6 @@ messages.getReplies#24b581ba peer:InputPeer msg_id:int offset_id:int offset_date messages.getDiscussionMessage#446972fd peer:InputPeer msg_id:int = messages.DiscussionMessage; messages.readDiscussion#f731a9f4 peer:InputPeer msg_id:int read_max_id:int = Bool; messages.unpinAllMessages#f025bc8b peer:InputPeer = messages.AffectedHistory; -messages.deleteChat#83247d11 chat_id:int = Bool; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; updates.getChannelDifference#3173d78 flags:# force:flags.0?true channel:InputChannel filter:ChannelMessagesFilter pts:int limit:int = updates.ChannelDifference; diff --git a/src/lib/gramjs/tl/static/api.reduced.tl b/src/lib/gramjs/tl/static/api.reduced.tl index 9c0f229a..dc6c105e 100644 --- a/src/lib/gramjs/tl/static/api.reduced.tl +++ b/src/lib/gramjs/tl/static/api.reduced.tl @@ -971,7 +971,6 @@ messages.getChats#3c6aa187 id:Vector = messages.Chats; messages.getFullChat#3b831c66 chat_id:int = messages.ChatFull; messages.editChatTitle#dc452855 chat_id:int title:string = Updates; messages.editChatPhoto#ca4c79d8 chat_id:int photo:InputChatPhoto = Updates; -messages.deleteChatUser#c534459a flags:# revoke_history:flags.0?true chat_id:int user_id:InputUser = Updates; messages.createChat#9cb126e users:Vector title:string = Updates; messages.getDhConfig#26cf8950 version:int random_length:int = messages.DhConfig; messages.readMessageContents#36a73f77 id:Vector = messages.AffectedMessages; @@ -1022,7 +1021,6 @@ messages.getReplies#24b581ba peer:InputPeer msg_id:int offset_id:int offset_date messages.getDiscussionMessage#446972fd peer:InputPeer msg_id:int = messages.DiscussionMessage; messages.readDiscussion#f731a9f4 peer:InputPeer msg_id:int read_max_id:int = Bool; messages.unpinAllMessages#f025bc8b peer:InputPeer = messages.AffectedHistory; -messages.deleteChat#83247d11 chat_id:int = Bool; updates.getState#edd4882a = updates.State; updates.getDifference#25939651 flags:# pts:int pts_total_limit:flags.0?int date:int qts:int = updates.Difference; updates.getChannelDifference#3173d78 flags:# force:flags.0?true channel:InputChannel filter:ChannelMessagesFilter pts:int limit:int = updates.ChannelDifference; diff --git a/src/modules/actions/api/chats.ts b/src/modules/actions/api/chats.ts index 331745a8..1952b426 100644 --- a/src/modules/actions/api/chats.ts +++ b/src/modules/actions/api/chats.ts @@ -228,35 +228,6 @@ addReducer('joinChannel', (global, actions, payload) => { } }); -addReducer('deleteChatUser', (global, actions, payload) => { - (async () => { - const { chatId, userId } : {chatId: number; userId?: number} = payload!; - const chat = selectChat(global, chatId); - if (!chat) { - return; - } - - const user = userId !== undefined ? selectUser(global, userId) : undefined; - await callApi('deleteChatUser', { chatId: chat.id, user }); - - actions.openChat({ id: undefined }); - })(); -}); - -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 }); - })(); -}); - addReducer('leaveChannel', (global, actions, payload) => { (async () => { const { chatId } = payload!;