From 1df1fad510e67f418b54d422d3c2eea723946d9f Mon Sep 17 00:00:00 2001 From: Ali <> Date: Tue, 4 Oct 2022 19:33:05 +0400 Subject: [PATCH] [WIP] Topics --- submodules/ChatListUI/BUILD | 1 + .../Sources/ChatListController.swift | 89 ++++++++++++++++--- .../TelegramCore/Sources/UpdatePeers.swift | 2 +- .../TelegramUI/Sources/ChatController.swift | 6 +- 4 files changed, 84 insertions(+), 14 deletions(-) diff --git a/submodules/ChatListUI/BUILD b/submodules/ChatListUI/BUILD index 458ac01c5a..54fe2bd0c3 100644 --- a/submodules/ChatListUI/BUILD +++ b/submodules/ChatListUI/BUILD @@ -81,6 +81,7 @@ swift_library( "//submodules/TelegramUI/Components/ForumCreateTopicScreen:ForumCreateTopicScreen", "//submodules/TelegramUI/Components/ChatTitleView", "//submodules/AnimationUI:AnimationUI", + "//submodules/PeerInfoUI", ], visibility = [ "//visibility:public", diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index c538a0e184..66860712c4 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -39,6 +39,7 @@ import TelegramStringFormatting import ForumCreateTopicScreen import AnimationUI import ChatTitleView +import PeerInfoUI private func fixListNodeScrolling(_ listNode: ListView, searchNode: NavigationBarSearchContentNode) -> Bool { if listNode.scroller.isDragging { @@ -342,6 +343,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController private let selectAddMemberDisposable = MetaDisposable() private let addMemberDisposable = MetaDisposable() + private let joinForumDisposable = MetaDisposable() public override func updateNavigationCustomData(_ data: Any?, progress: CGFloat, transition: ContainedViewLayoutTransition) { if self.isNodeLoaded { @@ -499,6 +501,16 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController navigationController.replaceController(strongSelf, with: chatController, animated: true) } } + + if let channel = peerView.peers[peerView.peerId] as? TelegramChannel { + switch channel.participationStatus { + case .member: + strongSelf.setToolbar(nil, transition: .animated(duration: 0.4, curve: .spring)) + default: + //TODO:localize + strongSelf.setToolbar(Toolbar(leftAction: nil, rightAction: nil, middleAction: ToolbarAction(title: "Join", isEnabled: true)), transition: .animated(duration: 0.4, curve: .spring)) + } + } }) } } @@ -1148,6 +1160,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController self.activeDownloadsDisposable?.dispose() self.selectAddMemberDisposable.dispose() self.addMemberDisposable.dispose() + self.joinForumDisposable.dispose() } private func openStatusSetup(sourceView: UIView) { @@ -3108,22 +3121,74 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController ]) ]) self.present(actionSheet, in: .window(.root)) - } else if case .middle = action, !peerIds.isEmpty { - if case .chatList(.root) = self.location { - self.donePressed() - self.archiveChats(peerIds: Array(peerIds)) - } else { + } else if case .middle = action { + switch self.location { + case let .chatList(groupId): if !peerIds.isEmpty { - self.chatListDisplayNode.containerNode.currentItemNode.setCurrentRemovingPeerId(peerIds.first!) - let _ = (self.context.engine.peers.updatePeersGroupIdInteractively(peerIds: Array(peerIds), groupId: .root) - |> deliverOnMainQueue).start(completed: { [weak self] in - guard let strongSelf = self else { + if groupId == .root { + self.donePressed() + self.archiveChats(peerIds: Array(peerIds)) + } else { + if !peerIds.isEmpty { + self.chatListDisplayNode.containerNode.currentItemNode.setCurrentRemovingPeerId(peerIds.first!) + let _ = (self.context.engine.peers.updatePeersGroupIdInteractively(peerIds: Array(peerIds), groupId: .root) + |> deliverOnMainQueue).start(completed: { [weak self] in + guard let strongSelf = self else { + return + } + strongSelf.chatListDisplayNode.containerNode.currentItemNode.setCurrentRemovingPeerId(nil) + strongSelf.donePressed() + }) + } + } + } + case let .forum(peerId): + self.joinForumDisposable.set((self.context.peerChannelMemberCategoriesContextsManager.join(engine: context.engine, peerId: peerId, hash: nil) + |> afterDisposed { [weak self] in + Queue.mainQueue().async { + if let strongSelf = self { + let _ = strongSelf + /*strongSelf.activityIndicator.isHidden = true + strongSelf.activityIndicator.stopAnimating() + strongSelf.isJoining = false*/ + } + } + }).start(error: { [weak self] error in + guard let strongSelf = self else { + return + } + let _ = (strongSelf.context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) + |> deliverOnMainQueue).start(next: { peer in + guard let strongSelf = self, let peer = peer else { return } - strongSelf.chatListDisplayNode.containerNode.currentItemNode.setCurrentRemovingPeerId(nil) - strongSelf.donePressed() + + let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } + + let text: String + switch error { + case .inviteRequestSent: + strongSelf.present(UndoOverlayController(presentationData: presentationData, content: .inviteRequestSent(title: presentationData.strings.Group_RequestToJoinSent, text: presentationData.strings.Group_RequestToJoinSentDescriptionGroup ), elevatedLayout: true, animateInAsReplacement: false, action: { _ in return false }), in: .window(.root)) + return + case .tooMuchJoined: + (strongSelf.navigationController as? NavigationController)?.pushViewController(oldChannelsController(context: strongSelf.context, intent: .join, completed: { value in + if value { + self?.toolbarActionSelected(action: .middle) + } + })) + return + case .tooMuchUsers: + text = presentationData.strings.Conversation_UsersTooMuchError + case .generic: + if case let .channel(channel) = peer, case .broadcast = channel.info { + text = presentationData.strings.Channel_ErrorAccessDenied + } else { + text = presentationData.strings.Group_ErrorAccessDenied + } + } + strongSelf.present(textAlertController(context: strongSelf.context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {})]), in: .window(.root)) }) - } + })) } } } diff --git a/submodules/TelegramCore/Sources/UpdatePeers.swift b/submodules/TelegramCore/Sources/UpdatePeers.swift index 27c3271085..a89c273305 100644 --- a/submodules/TelegramCore/Sources/UpdatePeers.swift +++ b/submodules/TelegramCore/Sources/UpdatePeers.swift @@ -73,7 +73,7 @@ public func updatePeers(transaction: Transaction, peers: [Peer], update: (Peer?, if let channel = updated as? TelegramChannel { switch channel.participationStatus { case .member: - updatePeerChatInclusionWithMinTimestamp(transaction: transaction, id: peerId, minTimestamp: channel.creationDate, forceRootGroupIfNotExists: false) + updatePeerChatInclusionWithMinTimestamp(transaction: transaction, id: peerId, minTimestamp: channel.creationDate, forceRootGroupIfNotExists: true) case .left: transaction.updatePeerChatListInclusion(peerId, inclusion: .notIncluded) case .kicked where channel.creationDate == 0: diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 95e7432fcb..809b64547c 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -15673,7 +15673,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } } } else if let navigationController = strongSelf.effectiveNavigationController { - strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(id: peerId.id), subject: subject, keepStack: .always, peekData: peekData)) + if case let .channel(channel) = peerId, channel.flags.contains(.isForum) { + strongSelf.context.sharedContext.navigateToForumChannel(context: strongSelf.context, peerId: peerId.id, navigationController: navigationController) + } else { + strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(id: peerId.id), subject: subject, keepStack: .always, peekData: peekData)) + } } case .info: strongSelf.navigationActionDisposable.set((strongSelf.context.account.postbox.loadedPeerWithId(peerId.id)