From eb5fa016e06d891a669d22d63914f221e52baa40 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sat, 22 Oct 2022 01:54:19 +0400 Subject: [PATCH] [WIP] Topics --- .../TelegramCore/Sources/ForumChannels.swift | 24 +++++++++++++++---- .../State/AccountStateManagementUtils.swift | 4 +++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/submodules/TelegramCore/Sources/ForumChannels.swift b/submodules/TelegramCore/Sources/ForumChannels.swift index a0c2d8ce23..eca113aab6 100644 --- a/submodules/TelegramCore/Sources/ForumChannels.swift +++ b/submodules/TelegramCore/Sources/ForumChannels.swift @@ -500,10 +500,24 @@ func _internal_loadMessageHistoryThreads(accountPeerId: PeerId, postbox: Postbox transaction.replaceMessageTagSummary(peerId: peerId, threadId: Int64(id), tagMask: .unseenPersonalMessage, namespace: Namespaces.Message.Cloud, count: unreadMentionsCount, maxId: topMessage) transaction.replaceMessageTagSummary(peerId: peerId, threadId: Int64(id), tagMask: .unseenReaction, namespace: Namespaces.Message.Cloud, count: unreadReactionsCount, maxId: topMessage) + if topMessage != 0 { + transaction.removeHole(peerId: peerId, threadId: Int64(id), namespace: Namespaces.Message.Cloud, space: .everywhere, range: topMessage ... (Int32.max - 1)) + } + var topTimestamp = date for message in addedMessages { if message.id.peerId == peerId && message.threadId == Int64(id) { topTimestamp = max(topTimestamp, message.timestamp) + + if case let .Id(messageId) = message.id { + for media in message.media { + if let action = media as? TelegramMediaAction { + if case .topicCreated = action.action { + transaction.removeHole(peerId: messageId.peerId, threadId: Int64(id), namespace: Namespaces.Message.Cloud, space: .everywhere, range: 1 ... messageId.id) + } + } + } + } } } @@ -520,10 +534,12 @@ func _internal_loadMessageHistoryThreads(accountPeerId: PeerId, postbox: Postbox } } - if let pinnedId = pinnedId { - transaction.setPeerPinnedThreads(peerId: peerId, threadIds: [pinnedId]) - } else { - transaction.setPeerPinnedThreads(peerId: peerId, threadIds: []) + if offsetIndex != nil { + if let pinnedId = pinnedId { + transaction.setPeerPinnedThreads(peerId: peerId, threadIds: [pinnedId]) + } else { + transaction.setPeerPinnedThreads(peerId: peerId, threadIds: []) + } } var nextIndex: StoredPeerThreadCombinedState.Index diff --git a/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift b/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift index 59ddb2ff52..47cc5c9d71 100644 --- a/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift +++ b/submodules/TelegramCore/Sources/State/AccountStateManagementUtils.swift @@ -3027,6 +3027,8 @@ func replayFinalState( for media in message.media { if let action = media as? TelegramMediaAction { switch action.action { + case .topicCreated: + transaction.removeHole(peerId: id.peerId, threadId: threadId, namespace: Namespaces.Message.Cloud, space: .everywhere, range: 1 ... id.id) case let .topicEdited(components): if let initialData = transaction.getMessageHistoryThreadInfo(peerId: id.peerId, threadId: threadId)?.data.get(MessageHistoryThreadData.self) { var data = initialData @@ -3038,7 +3040,7 @@ func replayFinalState( case let .iconFileId(fileId): data.info = EngineMessageHistoryThread.Info(title: data.info.title, icon: fileId == 0 ? nil : fileId, iconColor: data.info.iconColor) case let .isClosed(isClosed): - let _ = isClosed + data.isClosed = isClosed } }