diff --git a/submodules/AccountContext/Sources/ChatListController.swift b/submodules/AccountContext/Sources/ChatListController.swift index a5079cdaf7..79cc87cf91 100644 --- a/submodules/AccountContext/Sources/ChatListController.swift +++ b/submodules/AccountContext/Sources/ChatListController.swift @@ -23,4 +23,5 @@ public protocol ChatListController: ViewController { func navigateToFolder(folderId: Int32, completion: @escaping () -> Void) func openStories(peerId: EnginePeer.Id) + func openStoriesFromNotification(peerId: EnginePeer.Id, storyId: Int32) } diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 0163ed063f..a336107a6a 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -3675,6 +3675,64 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController }) } + public func openStoriesFromNotification(peerId: EnginePeer.Id, storyId: Int32) { + let presentationData = self.presentationData + let progressSignal = Signal { [weak self] subscriber in + let controller = OverlayStatusController(theme: presentationData.theme, type: .loading(cancelled: nil)) + self?.present(controller, in: .window(.root)) + return ActionDisposable { [weak controller] in + Queue.mainQueue().async() { + controller?.dismiss() + } + } + } + |> runOn(Queue.mainQueue()) + |> delay(0.8, queue: Queue.mainQueue()) + let progressDisposable = progressSignal.start() + + let signal: Signal = self.context.engine.messages.peerStoriesAreReady( + id: peerId, + minId: storyId + ) + |> filter { $0 } + |> deliverOnMainQueue + |> timeout(5.0, queue: .mainQueue(), alternate: .single(false)) + |> take(1) + |> ignoreValues + |> afterDisposed { + Queue.mainQueue().async { + progressDisposable.dispose() + } + } + + self.sharedOpenStoryProgressDisposable.set((signal |> deliverOnMainQueue).start(completed: { [weak self] in + guard let self else { + return + } + StoryContainerScreen.openPeerStoriesCustom( + context: self.context, + peerId: peerId, + isHidden: false, + singlePeer: true, + parentController: self, + transitionIn: { + return nil + }, + transitionOut: { _ in + return nil + }, + setFocusedItem: { _ in + }, + setProgress: { [weak self] signal in + guard let self else { + return + } + self.sharedOpenStoryProgressDisposable.set(signal.start()) + } + ) + })) + } + public func openStories(peerId: EnginePeer.Id) { if let navigationBarView = self.chatListDisplayNode.navigationBarView.view as? ChatListNavigationBar.View { if navigationBarView.storiesUnlocked { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift index 0aed71eee0..f54e9d886d 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/TelegramEngineMessages.swift @@ -629,6 +629,20 @@ public extension TelegramEngine { }).start() } + public func peerStoriesAreReady(id: EnginePeer.Id, minId: Int32) -> Signal { + return self.account.postbox.combinedView(keys: [ + PostboxViewKey.storyItems(peerId: id) + ]) + |> map { views -> Bool in + guard let view = views.views[PostboxViewKey.storyItems(peerId: id)] as? StoryItemsView else { + return false + } + return view.items.contains(where: { item in + return item.id >= minId + }) + } + } + public func storySubscriptions(isHidden: Bool, tempKeepNewlyArchived: Bool = false) -> Signal { return `deferred` { () -> Signal in let debugTimerSignal: Signal diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/OpenStories.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/OpenStories.swift index 6d01f0245b..d6de013c55 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/OpenStories.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/OpenStories.swift @@ -85,7 +85,7 @@ public extension StoryContainerScreen { let _ = avatarNode.pushLoadingStatus(signal: signal) } - static func openPeerStories(context: AccountContext, peerId: EnginePeer.Id, parentController: ViewController, avatarNode: AvatarNode, sharedProgressDisposable: MetaDisposable? = nil) { + static func openPeerStories(context: AccountContext, peerId: EnginePeer.Id, parentController: ViewController, avatarNode: AvatarNode?, sharedProgressDisposable: MetaDisposable? = nil) { return openPeerStoriesCustom( context: context, peerId: peerId, diff --git a/submodules/TelegramUI/Sources/ApplicationContext.swift b/submodules/TelegramUI/Sources/ApplicationContext.swift index f64752cd0f..b9b414cad5 100644 --- a/submodules/TelegramUI/Sources/ApplicationContext.swift +++ b/submodules/TelegramUI/Sources/ApplicationContext.swift @@ -27,6 +27,7 @@ import ContextUI import TelegramCallsUI import AuthorizationUI import ChatListUI +import StoryContainerScreen final class UnauthorizedApplicationContext { let sharedContext: SharedAccountContextImpl @@ -854,7 +855,18 @@ final class AuthorizedApplicationContext { func openChatWithPeerId(peerId: PeerId, threadId: Int64?, messageId: MessageId? = nil, activateInput: Bool = false, storyId: StoryId?) { if let storyId { - if let chatListController = self.rootController.chatListController as? ChatListControllerImpl { + var controllers = self.rootController.viewControllers + controllers = controllers.filter { c in + if c is StoryContainerScreen { + return false + } + return true + } + self.rootController.setViewControllers(controllers, animated: false) + + self.rootController.chatListController?.openStoriesFromNotification(peerId: storyId.peerId, storyId: storyId.id) + + /*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 @@ -902,7 +914,7 @@ final class AuthorizedApplicationContext { } } }) - } + }*/ } else { var visiblePeerId: PeerId? if let controller = self.rootController.topViewController as? ChatControllerImpl, controller.chatLocation.peerId == peerId, controller.chatLocation.threadId == threadId {