[WIP] Stories

This commit is contained in:
Ali
2023-06-10 00:29:41 +04:00
parent 749023af1f
commit 8a09cd5f70
12 changed files with 433 additions and 24 deletions

View File

@@ -1457,6 +1457,63 @@ final class HistoryViewLoadedState {
return updated
}
func updateStories(postbox: PostboxImpl, updatedStories: Set<StoryId>) -> Bool {
var updated = false
for space in self.orderedEntriesBySpace.keys {
let spaceUpdated = self.orderedEntriesBySpace[space]!.mutableScan({ entry in
switch entry {
case let .MessageEntry(value, reloadAssociatedMessages, reloadPeers):
let message = value.message
var rebuild = false
for media in message.media {
for storyId in media.storyIds {
if updatedStories.contains(storyId) {
rebuild = true
break
}
}
}
for attribute in message.attributes {
for storyId in attribute.associatedStoryIds {
if updatedStories.contains(storyId) {
rebuild = true
break
}
}
}
if rebuild {
let messageMedia: [Media] = message.media
var associatedStories: [StoryId: CodableEntry] = [:]
for media in message.media {
for storyId in media.storyIds {
if associatedStories[storyId] == nil, let value = postbox.storyTable.get(id: storyId) {
associatedStories[storyId] = value
}
}
}
for attribute in message.attributes {
for storyId in attribute.associatedStoryIds {
if associatedStories[storyId] == nil, let value = postbox.storyTable.get(id: storyId) {
associatedStories[storyId] = value
}
}
}
let updatedMessage = Message(stableId: message.stableId, stableVersion: message.stableVersion, id: message.id, globallyUniqueId: message.globallyUniqueId, groupingKey: message.groupingKey, groupInfo: message.groupInfo, threadId: message.threadId, timestamp: message.timestamp, flags: message.flags, tags: message.tags, globalTags: message.globalTags, localTags: message.localTags, forwardInfo: message.forwardInfo, author: message.author, text: message.text, attributes: message.attributes, media: messageMedia, peers: message.peers, associatedMessages: message.associatedMessages, associatedMessageIds: message.associatedMessageIds, associatedMedia: message.associatedMedia, associatedThreadInfo: message.associatedThreadInfo, associatedStories: associatedStories)
return .MessageEntry(MessageHistoryMessageEntry(message: updatedMessage, location: value.location, monthLocation: value.monthLocation, attributes: value.attributes), reloadAssociatedMessages: reloadAssociatedMessages, reloadPeers: reloadPeers)
}
case .IntermediateMessageEntry:
break
}
return nil
})
if spaceUpdated {
updated = true
}
}
return updated
}
func add(entry: MutableMessageHistoryEntry) -> Bool {
if let ignoreMessagesInTimestampRange = self.ignoreMessagesInTimestampRange {
if ignoreMessagesInTimestampRange.contains(entry.index.timestamp) {