diff --git a/submodules/ChatListUI/Sources/Node/ChatListNode.swift b/submodules/ChatListUI/Sources/Node/ChatListNode.swift index 9af17c1444..4976a70cd4 100644 --- a/submodules/ChatListUI/Sources/Node/ChatListNode.swift +++ b/submodules/ChatListUI/Sources/Node/ChatListNode.swift @@ -3197,7 +3197,7 @@ public final class ChatListNode: ListView { } var options = transition.options - options.insert(.Synchronous) + //options.insert(.Synchronous) if self.view.window != nil { if !options.contains(.AnimateInsertion) { options.insert(.PreferSynchronousDrawing) diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/StoryListContext.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/StoryListContext.swift index 476a19efe6..b459b71169 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/StoryListContext.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/StoryListContext.swift @@ -450,6 +450,8 @@ public final class PeerStoryListContext { private var updatesDisposable: Disposable? + private var completionCallbacksByToken: [Int: [() -> Void]] = [:] + init(queue: Queue, account: Account, peerId: EnginePeer.Id, isArchived: Bool) { self.queue = queue self.account = account @@ -519,7 +521,7 @@ public final class PeerStoryListContext { } self.stateValue = State(peerReference: peerReference, items: items, totalCount: totalCount, loadMoreToken: 0, isCached: true, allEntityFiles: allEntityFiles) - self.loadMore() + self.loadMore(completion: nil) }) } @@ -527,16 +529,26 @@ public final class PeerStoryListContext { self.requestDisposable?.dispose() } - func loadMore() { - if self.isLoadingMore { - return - } + func loadMore(completion: (() -> Void)?) { guard let loadMoreToken = self.stateValue.loadMoreToken else { return } + if let completion = completion { + if self.completionCallbacksByToken[loadMoreToken] == nil { + self.completionCallbacksByToken[loadMoreToken] = [] + } + self.completionCallbacksByToken[loadMoreToken]?.append(completion) + } + + if self.isLoadingMore { + return + } + self.isLoadingMore = true + let limit = 100 + let peerId = self.peerId let account = self.account let accountPeerId = account.peerId @@ -551,9 +563,9 @@ public final class PeerStoryListContext { let signal: Signal if isArchived { - signal = account.network.request(Api.functions.stories.getStoriesArchive(offsetId: Int32(loadMoreToken), limit: 100)) + signal = account.network.request(Api.functions.stories.getStoriesArchive(offsetId: Int32(loadMoreToken), limit: Int32(limit))) } else { - signal = account.network.request(Api.functions.stories.getPinnedStories(userId: inputUser, offsetId: Int32(loadMoreToken), limit: 100)) + signal = account.network.request(Api.functions.stories.getPinnedStories(userId: inputUser, offsetId: Int32(loadMoreToken), limit: Int32(limit))) } return signal |> map { result -> Api.stories.Stories? in @@ -575,7 +587,7 @@ public final class PeerStoryListContext { switch result { case let .stories(count, stories, users): totalCount = Int(count) - hasMore = stories.count >= 100 + hasMore = stories.count >= limit updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: AccumulatedPeers(users: users)) @@ -664,6 +676,12 @@ public final class PeerStoryListContext { } self.stateValue = updatedState + if let callbacks = self.completionCallbacksByToken.removeValue(forKey: loadMoreToken) { + for f in callbacks { + f() + } + } + if self.updatesDisposable == nil { self.updatesDisposable = (self.account.stateManager.storyUpdates |> deliverOn(self.queue)).start(next: { [weak self] updates in @@ -863,9 +881,9 @@ public final class PeerStoryListContext { }) } - public func loadMore() { + public func loadMore(completion: (() -> Void)? = nil) { self.impl.with { impl in - impl.loadMore() + impl.loadMore(completion : completion) } } } diff --git a/submodules/TelegramUI/Components/PeerInfo/PeerInfoVisualMediaPaneNode/Sources/PeerInfoStoryPaneNode.swift b/submodules/TelegramUI/Components/PeerInfo/PeerInfoVisualMediaPaneNode/Sources/PeerInfoStoryPaneNode.swift index 116bd2d467..52be5dd889 100644 --- a/submodules/TelegramUI/Components/PeerInfo/PeerInfoVisualMediaPaneNode/Sources/PeerInfoStoryPaneNode.swift +++ b/submodules/TelegramUI/Components/PeerInfo/PeerInfoVisualMediaPaneNode/Sources/PeerInfoStoryPaneNode.swift @@ -1488,7 +1488,7 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr self.requestHistoryAroundVisiblePosition(synchronous: false, reloadAtTop: false) - if peerId == context.account.peerId { + if peerId == context.account.peerId && !isArchive { self.preloadArchiveListContext = PeerStoryListContext(account: context.account, peerId: peerId, isArchived: true) } } @@ -1502,8 +1502,13 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr public func loadHole(anchor: SparseItemGrid.HoleAnchor, at location: SparseItemGrid.HoleLocation) -> Signal { let listSource = self.listSource - return Signal { _ in - listSource.loadMore() + return Signal { subscriber in + listSource.loadMore(completion: { + Queue.mainQueue().async { + subscriber.putCompletion() + } + }) + return EmptyDisposable } @@ -1584,8 +1589,8 @@ public final class PeerInfoStoryPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr localMonthTimestamp: Month(localTimestamp: item.timestamp + timezoneOffset).packedValue )) } - if mappedItems.count < state.totalCount, let lastItem = state.items.last { - mappedHoles.append(VisualMediaHoleAnchor(index: mappedItems.count, storyId: 1, localMonthTimestamp: Month(localTimestamp: lastItem.timestamp + timezoneOffset).packedValue)) + if mappedItems.count < state.totalCount, let lastItem = state.items.last, let loadMoreToken = state.loadMoreToken { + mappedHoles.append(VisualMediaHoleAnchor(index: mappedItems.count, storyId: Int32(loadMoreToken), localMonthTimestamp: Month(localTimestamp: lastItem.timestamp + timezoneOffset).packedValue)) } } totalCount = state.totalCount diff --git a/submodules/TelegramUI/Components/Settings/ArchiveInfoScreen/Sources/ArchiveInfoContentComponent.swift b/submodules/TelegramUI/Components/Settings/ArchiveInfoScreen/Sources/ArchiveInfoContentComponent.swift index c8c1c83636..a5020116f7 100644 --- a/submodules/TelegramUI/Components/Settings/ArchiveInfoScreen/Sources/ArchiveInfoContentComponent.swift +++ b/submodules/TelegramUI/Components/Settings/ArchiveInfoScreen/Sources/ArchiveInfoContentComponent.swift @@ -125,11 +125,17 @@ public final class ArchiveInfoContentComponent: Component { contentHeight += iconSize contentHeight += 15.0 + let titleString = NSMutableAttributedString() + titleString.append(NSAttributedString(string: "This is Your Archive", font: Font.semibold(19.0), textColor: component.theme.list.itemPrimaryTextColor)) + let imageAttachment = NSTextAttachment() + imageAttachment.image = self.iconBackground.image + titleString.append(NSAttributedString(attachment: imageAttachment)) + //TODO:localize let titleSize = self.title.update( transition: .immediate, component: AnyComponent(MultilineTextComponent( - text: .plain(NSAttributedString(string: "This is Your Archive", font: Font.semibold(19.0), textColor: component.theme.list.itemPrimaryTextColor)), + text: .plain(titleString), maximumNumberOfLines: 1 )), environment: {}, diff --git a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemContentComponent.swift b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemContentComponent.swift index 578a62c639..5b71efa33e 100644 --- a/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemContentComponent.swift +++ b/submodules/TelegramUI/Components/Stories/StoryContainerScreen/Sources/StoryItemContentComponent.swift @@ -163,7 +163,7 @@ final class StoryItemContentComponent: Component { videoNode.isHidden = true self.videoNode = videoNode - self.addSubnode(videoNode) + //self.addSubview(videoNode.view) videoNode.playbackCompleted = { [weak self] in guard let self else { diff --git a/submodules/TelegramUI/Sources/ChatMessageDateHeader.swift b/submodules/TelegramUI/Sources/ChatMessageDateHeader.swift index 62fc5e9647..7465e2ca1f 100644 --- a/submodules/TelegramUI/Sources/ChatMessageDateHeader.swift +++ b/submodules/TelegramUI/Sources/ChatMessageDateHeader.swift @@ -609,8 +609,8 @@ final class ChatMessageAvatarHeaderNode: ListViewItemHeaderNode { if self.storyStats != storyStats || self.presentationData.theme.theme !== theme || force { self.avatarNode.setStoryStats(storyStats: storyStats.flatMap { storyStats in return AvatarNode.StoryStats( - totalCount: storyStats.totalCount, - unseenCount: storyStats.unseenCount, + totalCount: storyStats.totalCount != 0 ? 1 : 0, + unseenCount: storyStats.unseenCount != 0 ? 1 : 0, hasUnseenCloseFriendsItems: storyStats.hasUnseenCloseFriends ) }, presentationParams: AvatarNode.StoryPresentationParams( diff --git a/submodules/TelegramUI/Sources/ChatMessageItem.swift b/submodules/TelegramUI/Sources/ChatMessageItem.swift index 976eece1c1..3290e4bebc 100644 --- a/submodules/TelegramUI/Sources/ChatMessageItem.swift +++ b/submodules/TelegramUI/Sources/ChatMessageItem.swift @@ -406,12 +406,15 @@ public final class ChatMessageItem: ListViewItem, CustomStringConvertible { if hasAvatar { if let effectiveAuthor = effectiveAuthor { - let storyStats: PeerStoryStats? - switch content { - case let .message(_, _, _, attributes, _): - storyStats = attributes.authorStoryStats - case let .group(messages): - storyStats = messages.first?.3.authorStoryStats + var storyStats: PeerStoryStats? + if case .peer(id: context.account.peerId) = chatLocation { + } else { + switch content { + case let .message(_, _, _, attributes, _): + storyStats = attributes.authorStoryStats + case let .group(messages): + storyStats = messages.first?.3.authorStoryStats + } } avatarHeader = ChatMessageAvatarHeader(timestamp: content.index.timestamp, peerId: effectiveAuthor.id, peer: effectiveAuthor, messageReference: MessageReference(message), message: message, presentationData: presentationData, context: context, controllerInteraction: controllerInteraction, storyStats: storyStats)