diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 6cd0a10c36..a59c4b9f29 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -1358,6 +1358,18 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController let contextController = ContextController(presentationData: strongSelf.presentationData, source: .controller(ContextControllerContentSourceImpl(controller: chatListController, sourceNode: node, navigationController: strongSelf.navigationController as? NavigationController)), items: chatContextMenuItems(context: strongSelf.context, peerId: peer.peerId, promoInfo: promoInfo, source: .chatList(filter: strongSelf.chatListDisplayNode.mainContainerNode.currentItemNode.chatListFilter), chatListController: strongSelf, joined: joined) |> map { ContextController.Items(content: .list($0)) }, gesture: gesture) strongSelf.presentInGlobalOverlay(contextController) } + } else if let peer = peer.peer, peer.id == strongSelf.context.account.peerId, peerData.displayAsTopicList { + if let peerInfoController = strongSelf.context.sharedContext.makePeerInfoController(context: strongSelf.context, updatedPresentationData: nil, peer: peer._asPeer(), mode: .generic, avatarInitiallyExpanded: false, fromChat: false, requestsContext: nil) { + let source: ContextContentSource + if let location = location { + source = .location(ChatListContextLocationContentSource(controller: strongSelf, location: location)) + } else { + source = .controller(ContextControllerContentSourceImpl(controller: peerInfoController, sourceNode: node, navigationController: strongSelf.navigationController as? NavigationController)) + } + + let contextController = ContextController(presentationData: strongSelf.presentationData, source: source, items: chatContextMenuItems(context: strongSelf.context, peerId: peer.id, promoInfo: promoInfo, source: .chatList(filter: strongSelf.chatListDisplayNode.mainContainerNode.currentItemNode.chatListFilter), chatListController: strongSelf, joined: joined) |> map { ContextController.Items(content: .list($0)) }, gesture: gesture) + strongSelf.presentInGlobalOverlay(contextController) + } } else { let source: ContextContentSource if let location = location { diff --git a/submodules/ChatListUI/Sources/Node/ChatListNode.swift b/submodules/ChatListUI/Sources/Node/ChatListNode.swift index 1e99bd5f14..f1b8176f9e 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListNode.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListNode.swift @@ -1182,13 +1182,29 @@ public final class ChatListNode: ListView { private let viewProcessingQueue = Queue() private var chatListView: ChatListNodeView? - var entriesCount: Int { + public var entriesCount: Int { if let chatListView = self.chatListView { return chatListView.filteredEntries.count } else { return 0 } } + public var entryPeerIds: [EnginePeer.Id] { + if let chatListView = self.chatListView { + return chatListView.filteredEntries.compactMap { item -> EnginePeer.Id? in + switch item.stableId { + case .Header, .Hole: + return nil + case let .PeerId(value): + return PeerId(value) + case .ThreadId, .GroupId, .ContactId, .ArchiveIntro, .EmptyIntro, .SectionHeader, .Notice, .additionalCategory: + return nil + } + } + } else { + return [] + } + } private var interaction: ChatListNodeInteraction? private var dequeuedInitialTransitionOnLayout = false diff --git a/submodules/Display/Source/TextNode.swift b/submodules/Display/Source/TextNode.swift index cabd9cb729..8c965c0a18 100644 --- a/submodules/Display/Source/TextNode.swift +++ b/submodules/Display/Source/TextNode.swift @@ -1503,7 +1503,7 @@ open class TextNode: ASDisplayNode { if let titleLine = segment.titleLine { titleLine.frame = CGRect(origin: CGPoint(x: titleLine.frame.origin.x, y: -insets.bottom + size.height + titleLine.frame.size.height), size: titleLine.frame.size) titleLine.frame.size.width += max(0.0, segment.additionalWidth - 2.0) - size.height += titleLine.frame.height + size.height += titleLine.frame.height + titleLine.frame.height * lineSpacingFactor blockWidth = max(blockWidth, titleLine.frame.origin.x + titleLine.frame.width) lines.append(titleLine) @@ -1512,8 +1512,7 @@ open class TextNode: ASDisplayNode { for line in segment.lines { line.frame = CGRect(origin: CGPoint(x: line.frame.origin.x, y: -insets.bottom + size.height + line.frame.size.height), size: line.frame.size) line.frame.size.width += max(0.0, segment.additionalWidth - 2.0) - //line.frame.size.width = max(blockWidth, line.frame.size.width) - size.height += line.frame.height + size.height += line.frame.height + line.frame.height * lineSpacingFactor blockWidth = max(blockWidth, line.frame.origin.x + line.frame.width) if let range = line.range { diff --git a/submodules/TelegramUI/Components/PeerInfo/PeerInfoChatListPaneNode/Sources/PeerInfoChatListPaneNode.swift b/submodules/TelegramUI/Components/PeerInfo/PeerInfoChatListPaneNode/Sources/PeerInfoChatListPaneNode.swift index 774183093f..a830414f1b 100644 --- a/submodules/TelegramUI/Components/PeerInfo/PeerInfoChatListPaneNode/Sources/PeerInfoChatListPaneNode.swift +++ b/submodules/TelegramUI/Components/PeerInfo/PeerInfoChatListPaneNode/Sources/PeerInfoChatListPaneNode.swift @@ -319,12 +319,20 @@ public final class PeerInfoChatListPaneNode: ASDisplayNode, PeerInfoPaneNode, UI return true }) - self.parentController?.present(UndoOverlayController(presentationData: self.context.sharedContext.currentPresentationData.with { $0 }, content: .removedChat(title: self.presentationData.strings.SavedMessages_SubChatDeleted, text: nil), elevatedLayout: false, animateInAsReplacement: true, action: { [weak self] value in - guard let self else { - return false - } + if self.chatListNode.entryPeerIds.count == 0 || self.chatListNode.entryPeerIds == [peer.id] { + let _ = context.engine.messages.clearHistoryInteractively(peerId: self.context.account.peerId, threadId: peer.id.toInt64(), type: .forLocalPeer).startStandalone(completed: { + }) + context.engine.peers.updateSavedMessagesViewAsTopics(value: false) + + self.parentController?.dismiss() + + return + } + + let context = self.context + let undoController = UndoOverlayController(presentationData: self.context.sharedContext.currentPresentationData.with { $0 }, content: .removedChat(title: self.presentationData.strings.SavedMessages_SubChatDeleted, text: nil), elevatedLayout: false, animateInAsReplacement: true, action: { [weak self] value in if value == .commit { - let _ = self.context.engine.messages.clearHistoryInteractively(peerId: self.context.account.peerId, threadId: peer.id.toInt64(), type: .forLocalPeer).startStandalone(completed: { [weak self] in + let _ = context.engine.messages.clearHistoryInteractively(peerId: context.account.peerId, threadId: peer.id.toInt64(), type: .forLocalPeer).startStandalone(completed: { guard let self else { return } @@ -336,15 +344,18 @@ public final class PeerInfoChatListPaneNode: ASDisplayNode, PeerInfoPaneNode, UI }) return true } else if value == .undo { - self.chatListNode.updateState({ state in - var state = state - state.pendingRemovalItemIds.remove(ChatListNodeState.ItemId(peerId: peer.id, threadId: nil)) - return state - }) + if let self { + self.chatListNode.updateState({ state in + var state = state + state.pendingRemovalItemIds.remove(ChatListNodeState.ItemId(peerId: peer.id, threadId: nil)) + return state + }) + } return true } return false - }), in: .current) + }) + self.parentController?.present(undoController, in: .window(.root)) })) actionSheet.setItemGroups([ActionSheetItemGroup(items: items), diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 4dd7a73d2d..f2cbac933d 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -7171,17 +7171,30 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var closeOnEmpty = false if case .pinnedMessages = self.presentationInterfaceState.subject { closeOnEmpty = true - } else if case let .replyThread(replyThreadMessage) = self.chatLocation, replyThreadMessage.peerId == self.context.account.peerId { - closeOnEmpty = false + } else if self.chatLocation.peerId == self.context.account.peerId { + if let data = self.context.currentAppConfiguration.with({ $0 }).data, let _ = data["ios_killswitch_disable_close_empty_saved"] { + } else { + closeOnEmpty = true + } } if closeOnEmpty { self.chatDisplayNode.historyNode.addSetLoadStateUpdated({ [weak self] state, _ in - guard let strongSelf = self else { + guard let self else { return } if case .empty = state { - strongSelf.dismiss() + if self.chatLocation.peerId == self.context.account.peerId { + if self.chatDisplayNode.historyNode.tag != nil { + self.updateChatPresentationInterfaceState(animated: true, interactive: false, { state in + return state.updatedSearch(nil).updatedHistoryFilter(nil) + }) + } else if case .replyThread = self.chatLocation { + self.dismiss() + } + } else { + self.dismiss() + } } }) }