This commit is contained in:
Ali
2023-07-11 00:43:25 +04:00
parent 4e06ed8bdd
commit fbea3fccc0
3 changed files with 149 additions and 35 deletions

View File

@@ -26,6 +26,7 @@ import AccountUtils
import ContextUI
import TelegramCallsUI
import AuthorizationUI
import ChatListUI
final class UnauthorizedApplicationContext {
let sharedContext: SharedAccountContextImpl
@@ -852,8 +853,56 @@ final class AuthorizedApplicationContext {
}
func openChatWithPeerId(peerId: PeerId, threadId: Int64?, messageId: MessageId? = nil, activateInput: Bool = false, storyId: StoryId?) {
if let _ = storyId {
self.rootController.chatListController?.openStories(peerId: peerId)
if let storyId {
if let chatListController = self.rootController.chatListController as? ChatListControllerImpl {
let _ = (chatListController.context.account.postbox.transaction { transaction -> Bool in
if let peer = transaction.getPeer(storyId.peerId) as? TelegramUser, let storiesHidden = peer.storiesHidden, storiesHidden {
return true
} else {
return false
}
}
|> deliverOnMainQueue).start(next: { [weak self] isArchived in
guard let self, let chatListController = self.rootController.chatListController as? ChatListControllerImpl else {
return
}
if isArchived {
if let navigationController = (chatListController.navigationController as? NavigationController) {
var viewControllers = navigationController.viewControllers
if let index = viewControllers.firstIndex(where: { c in
if let c = c as? ChatListControllerImpl {
if case .chatList(groupId: .archive) = c.location {
return true
}
}
return false
}) {
(viewControllers[index] as? ChatListControllerImpl)?.scrollToStories()
viewControllers.removeSubrange((index + 1) ..< viewControllers.count)
navigationController.setViewControllers(viewControllers, animated: false)
} else {
let archive = ChatListControllerImpl(context: chatListController.context, location: .chatList(groupId: .archive), controlsHistoryPreload: false, hideNetworkActivityStatus: false, previewing: false, enableDebugActions: false)
archive.onDidAppear = { [weak archive] in
Queue.mainQueue().after(0.1, {
guard let archive else {
return
}
if archive.hasStorySubscriptions {
archive.scrollToStoriesAnimated()
}
})
}
navigationController.pushViewController(archive, animated: false, completion: {})
}
}
} else {
chatListController.scrollToStories()
if let navigationController = (chatListController.navigationController as? NavigationController) {
navigationController.popToRoot(animated: true)
}
}
})
}
} else {
var visiblePeerId: PeerId?
if let controller = self.rootController.topViewController as? ChatControllerImpl, controller.chatLocation.peerId == peerId, controller.chatLocation.threadId == threadId {