Skip to content

Commit

Permalink
Update peers in message history views
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali committed Oct 26, 2023
1 parent bc09798 commit 99a1a93
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions submodules/Postbox/Sources/MessageHistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,11 @@ final class MutableMessageHistoryView {
hasChanges = true
}
}
if !transaction.currentUpdatedPeers.isEmpty {
if loadedState.updatePeers(postbox: postbox, updatedPeers: transaction.currentUpdatedPeers) {
hasChanges = true
}
}
}

if hasChanges {
Expand Down
37 changes: 37 additions & 0 deletions submodules/Postbox/Sources/MessageHistoryViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,43 @@ final class HistoryViewLoadedState {
return updated
}

func updatePeers(postbox: PostboxImpl, updatedPeers: [PeerId: Peer]) -> 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
var peers = message.peers
var author = message.author
for (peerId, _) in message.peers {
if let updatedPeer = updatedPeers[peerId] {
peers[peerId] = updatedPeer
rebuild = true
}
}
if let authorValue = author, let updatedAuthor = updatedPeers[authorValue.id] {
author = updatedAuthor
rebuild = true
}

if rebuild {
let updatedMessage = message.withUpdatedPeers(peers).withUpdatedAuthor(author)
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ public enum ChatHistoryEntry: Identifiable, Comparable {
if lhsMessage.stableVersion != rhsMessage.stableVersion {
return false
}

if lhsMessage.peers.count != rhsMessage.peers.count {
return false
}
for (id, peer) in lhsMessage.peers {
if let otherPeer = rhsMessage.peers[id] {
if !peer.isEqual(otherPeer) {
return false
}
}
}

if lhsMessage.media.count != rhsMessage.media.count {
return false
}
Expand Down

0 comments on commit 99a1a93

Please sign in to comment.