From e2078ca0ff4e27fd8a836ba6cf474ac0b26b9dff Mon Sep 17 00:00:00 2001 From: Peter <> Date: Thu, 21 Mar 2019 01:06:30 +0400 Subject: [PATCH] ChatListController: display options for peers other than users --- TelegramUI/ChatListController.swift | 237 ++++++++++++++-------------- 1 file changed, 118 insertions(+), 119 deletions(-) diff --git a/TelegramUI/ChatListController.swift b/TelegramUI/ChatListController.swift index a2866c99a2..3b158a2790 100644 --- a/TelegramUI/ChatListController.swift +++ b/TelegramUI/ChatListController.swift @@ -378,148 +378,147 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie } } |> deliverOnMainQueue).start(next: { peer in - guard let strongSelf = self, let peer = peer else { + guard let strongSelf = self, let peer = peer, let chatPeer = peer.peers[peer.peerId], let mainPeer = peer.chatMainPeer else { return } - strongSelf.maybeAskForPeerChatRemoval(peer: peer, completion: { _ in }) + if chatPeer is TelegramUser { + strongSelf.maybeAskForPeerChatRemoval(peer: peer, completion: { _ in }) + } else { + let actionSheet = ActionSheetController(presentationTheme: strongSelf.presentationData.theme) + var items: [ActionSheetItem] = [] + var canClear = true + var canStop = false - /*guard let strongSelf = self, let peer = peer, let chatPeer = peer.peers[peer.peerId], let mainPeer = peer.chatMainPeer else { - return - } - let actionSheet = ActionSheetController(presentationTheme: strongSelf.presentationData.theme) - var items: [ActionSheetItem] = [] - var canClear = true - var canStop = false - - var deleteTitle = strongSelf.presentationData.strings.Common_Delete - if let channel = chatPeer as? TelegramChannel { - if case .broadcast = channel.info { - canClear = false - deleteTitle = strongSelf.presentationData.strings.Channel_LeaveChannel - } else { - deleteTitle = strongSelf.presentationData.strings.Group_LeaveGroup - } - if let addressName = channel.addressName, !addressName.isEmpty { - canClear = false - } - } else if let user = chatPeer as? TelegramUser, user.botInfo != nil { - canStop = !user.flags.contains(.isSupport) - deleteTitle = strongSelf.presentationData.strings.ChatList_DeleteChat - } else if let _ = chatPeer as? TelegramSecretChat { - deleteTitle = strongSelf.presentationData.strings.ChatList_DeleteChat - } - - var canRemoveGlobally = false - let limitsConfiguration = strongSelf.context.currentLimitsConfiguration.with { $0 } - if chatPeer is TelegramUser && chatPeer.id != strongSelf.context.account.peerId { - if limitsConfiguration.maxMessageRevokeIntervalInPrivateChats == LimitsConfiguration.timeIntervalForever { - canRemoveGlobally = true - } - } - - items.append(DeleteChatPeerActionSheetItem(context: strongSelf.context, peer: mainPeer, chatPeer: chatPeer, action: .delete, strings: strongSelf.presentationData.strings)) - if canClear { - items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.DialogList_ClearHistoryConfirmation, color: .accent, action: { [weak actionSheet] in - actionSheet?.dismissAnimated() - - guard let strongSelf = self else { - return + var deleteTitle = strongSelf.presentationData.strings.Common_Delete + if let channel = chatPeer as? TelegramChannel { + if case .broadcast = channel.info { + canClear = false + deleteTitle = strongSelf.presentationData.strings.Channel_LeaveChannel + } else { + deleteTitle = strongSelf.presentationData.strings.Group_LeaveGroup } - - let beginClear: (InteractiveMessagesDeletionType) -> Void = { type in + if let addressName = channel.addressName, !addressName.isEmpty { + canClear = false + } + } else if let user = chatPeer as? TelegramUser, user.botInfo != nil { + canStop = !user.flags.contains(.isSupport) + deleteTitle = strongSelf.presentationData.strings.ChatList_DeleteChat + } else if let _ = chatPeer as? TelegramSecretChat { + deleteTitle = strongSelf.presentationData.strings.ChatList_DeleteChat + } + + var canRemoveGlobally = false + let limitsConfiguration = strongSelf.context.currentLimitsConfiguration.with { $0 } + if chatPeer is TelegramUser && chatPeer.id != strongSelf.context.account.peerId { + if limitsConfiguration.maxMessageRevokeIntervalInPrivateChats == LimitsConfiguration.timeIntervalForever { + canRemoveGlobally = true + } + } + + items.append(DeleteChatPeerActionSheetItem(context: strongSelf.context, peer: mainPeer, chatPeer: chatPeer, action: .delete, strings: strongSelf.presentationData.strings)) + if canClear { + items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.DialogList_ClearHistoryConfirmation, color: .accent, action: { [weak actionSheet] in + actionSheet?.dismissAnimated() + guard let strongSelf = self else { return } - strongSelf.chatListDisplayNode.chatListNode.updateState({ state in - var state = state - state.pendingClearHistoryPeerIds.insert(peer.peerId) - return state - }) - strongSelf.present(UndoOverlayController(context: strongSelf.context, text: strongSelf.presentationData.strings.Undo_MessagesDeleted, action: { shouldCommit in + + let beginClear: (InteractiveMessagesDeletionType) -> Void = { type in guard let strongSelf = self else { return } - if shouldCommit { - let _ = clearHistoryInteractively(postbox: strongSelf.context.account.postbox, peerId: peerId, type: type).start(completed: { - guard let strongSelf = self else { - return - } + strongSelf.chatListDisplayNode.chatListNode.updateState({ state in + var state = state + state.pendingClearHistoryPeerIds.insert(peer.peerId) + return state + }) + strongSelf.present(UndoOverlayController(context: strongSelf.context, text: strongSelf.presentationData.strings.Undo_MessagesDeleted, action: { shouldCommit in + guard let strongSelf = self else { + return + } + if shouldCommit { + let _ = clearHistoryInteractively(postbox: strongSelf.context.account.postbox, peerId: peerId, type: type).start(completed: { + guard let strongSelf = self else { + return + } + strongSelf.chatListDisplayNode.chatListNode.updateState({ state in + var state = state + state.pendingClearHistoryPeerIds.remove(peer.peerId) + return state + }) + }) + } else { strongSelf.chatListDisplayNode.chatListNode.updateState({ state in var state = state state.pendingClearHistoryPeerIds.remove(peer.peerId) return state }) - }) - } else { - strongSelf.chatListDisplayNode.chatListNode.updateState({ state in - var state = state - state.pendingClearHistoryPeerIds.remove(peer.peerId) - return state - }) - } - }), in: .window(.root)) - } - - if canRemoveGlobally { - let actionSheet = ActionSheetController(presentationTheme: strongSelf.presentationData.theme) - var items: [ActionSheetItem] = [] + } + }), in: .window(.root)) + } - items.append(DeleteChatPeerActionSheetItem(context: strongSelf.context, peer: mainPeer, chatPeer: chatPeer, action: .clearHistory, strings: strongSelf.presentationData.strings)) - items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.ChatList_DeleteForCurrentUser, color: .destructive, action: { [weak actionSheet] in - beginClear(.forLocalPeer) - actionSheet?.dismissAnimated() - })) - items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.ChatList_DeleteForEveryone(mainPeer.displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder)).0, color: .destructive, action: { [weak actionSheet] in - beginClear(.forEveryone) - actionSheet?.dismissAnimated() - })) - - actionSheet.setItemGroups([ - ActionSheetItemGroup(items: items), - ActionSheetItemGroup(items: [ - ActionSheetButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, color: .accent, action: { [weak actionSheet] in - actionSheet?.dismissAnimated() - }) + if canRemoveGlobally { + let actionSheet = ActionSheetController(presentationTheme: strongSelf.presentationData.theme) + var items: [ActionSheetItem] = [] + + items.append(DeleteChatPeerActionSheetItem(context: strongSelf.context, peer: mainPeer, chatPeer: chatPeer, action: .clearHistory, strings: strongSelf.presentationData.strings)) + items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.ChatList_DeleteForCurrentUser, color: .destructive, action: { [weak actionSheet] in + beginClear(.forLocalPeer) + actionSheet?.dismissAnimated() + })) + items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.ChatList_DeleteForEveryone(mainPeer.displayTitle(strings: strongSelf.presentationData.strings, displayOrder: strongSelf.presentationData.nameDisplayOrder)).0, color: .destructive, action: { [weak actionSheet] in + beginClear(.forEveryone) + actionSheet?.dismissAnimated() + })) + + actionSheet.setItemGroups([ + ActionSheetItemGroup(items: items), + ActionSheetItemGroup(items: [ + ActionSheetButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, color: .accent, action: { [weak actionSheet] in + actionSheet?.dismissAnimated() + }) + ]) ]) - ]) - strongSelf.present(actionSheet, in: .window(.root)) - } else { - beginClear(.forLocalPeer) - } - })) - } - - items.append(ActionSheetButtonItem(title: deleteTitle, color: .destructive, action: { [weak actionSheet] in - actionSheet?.dismissAnimated() - guard let strongSelf = self else { - return + strongSelf.present(actionSheet, in: .window(.root)) + } else { + beginClear(.forLocalPeer) + } + })) } - - strongSelf.maybeAskForPeerChatRemoval(peer: peer, completion: { _ in }) - })) - - if canStop { - items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.DialogList_DeleteBotConversationConfirmation, color: .destructive, action: { [weak actionSheet] in + + items.append(ActionSheetButtonItem(title: deleteTitle, color: .destructive, action: { [weak actionSheet] in actionSheet?.dismissAnimated() - - if let strongSelf = self { - strongSelf.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(peerId) - let _ = removePeerChat(account: strongSelf.context.account, peerId: peerId, reportChatSpam: false).start(completed: { - self?.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(peerId) - }) - let _ = requestUpdatePeerIsBlocked(account: strongSelf.context.account, peerId: peer.peerId, isBlocked: true).start() + guard let strongSelf = self else { + return } + + strongSelf.maybeAskForPeerChatRemoval(peer: peer, completion: { _ in }) })) - } - - actionSheet.setItemGroups([ActionSheetItemGroup(items: items), - ActionSheetItemGroup(items: [ - ActionSheetButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, color: .accent, action: { [weak actionSheet] in + + if canStop { + items.append(ActionSheetButtonItem(title: strongSelf.presentationData.strings.DialogList_DeleteBotConversationConfirmation, color: .destructive, action: { [weak actionSheet] in actionSheet?.dismissAnimated() - }) + + if let strongSelf = self { + strongSelf.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(peerId) + let _ = removePeerChat(account: strongSelf.context.account, peerId: peerId, reportChatSpam: false).start(completed: { + self?.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(peerId) + }) + let _ = requestUpdatePeerIsBlocked(account: strongSelf.context.account, peerId: peer.peerId, isBlocked: true).start() + } + })) + } + + actionSheet.setItemGroups([ActionSheetItemGroup(items: items), + ActionSheetItemGroup(items: [ + ActionSheetButtonItem(title: strongSelf.presentationData.strings.Common_Cancel, color: .accent, action: { [weak actionSheet] in + actionSheet?.dismissAnimated() + }) + ]) ]) - ]) - strongSelf.present(actionSheet, in: .window(.root))*/ + strongSelf.present(actionSheet, in: .window(.root)) + } }) }