mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
[WIP] Topics
This commit is contained in:
@@ -5,27 +5,32 @@ final class MutableMessageHistoryThreadIndexView: MutablePostboxView {
|
||||
let id: Int64
|
||||
let index: MessageIndex
|
||||
var info: CodableEntry
|
||||
var tagSummaryInfo: [ChatListEntryMessageTagSummaryKey: ChatListMessageTagSummaryInfo]
|
||||
var topMessage: Message?
|
||||
|
||||
init(
|
||||
id: Int64,
|
||||
index: MessageIndex,
|
||||
info: CodableEntry,
|
||||
tagSummaryInfo: [ChatListEntryMessageTagSummaryKey: ChatListMessageTagSummaryInfo],
|
||||
topMessage: Message?
|
||||
) {
|
||||
self.id = id
|
||||
self.index = index
|
||||
self.info = info
|
||||
self.tagSummaryInfo = tagSummaryInfo
|
||||
self.topMessage = topMessage
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate let peerId: PeerId
|
||||
fileprivate let summaryComponents: ChatListEntrySummaryComponents
|
||||
fileprivate var peer: Peer?
|
||||
fileprivate var items: [Item] = []
|
||||
|
||||
init(postbox: PostboxImpl, peerId: PeerId) {
|
||||
init(postbox: PostboxImpl, peerId: PeerId, summaryComponents: ChatListEntrySummaryComponents) {
|
||||
self.peerId = peerId
|
||||
self.summaryComponents = summaryComponents
|
||||
|
||||
self.reload(postbox: postbox)
|
||||
}
|
||||
@@ -36,10 +41,34 @@ final class MutableMessageHistoryThreadIndexView: MutablePostboxView {
|
||||
self.peer = postbox.peerTable.get(self.peerId)
|
||||
|
||||
for item in postbox.messageHistoryThreadIndexTable.getAll(peerId: self.peerId) {
|
||||
var tagSummaryInfo: [ChatListEntryMessageTagSummaryKey: ChatListMessageTagSummaryInfo] = [:]
|
||||
for (key, component) in self.summaryComponents.components {
|
||||
var tagSummaryCount: Int32?
|
||||
var actionsSummaryCount: Int32?
|
||||
|
||||
if let tagSummary = component.tagSummary {
|
||||
let key = MessageHistoryTagsSummaryKey(tag: key.tag, peerId: self.peerId, threadId: item.threadId, namespace: tagSummary.namespace)
|
||||
if let summary = postbox.messageHistoryTagsSummaryTable.get(key) {
|
||||
tagSummaryCount = summary.count
|
||||
}
|
||||
}
|
||||
|
||||
if let actionsSummary = component.actionsSummary {
|
||||
let key = PendingMessageActionsSummaryKey(type: key.actionType, peerId: self.peerId, namespace: actionsSummary.namespace)
|
||||
actionsSummaryCount = postbox.pendingMessageActionsMetadataTable.getCount(.peerNamespaceAction(key.peerId, key.namespace, key.type))
|
||||
}
|
||||
|
||||
tagSummaryInfo[key] = ChatListMessageTagSummaryInfo(
|
||||
tagSummaryCount: tagSummaryCount,
|
||||
actionsSummaryCount: actionsSummaryCount
|
||||
)
|
||||
}
|
||||
|
||||
self.items.append(Item(
|
||||
id: item.threadId,
|
||||
index: item.index,
|
||||
info: item.info,
|
||||
tagSummaryInfo: tagSummaryInfo,
|
||||
topMessage: postbox.getMessage(item.index.id)
|
||||
))
|
||||
}
|
||||
@@ -48,7 +77,7 @@ final class MutableMessageHistoryThreadIndexView: MutablePostboxView {
|
||||
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
|
||||
var updated = false
|
||||
|
||||
if transaction.updatedMessageThreadPeerIds.contains(self.peerId) {
|
||||
if transaction.updatedMessageThreadPeerIds.contains(self.peerId) || transaction.currentUpdatedMessageTagSummaries.contains(where: { $0.key.peerId == self.peerId }) || transaction.currentUpdatedMessageActionsSummaries.contains(where: { $0.key.peerId == self.peerId }) {
|
||||
self.reload(postbox: postbox)
|
||||
updated = true
|
||||
}
|
||||
@@ -70,17 +99,20 @@ public final class EngineMessageHistoryThread {
|
||||
public let id: Int64
|
||||
public let index: MessageIndex
|
||||
public let info: CodableEntry
|
||||
public let tagSummaryInfo: [ChatListEntryMessageTagSummaryKey: ChatListMessageTagSummaryInfo]
|
||||
public let topMessage: Message?
|
||||
|
||||
public init(
|
||||
id: Int64,
|
||||
index: MessageIndex,
|
||||
info: CodableEntry,
|
||||
tagSummaryInfo: [ChatListEntryMessageTagSummaryKey: ChatListMessageTagSummaryInfo],
|
||||
topMessage: Message?
|
||||
) {
|
||||
self.id = id
|
||||
self.index = index
|
||||
self.info = info
|
||||
self.tagSummaryInfo = tagSummaryInfo
|
||||
self.topMessage = topMessage
|
||||
}
|
||||
|
||||
@@ -94,6 +126,9 @@ public final class EngineMessageHistoryThread {
|
||||
if lhs.info != rhs.info {
|
||||
return false
|
||||
}
|
||||
if lhs.tagSummaryInfo != rhs.tagSummaryInfo {
|
||||
return false
|
||||
}
|
||||
if let lhsMessage = lhs.topMessage, let rhsMessage = rhs.topMessage {
|
||||
if lhsMessage.index != rhsMessage.index {
|
||||
return false
|
||||
@@ -123,6 +158,7 @@ public final class MessageHistoryThreadIndexView: PostboxView {
|
||||
id: item.id,
|
||||
index: item.index,
|
||||
info: item.info,
|
||||
tagSummaryInfo: item.tagSummaryInfo,
|
||||
topMessage: item.topMessage
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user