[WIP] Topics

This commit is contained in:
Ali
2022-10-04 19:33:05 +04:00
parent 62697d4ffb
commit 1df1fad510
4 changed files with 84 additions and 14 deletions

View File

@@ -81,6 +81,7 @@ swift_library(
"//submodules/TelegramUI/Components/ForumCreateTopicScreen:ForumCreateTopicScreen",
"//submodules/TelegramUI/Components/ChatTitleView",
"//submodules/AnimationUI:AnimationUI",
"//submodules/PeerInfoUI",
],
visibility = [
"//visibility:public",

View File

@@ -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))
})
}
}))
}
}
}

View File

@@ -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:

View File

@@ -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)