diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index e100375512..30f979a49f 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -953,7 +953,7 @@ public protocol SharedAccountContext: AnyObject { func makeChannelStatsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)?, peerId: EnginePeer.Id, boosts: Bool, boostStatus: ChannelBoostStatus?) -> ViewController func makeMessagesStatsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)?, messageId: EngineMessage.Id) -> ViewController - func makeStoryStatsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)?, peerId: EnginePeer.Id, storyId: Int32, storyItem: EngineStoryItem?) -> ViewController + func makeStoryStatsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)?, peerId: EnginePeer.Id, storyId: Int32, storyItem: EngineStoryItem, fromStory: Bool) -> ViewController func makeDebugSettingsController(context: AccountContext?) -> ViewController? diff --git a/submodules/StatisticsUI/Sources/ChannelStatsController.swift b/submodules/StatisticsUI/Sources/ChannelStatsController.swift index 6a24992805..e28c3e6640 100644 --- a/submodules/StatisticsUI/Sources/ChannelStatsController.swift +++ b/submodules/StatisticsUI/Sources/ChannelStatsController.swift @@ -1314,7 +1314,7 @@ public func channelStatsController(context: AccountContext, updatedPresentationD case let .message(message): subject = .message(id: message.id) case let .story(story): - subject = .story(peerId: peerId, id: story.id, item: story) + subject = .story(peerId: peerId, id: story.id, item: story, fromStory: false) } controller?.push(messageStatsController(context: context, subject: subject)) } diff --git a/submodules/StatisticsUI/Sources/MessageStatsController.swift b/submodules/StatisticsUI/Sources/MessageStatsController.swift index 3be5c9a213..b0b368c4b3 100644 --- a/submodules/StatisticsUI/Sources/MessageStatsController.swift +++ b/submodules/StatisticsUI/Sources/MessageStatsController.swift @@ -247,7 +247,7 @@ private func messageStatsControllerEntries(data: PostStats?, storyViews: EngineS public enum StatsSubject { case message(id: EngineMessage.Id) - case story(peerId: EnginePeer.Id, id: Int32, item: EngineStoryItem?) + case story(peerId: EnginePeer.Id, id: Int32, item: EngineStoryItem, fromStory: Bool) } protocol PostStats { @@ -303,7 +303,7 @@ public func messageStatsController(context: AccountContext, updatedPresentationD } messagesPromise.set(.single(nil) |> then(searchSignal)) forwardsPromise.set(.single(nil)) - case let .story(peerId, id, _): + case let .story(peerId, id, _, _): let statsContext = StoryStatsContext(account: context.account, peerId: peerId, storyId: id) loadDetailedGraphImpl = { [weak statsContext] graph, x in return statsContext?.loadDetailedGraph(graph, x: x) ?? .single(nil) @@ -342,7 +342,7 @@ public func messageStatsController(context: AccountContext, updatedPresentationD let previousData = Atomic(value: nil) let iconNodePromise = Promise() - if case let .story(peerId, id, storyItem) = subject, let storyItem { + if case let .story(peerId, id, storyItem, fromStory) = subject, !fromStory { let _ = id iconNodePromise.set( context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId)) @@ -387,9 +387,9 @@ public func messageStatsController(context: AccountContext, updatedPresentationD switch subject { case .message: title = presentationData.strings.Stats_MessageTitle - case let .story(_, _, storyItem): + case let .story(_, _, storyItem, _): title = presentationData.strings.Stats_StoryTitle - storyViews = storyItem?.views + storyViews = storyItem.views } let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(title), leftNavigationButton: nil, rightNavigationButton: iconNode.flatMap { ItemListNavigationButton(content: .node($0), style: .regular, enabled: true, action: { }) }, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: true) diff --git a/submodules/TelegramUI/Components/Chat/ChatMessageJoinedChannelBubbleContentNode/Sources/ChatMessageJoinedChannelBubbleContentNode.swift b/submodules/TelegramUI/Components/Chat/ChatMessageJoinedChannelBubbleContentNode/Sources/ChatMessageJoinedChannelBubbleContentNode.swift index 3130bc9361..9a5613a7ba 100644 --- a/submodules/TelegramUI/Components/Chat/ChatMessageJoinedChannelBubbleContentNode/Sources/ChatMessageJoinedChannelBubbleContentNode.swift +++ b/submodules/TelegramUI/Components/Chat/ChatMessageJoinedChannelBubbleContentNode/Sources/ChatMessageJoinedChannelBubbleContentNode.swift @@ -220,7 +220,9 @@ public class ChatMessageJoinedChannelBubbleContentNode: ChatMessageBubbleContent strongSelf.item = item strongSelf.isExpanded = isExpanded - info?.setInvertOffsetDirection() + if !item.controllerInteraction.recommendedChannelsOpenUp { + info?.setInvertOffsetDirection() + } let panelFrame = CGRect(origin: CGPoint(x: 0.0, y: labelLayout.size.height + spacing - 14.0), size: CGSize(width: constrainedSize.width, height: 140.0)) diff --git a/submodules/TelegramUI/Components/ChatControllerInteraction/Sources/ChatControllerInteraction.swift b/submodules/TelegramUI/Components/ChatControllerInteraction/Sources/ChatControllerInteraction.swift index 894cb5ad0f..a0d5530497 100644 --- a/submodules/TelegramUI/Components/ChatControllerInteraction/Sources/ChatControllerInteraction.swift +++ b/submodules/TelegramUI/Components/ChatControllerInteraction/Sources/ChatControllerInteraction.swift @@ -257,6 +257,7 @@ public final class ChatControllerInteraction: ChatControllerInteractionProtocol public var updatedPresentationData: (initial: PresentationData, signal: Signal)? public let presentationContext: ChatPresentationContext public var playNextOutgoingGift: Bool = false + public var recommendedChannelsOpenUp: Bool = false public var enableFullTranslucency: Bool = true public init( diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift index 88b895a520..0beedcf77e 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemSetContainerComponent.swift @@ -6095,7 +6095,8 @@ public final class StoryItemSetContainerComponent: Component { updatedPresentationData: (presentationData, .single(presentationData)), peerId: component.slice.peer.id, storyId: component.slice.item.storyItem.id, - storyItem: component.slice.item.storyItem + storyItem: component.slice.item.storyItem, + fromStory: true ) component.controller()?.push(statsController) }))) @@ -6497,7 +6498,8 @@ public final class StoryItemSetContainerComponent: Component { updatedPresentationData: (presentationData, .single(presentationData)), peerId: component.slice.peer.id, storyId: component.slice.item.storyItem.id, - storyItem: component.slice.item.storyItem + storyItem: component.slice.item.storyItem, + fromStory: true ) component.controller()?.push(statsController) }))) diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index de51e8af43..d4c08ddcac 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -7752,6 +7752,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } strongSelf.shouldDisplayDownButton = !offsetAlpha.isZero + strongSelf.controllerInteraction?.recommendedChannelsOpenUp = !strongSelf.shouldDisplayDownButton strongSelf.updateDownButtonVisibility() strongSelf.chatDisplayNode.updatePlainInputSeparatorAlpha(plainInputSeparatorAlpha, transition: .animated(duration: 0.2, curve: .easeInOut)) } diff --git a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift index a94ab71d1d..ffba3352cf 100644 --- a/submodules/TelegramUI/Sources/ChatHistoryListNode.swift +++ b/submodules/TelegramUI/Sources/ChatHistoryListNode.swift @@ -1642,6 +1642,7 @@ public final class ChatHistoryListNodeImpl: ListView, ChatHistoryNode, ChatHisto } } + if let strongSelf = self, updatedScrollPosition == nil, case .InteractiveChanges = reason, case let .known(offset) = strongSelf.visibleContentOffset(), abs(offset) <= 0.9, let previous = previous { var fillsScreen = true switch strongSelf.visibleBottomContentOffset() { @@ -1682,6 +1683,34 @@ public final class ChatHistoryListNodeImpl: ListView, ChatHistoryNode, ChatHisto } } + if let strongSelf = self, updatedScrollPosition == nil, case .InteractiveChanges = reason, let previous = previous, case let .known(offset) = strongSelf.visibleContentOffset(), abs(offset) <= 320.0 { + var hadJoin = false + var hadAd = false + for entry in previous.filteredEntries.reversed() { + if case let .MessageEntry(message, _, _, _, _, _) = entry { + if let action = message.media.first(where: { $0 is TelegramMediaAction }) as? TelegramMediaAction, case .joinedChannel = action.action { + hadJoin = true + break + } else if message.adAttribute != nil { + hadAd = true + } + } + } + + if !hadJoin && hadAd { + for entry in processedView.filteredEntries.reversed() { + if case let .MessageEntry(message, _, _, _, _, _) = entry { + if message.adAttribute == nil { + if let action = message.media.first(where: { $0 is TelegramMediaAction }) as? TelegramMediaAction, case .joinedChannel = action.action { + updatedScrollPosition = .index(subject: MessageHistoryScrollToSubject(index: .message(message.index), quote: nil), position: .top(0.0), directionHint: .Up, animated: true, highlight: false, displayLink: false) + } + break + } + } + } + } + } + var forceUpdateAll = false if let previous = previous, previous.associatedData.isPremium != processedView.associatedData.isPremium { forceUpdateAll = true diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index 8c463d0c2a..735fc5f8e1 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -1889,8 +1889,8 @@ public final class SharedAccountContextImpl: SharedAccountContext { return messageStatsController(context: context, updatedPresentationData: updatedPresentationData, subject: .message(id: messageId)) } - public func makeStoryStatsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)?, peerId: EnginePeer.Id, storyId: Int32, storyItem: EngineStoryItem?) -> ViewController { - return messageStatsController(context: context, updatedPresentationData: updatedPresentationData, subject: .story(peerId: peerId, id: storyId, item: storyItem)) + public func makeStoryStatsController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)?, peerId: EnginePeer.Id, storyId: Int32, storyItem: EngineStoryItem, fromStory: Bool) -> ViewController { + return messageStatsController(context: context, updatedPresentationData: updatedPresentationData, subject: .story(peerId: peerId, id: storyId, item: storyItem, fromStory: fromStory)) } }