mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-21 13:04:42 +00:00
Bring back history preload
Grouping updates
This commit is contained in:
parent
34002d0dad
commit
f3d30efc95
@ -240,13 +240,11 @@ final class ChatListTable: Table {
|
||||
}
|
||||
}
|
||||
|
||||
func getPinnedItemIds(messageHistoryTable: MessageHistoryTable, peerChatInterfaceStateTable: PeerChatInterfaceStateTable) -> [PinnedItemId] {
|
||||
func getPinnedItemIds(groupId: PeerGroupId?, messageHistoryTable: MessageHistoryTable, peerChatInterfaceStateTable: PeerChatInterfaceStateTable) -> [PinnedItemId] {
|
||||
var itemIds: [PinnedItemId] = []
|
||||
self.valueBox.range(self.table, start: self.upperBound(groupId: nil), end: self.key(groupId: nil, index: ChatListIndex(pinningIndex: UInt16.max - 1, messageIndex: MessageIndex.absoluteUpperBound()), type: .message).successor, values: { key, value in
|
||||
let entry = readEntry(groupId: nil, messageHistoryTable: messageHistoryTable, peerChatInterfaceStateTable: peerChatInterfaceStateTable, key: key, value: value)
|
||||
self.valueBox.range(self.table, start: self.upperBound(groupId: groupId), end: self.key(groupId: groupId, index: ChatListIndex(pinningIndex: UInt16.max - 1, messageIndex: MessageIndex.absoluteUpperBound()), type: .message).successor, values: { key, value in
|
||||
let entry = readEntry(groupId: groupId, messageHistoryTable: messageHistoryTable, peerChatInterfaceStateTable: peerChatInterfaceStateTable, key: key, value: value)
|
||||
switch entry {
|
||||
/*case let .groupReference(groupId, _):
|
||||
itemIds.append(.group(groupId))*/
|
||||
case let .message(index, _, _):
|
||||
itemIds.append(.peer(index.messageIndex.id.peerId))
|
||||
default:
|
||||
@ -257,9 +255,9 @@ final class ChatListTable: Table {
|
||||
return itemIds
|
||||
}
|
||||
|
||||
func setPinnedItemIds(_ itemIds: [PinnedItemId], updatedChatListInclusions: inout [PeerId: PeerChatListInclusion], updatedChatListGroupInclusions: inout [PeerGroupId: GroupChatListInclusion], messageHistoryTable: MessageHistoryTable, peerChatInterfaceStateTable: PeerChatInterfaceStateTable) {
|
||||
func setPinnedItemIds(groupId: PeerGroupId?, itemIds: [PinnedItemId], updatedChatListInclusions: inout [PeerId: PeerChatListInclusion], updatedChatListGroupInclusions: inout [PeerGroupId: GroupChatListInclusion], messageHistoryTable: MessageHistoryTable, peerChatInterfaceStateTable: PeerChatInterfaceStateTable) {
|
||||
let updatedIds = Set(itemIds)
|
||||
for itemId in self.getPinnedItemIds(messageHistoryTable: messageHistoryTable, peerChatInterfaceStateTable: peerChatInterfaceStateTable) {
|
||||
for itemId in self.getPinnedItemIds(groupId: groupId, messageHistoryTable: messageHistoryTable, peerChatInterfaceStateTable: peerChatInterfaceStateTable) {
|
||||
if !updatedIds.contains(itemId) {
|
||||
switch itemId {
|
||||
case let .peer(peerId):
|
||||
|
@ -46,6 +46,7 @@ public struct ChatListMessageTagSummaryInfo: Equatable {
|
||||
|
||||
public struct ChatListGroupReferenceEntry: Equatable {
|
||||
public let groupId: PeerGroupId
|
||||
public let renderedPeer: RenderedPeer
|
||||
public let message: Message?
|
||||
public let unreadState: ChatListTotalUnreadState
|
||||
|
||||
@ -56,6 +57,9 @@ public struct ChatListGroupReferenceEntry: Equatable {
|
||||
if lhs.unreadState != rhs.unreadState {
|
||||
return false
|
||||
}
|
||||
if lhs.renderedPeer != rhs.renderedPeer {
|
||||
return false
|
||||
}
|
||||
if lhs.message?.stableVersion != rhs.message?.stableVersion {
|
||||
return false
|
||||
}
|
||||
@ -331,11 +335,54 @@ final class MutableChatListView {
|
||||
self.groupEntries.removeAll()
|
||||
for groupId in postbox.chatListTable.existingGroups() {
|
||||
var upperBound: (ChatListIndex, Bool)?
|
||||
var foundMessage: IntermediateMessage?
|
||||
var foundPeerWithIndex: (PeerId, MessageIndex)?
|
||||
inner: while true {
|
||||
if let entry = postbox.chatListTable.earlierEntries(groupId: groupId, index: upperBound, messageHistoryTable: postbox.messageHistoryTable, peerChatInterfaceStateTable: postbox.peerChatInterfaceStateTable, count: 1).first {
|
||||
if case let .message(_, maybeMessage, _) = entry, let message = maybeMessage {
|
||||
self.groupEntries.append(ChatListGroupReferenceEntry(groupId: groupId, message: postbox.messageHistoryTable.renderMessage(message, peerTable: postbox.peerTable), unreadState: postbox.groupMessageStatsTable.get(groupId: groupId)))
|
||||
break inner
|
||||
var currentTopIndex: MessageIndex?
|
||||
if let (_, foundIndex) = foundPeerWithIndex {
|
||||
currentTopIndex = foundIndex
|
||||
}
|
||||
if let foundMessageValue = foundMessage {
|
||||
if let currentTopIndexValue = currentTopIndex {
|
||||
if foundMessageValue.index > currentTopIndexValue {
|
||||
currentTopIndex = foundMessageValue.index
|
||||
}
|
||||
} else {
|
||||
currentTopIndex = foundMessageValue.index
|
||||
}
|
||||
}
|
||||
|
||||
if case let .message(index, maybeMessage, _) = entry {
|
||||
if let message = maybeMessage {
|
||||
if let currentTopIndex = currentTopIndex {
|
||||
if message.index > currentTopIndex {
|
||||
foundMessage = message
|
||||
foundPeerWithIndex = nil
|
||||
}
|
||||
} else {
|
||||
foundMessage = message
|
||||
foundPeerWithIndex = nil
|
||||
}
|
||||
if index.pinningIndex == nil {
|
||||
break inner
|
||||
}
|
||||
upperBound = (entry.index, true)
|
||||
} else {
|
||||
if let currentTopIndex = currentTopIndex {
|
||||
if index.messageIndex > currentTopIndex {
|
||||
foundMessage = nil
|
||||
foundPeerWithIndex = (index.messageIndex.id.peerId, index.messageIndex)
|
||||
}
|
||||
} else {
|
||||
foundMessage = nil
|
||||
foundPeerWithIndex = (index.messageIndex.id.peerId, index.messageIndex)
|
||||
}
|
||||
if index.pinningIndex == nil {
|
||||
break inner
|
||||
}
|
||||
upperBound = (entry.index.predecessor, true)
|
||||
}
|
||||
} else {
|
||||
upperBound = (entry.index, false)
|
||||
}
|
||||
@ -343,6 +390,24 @@ final class MutableChatListView {
|
||||
break inner
|
||||
}
|
||||
}
|
||||
|
||||
if let peerId = foundMessage?.id.peerId ?? foundPeerWithIndex?.0, let peer = postbox.peerTable.get(peerId) {
|
||||
var peers = SimpleDictionary<PeerId, Peer>()
|
||||
peers[peer.id] = peer
|
||||
if let associatedPeerId = peer.associatedPeerId {
|
||||
if let associatedPeer = postbox.peerTable.get(associatedPeerId) {
|
||||
peers[associatedPeer.id] = associatedPeer
|
||||
}
|
||||
}
|
||||
|
||||
let renderedPeer = RenderedPeer(peerId: peerId, peers: peers)
|
||||
|
||||
if let message = foundMessage {
|
||||
self.groupEntries.append(ChatListGroupReferenceEntry(groupId: groupId, renderedPeer: renderedPeer, message: postbox.messageHistoryTable.renderMessage(message, peerTable: postbox.peerTable), unreadState: postbox.groupMessageStatsTable.get(groupId: groupId)))
|
||||
} else if let (peerId, _) = foundPeerWithIndex {
|
||||
self.groupEntries.append(ChatListGroupReferenceEntry(groupId: groupId, renderedPeer: renderedPeer, message: nil, unreadState: postbox.groupMessageStatsTable.get(groupId: groupId)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -418,7 +483,7 @@ final class MutableChatListView {
|
||||
} else {
|
||||
for i in 0 ..< self.groupEntries.count {
|
||||
if let updatedState = transaction.currentUpdatedTotalUnreadStates[WrappedPeerGroupId(groupId: self.groupEntries[i].groupId)] {
|
||||
self.groupEntries[i] = ChatListGroupReferenceEntry(groupId: self.groupEntries[i].groupId, message: self.groupEntries[i].message, unreadState: updatedState)
|
||||
self.groupEntries[i] = ChatListGroupReferenceEntry(groupId: self.groupEntries[i].groupId, renderedPeer: self.groupEntries[i].renderedPeer, message: self.groupEntries[i].message, unreadState: updatedState)
|
||||
hasChanges = true
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import Foundation
|
||||
public struct MessageHistoryViewPeerHole: Equatable, Hashable {
|
||||
public let peerId: PeerId
|
||||
public let namespace: MessageId.Namespace
|
||||
public let indices: IndexSet
|
||||
}
|
||||
|
||||
public enum MessageHistoryViewHole: Equatable, Hashable {
|
||||
@ -178,16 +177,6 @@ public struct MessageHistoryEntry: Comparable {
|
||||
}
|
||||
}
|
||||
|
||||
final class MutableMessageHistoryViewReplayContext {
|
||||
var invalidEarlier: Bool = false
|
||||
var invalidLater: Bool = false
|
||||
var removedEntries: Bool = false
|
||||
|
||||
func empty() -> Bool {
|
||||
return !self.removedEntries && !invalidEarlier && !invalidLater
|
||||
}
|
||||
}
|
||||
|
||||
enum MessageHistoryTopTaggedMessage {
|
||||
case message(Message)
|
||||
case intermediate(IntermediateMessage)
|
||||
@ -276,7 +265,7 @@ public enum MessageHistoryViewReadState {
|
||||
case peer([PeerId: CombinedPeerReadState])
|
||||
}
|
||||
|
||||
public enum HistoryViewInputAnchor {
|
||||
public enum HistoryViewInputAnchor: Equatable {
|
||||
case lowerBound
|
||||
case upperBound
|
||||
case message(MessageId)
|
||||
@ -299,7 +288,7 @@ final class MutableMessageHistoryView {
|
||||
fileprivate var topTaggedMessages: [MessageId.Namespace: MessageHistoryTopTaggedMessage?]
|
||||
fileprivate var additionalDatas: [AdditionalMessageHistoryViewDataEntry]
|
||||
|
||||
fileprivate var sampledState: HistoryViewSample
|
||||
fileprivate(set) var sampledState: HistoryViewSample
|
||||
|
||||
init(postbox: Postbox, orderStatistics: MessageHistoryViewOrderStatistics, peerIds: MessageHistoryViewPeerIds, anchor inputAnchor: HistoryViewInputAnchor, combinedReadStates: MessageHistoryViewReadState?, transientReadStates: MessageHistoryViewReadState?, tag: MessageTags?, count: Int, topTaggedMessages: [MessageId.Namespace: MessageHistoryTopTaggedMessage?], additionalDatas: [AdditionalMessageHistoryViewDataEntry], getMessageCountInRange: (MessageIndex, MessageIndex) -> Int32) {
|
||||
self.anchor = inputAnchor
|
||||
@ -372,7 +361,7 @@ final class MutableMessageHistoryView {
|
||||
}
|
||||
}
|
||||
|
||||
func replay(postbox: Postbox, transaction: PostboxTransaction, updatedMedia: [MediaId: Media?], updatedCachedPeerData: [PeerId: CachedPeerData], context: MutableMessageHistoryViewReplayContext, renderIntermediateMessage: (IntermediateMessage) -> Message) -> Bool {
|
||||
func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool {
|
||||
var operations: [[MessageHistoryOperation]] = []
|
||||
var peerIdsSet = Set<PeerId>()
|
||||
|
||||
@ -501,8 +490,8 @@ final class MutableMessageHistoryView {
|
||||
}
|
||||
}
|
||||
}
|
||||
if !updatedMedia.isEmpty {
|
||||
if loadedState.updateMedia(updatedMedia: updatedMedia) {
|
||||
if !transaction.updatedMedia.isEmpty {
|
||||
if loadedState.updateMedia(updatedMedia: transaction.updatedMedia) {
|
||||
hasChanges = true
|
||||
}
|
||||
}
|
||||
@ -584,7 +573,7 @@ final class MutableMessageHistoryView {
|
||||
switch self.additionalDatas[i] {
|
||||
case let .cachedPeerData(peerId, currentData):
|
||||
currentCachedPeerData = currentData
|
||||
if let updatedData = updatedCachedPeerData[peerId] {
|
||||
if let updatedData = transaction.currentUpdatedCachedPeerData[peerId] {
|
||||
if currentData?.messageIds != updatedData.messageIds {
|
||||
updatedCachedPeerDataMessages = true
|
||||
}
|
||||
@ -700,21 +689,16 @@ final class MutableMessageHistoryView {
|
||||
}
|
||||
}
|
||||
|
||||
return hasChanges
|
||||
}
|
||||
|
||||
func updatePeers(_ peers: [PeerId: Peer]) -> Bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func render(postbox: Postbox) {
|
||||
|
||||
for namespace in self.topTaggedMessages.keys {
|
||||
if let entry = self.topTaggedMessages[namespace]!, case let .intermediate(message) = entry {
|
||||
let item: MessageHistoryTopTaggedMessage? = .message(postbox.messageHistoryTable.renderMessage(message, peerTable: postbox.peerTable))
|
||||
self.topTaggedMessages[namespace] = item
|
||||
if hasChanges {
|
||||
for namespace in self.topTaggedMessages.keys {
|
||||
if let entry = self.topTaggedMessages[namespace]!, case let .intermediate(message) = entry {
|
||||
let item: MessageHistoryTopTaggedMessage? = .message(postbox.messageHistoryTable.renderMessage(message, peerTable: postbox.peerTable))
|
||||
self.topTaggedMessages[namespace] = item
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hasChanges
|
||||
}
|
||||
|
||||
func firstHole() -> (MessageHistoryViewHole, MessageHistoryViewRelativeHoleDirection)? {
|
||||
@ -723,8 +707,8 @@ final class MutableMessageHistoryView {
|
||||
switch loadingSample {
|
||||
case .ready:
|
||||
return nil
|
||||
case let .loadHole(peerId, namespace, _, indices, id):
|
||||
return (MessageHistoryViewHole.peer(MessageHistoryViewPeerHole(peerId: peerId, namespace: namespace, indices: indices)), .aroundId(MessageId(peerId: peerId, namespace: namespace, id: id)))
|
||||
case let .loadHole(peerId, namespace, _, id):
|
||||
return (.peer(MessageHistoryViewPeerHole(peerId: peerId, namespace: namespace)), .aroundId(MessageId(peerId: peerId, namespace: namespace, id: id)))
|
||||
}
|
||||
case let .loaded(loadedSample):
|
||||
if let hole = loadedSample.hole {
|
||||
@ -734,7 +718,7 @@ final class MutableMessageHistoryView {
|
||||
} else {
|
||||
direction = .aroundId(MessageId(peerId: hole.peerId, namespace: hole.namespace, id: hole.startId))
|
||||
}
|
||||
return (MessageHistoryViewHole.peer(MessageHistoryViewPeerHole(peerId: hole.peerId, namespace: hole.namespace, indices: hole.indices)), direction)
|
||||
return (.peer(MessageHistoryViewPeerHole(peerId: hole.peerId, namespace: hole.namespace)), direction)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
@ -88,6 +88,22 @@ func binaryIndexOrLower(_ inputArr: [MessageHistoryEntry], _ searchItem: History
|
||||
return hi
|
||||
}
|
||||
|
||||
func binaryIndexOrLower(_ inputArr: [MessageHistoryMessageEntry], _ searchItem: HistoryViewAnchor) -> Int {
|
||||
var lo = 0
|
||||
var hi = inputArr.count - 1
|
||||
while lo <= hi {
|
||||
let mid = (lo + hi) / 2
|
||||
if searchItem.isGreater(than: inputArr[mid].message.index) {
|
||||
lo = mid + 1
|
||||
} else if searchItem.isLower(than: inputArr[mid].message.index) {
|
||||
hi = mid - 1
|
||||
} else {
|
||||
return mid
|
||||
}
|
||||
}
|
||||
return hi
|
||||
}
|
||||
|
||||
private func binaryIndexOrLower(_ inputArr: [MutableMessageHistoryEntry], _ searchItem: HistoryViewAnchor) -> Int {
|
||||
var lo = 0
|
||||
var hi = inputArr.count - 1
|
||||
@ -215,7 +231,7 @@ private func isIndex(index: MessageIndex, closerTo anchor: HistoryViewAnchor, th
|
||||
|
||||
private func sampleHoleRanges(orderedEntriesBySpace: [PeerIdAndNamespace: OrderedHistoryViewEntries], holes: HistoryViewHoles, anchor: HistoryViewAnchor, tag: MessageTags?) -> (clipRanges: [ClosedRange<MessageIndex>], sampledHole: SampledHistoryViewHole?) {
|
||||
var clipRanges: [ClosedRange<MessageIndex>] = []
|
||||
var sampledHole: (itemIndex: Int, hole: SampledHistoryViewHole)?
|
||||
var sampledHole: (itemIndex: Int?, hole: SampledHistoryViewHole)?
|
||||
|
||||
for (space, indices) in holes.holesBySpace {
|
||||
if indices.isEmpty {
|
||||
@ -242,7 +258,12 @@ private func sampleHoleRanges(orderedEntriesBySpace: [PeerIdAndNamespace: Ordere
|
||||
case .upperBound, .index:
|
||||
holeBounds = (Int32.max - 1, 1)
|
||||
}
|
||||
return ([MessageIndex.absoluteLowerBound() ... MessageIndex.absoluteUpperBound()], SampledHistoryViewHole(peerId: space.peerId, namespace: space.namespace, tag: tag, indices: indices, startId: holeBounds.startId, endId: holeBounds.endId))
|
||||
if case let .index(index) = anchor, index.id.peerId == space.peerId {
|
||||
return ([MessageIndex.absoluteLowerBound() ... MessageIndex.absoluteUpperBound()], SampledHistoryViewHole(peerId: space.peerId, namespace: space.namespace, tag: tag, indices: indices, startId: holeBounds.startId, endId: holeBounds.endId))
|
||||
} else {
|
||||
sampledHole = (nil, SampledHistoryViewHole(peerId: space.peerId, namespace: space.namespace, tag: tag, indices: indices, startId: holeBounds.startId, endId: holeBounds.endId))
|
||||
continue
|
||||
}
|
||||
}
|
||||
guard let bounds = items.bounds else {
|
||||
assertionFailure("A non-empty entry list should have non-nil bounds")
|
||||
@ -285,7 +306,7 @@ private func sampleHoleRanges(orderedEntriesBySpace: [PeerIdAndNamespace: Ordere
|
||||
clipRanges.append(MessageIndex.absoluteLowerBound() ... itemClipIndex)
|
||||
var replaceHole = false
|
||||
if let (currentItemIndex, _) = sampledHole {
|
||||
if abs(lowerDirectionIndex - anchorIndex) < abs(currentItemIndex - anchorIndex) {
|
||||
if let currentItemIndex = currentItemIndex, abs(lowerDirectionIndex - anchorIndex) < abs(currentItemIndex - anchorIndex) {
|
||||
replaceHole = true
|
||||
}
|
||||
} else {
|
||||
@ -327,7 +348,7 @@ private func sampleHoleRanges(orderedEntriesBySpace: [PeerIdAndNamespace: Ordere
|
||||
clipRanges.append(itemClipIndex ... MessageIndex.absoluteUpperBound())
|
||||
var replaceHole = false
|
||||
if let (currentItemIndex, _) = sampledHole {
|
||||
if abs(higherDirectionIndex - anchorIndex) < abs(currentItemIndex - anchorIndex) {
|
||||
if let currentItemIndex = currentItemIndex, abs(higherDirectionIndex - anchorIndex) < abs(currentItemIndex - anchorIndex) {
|
||||
replaceHole = true
|
||||
}
|
||||
} else {
|
||||
@ -800,7 +821,7 @@ private func fetchHoles(postbox: Postbox, locations: MessageHistoryViewPeerIds,
|
||||
|
||||
enum HistoryViewLoadingSample {
|
||||
case ready(HistoryViewAnchor, HistoryViewHoles)
|
||||
case loadHole(PeerId, MessageId.Namespace, MessageTags?, IndexSet, MessageId.Id)
|
||||
case loadHole(PeerId, MessageId.Namespace, MessageTags?, MessageId.Id)
|
||||
}
|
||||
|
||||
final class HistoryViewLoadingState {
|
||||
@ -828,7 +849,7 @@ final class HistoryViewLoadingState {
|
||||
while true {
|
||||
if let indices = self.holes.holesBySpace[PeerIdAndNamespace(peerId: self.messageId.peerId, namespace: self.messageId.namespace)] {
|
||||
if indices.contains(Int(messageId.id)) {
|
||||
return .loadHole(messageId.peerId, messageId.namespace, self.tag, indices, messageId.id)
|
||||
return .loadHole(messageId.peerId, messageId.namespace, self.tag, messageId.id)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,32 +22,108 @@ public struct MessageOfInterestHole: Hashable, Equatable {
|
||||
|
||||
public enum MessageOfInterestViewLocation: Hashable {
|
||||
case peer(PeerId)
|
||||
|
||||
public static func ==(lhs: MessageOfInterestViewLocation, rhs: MessageOfInterestViewLocation) -> Bool {
|
||||
switch lhs {
|
||||
case let .peer(value):
|
||||
if case .peer(value) = rhs {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var hashValue: Int {
|
||||
switch self {
|
||||
case let .peer(id):
|
||||
return id.hashValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class MutableMessageOfInterestHolesView: MutablePostboxView {
|
||||
private let location: MessageOfInterestViewLocation
|
||||
private let count: Int
|
||||
private var anchor: HistoryViewInputAnchor
|
||||
private var wrappedView: MutableMessageHistoryView
|
||||
|
||||
fileprivate var closestHole: MessageOfInterestHole?
|
||||
fileprivate var closestLaterMedia: [HolesViewMedia] = []
|
||||
|
||||
init(postbox: Postbox, location: MessageOfInterestViewLocation, namespace: MessageId.Namespace, count: Int) {
|
||||
self.location = location
|
||||
self.count = count
|
||||
|
||||
var peerId: PeerId
|
||||
switch self.location {
|
||||
case let .peer(id):
|
||||
peerId = id
|
||||
}
|
||||
var anchor: HistoryViewInputAnchor = .upperBound
|
||||
if let combinedState = postbox.readStateTable.getCombinedState(peerId), let state = combinedState.states.first, state.1.count != 0 {
|
||||
switch state.1 {
|
||||
case let .idBased(maxIncomingReadId, _, _, _, _):
|
||||
anchor = .message(MessageId(peerId: peerId, namespace: state.0, id: maxIncomingReadId))
|
||||
case let .indexBased(maxIncomingReadIndex, _, _, _):
|
||||
anchor = .index(maxIncomingReadIndex)
|
||||
}
|
||||
}
|
||||
self.anchor = anchor
|
||||
self.wrappedView = MutableMessageHistoryView(postbox: postbox, orderStatistics: [], peerIds: .single(peerId), anchor: self.anchor, combinedReadStates: nil, transientReadStates: nil, tag: nil, count: self.count, topTaggedMessages: [:], additionalDatas: [], getMessageCountInRange: { _, _ in return 0})
|
||||
let _ = self.updateFromView()
|
||||
}
|
||||
|
||||
private func updateFromView() -> Bool {
|
||||
let closestHole: MessageOfInterestHole?
|
||||
if let (hole, direction) = self.wrappedView.firstHole() {
|
||||
closestHole = MessageOfInterestHole(hole: hole, direction: direction)
|
||||
} else {
|
||||
closestHole = nil
|
||||
}
|
||||
|
||||
var closestLaterMedia: [HolesViewMedia] = []
|
||||
switch self.wrappedView.sampledState {
|
||||
case .loading:
|
||||
break
|
||||
case let .loaded(sample):
|
||||
switch sample.anchor {
|
||||
case let .index(index):
|
||||
let anchorIndex = binaryIndexOrLower(sample.entries, sample.anchor)
|
||||
loop: for i in max(0, anchorIndex) ..< sample.entries.count {
|
||||
let message = sample.entries[i].message
|
||||
if !message.media.isEmpty, let peer = message.peers[message.id.peerId] {
|
||||
for media in message.media {
|
||||
closestLaterMedia.append(HolesViewMedia(media: media, peer: peer, authorIsContact: sample.entries[i].attributes.authorIsContact, index: message.index))
|
||||
}
|
||||
}
|
||||
if closestLaterMedia.count >= 3 {
|
||||
break loop
|
||||
}
|
||||
}
|
||||
case .lowerBound, .upperBound:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if self.closestHole != closestHole || self.closestLaterMedia != closestLaterMedia {
|
||||
self.closestHole = closestHole
|
||||
self.closestLaterMedia = closestLaterMedia
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool {
|
||||
return false
|
||||
var peerId: PeerId
|
||||
switch self.location {
|
||||
case let .peer(id):
|
||||
peerId = id
|
||||
}
|
||||
var anchor: HistoryViewInputAnchor = self.anchor
|
||||
if transaction.alteredInitialPeerCombinedReadStates[peerId] != nil {
|
||||
if let combinedState = postbox.readStateTable.getCombinedState(peerId), let state = combinedState.states.first, state.1.count != 0 {
|
||||
switch state.1 {
|
||||
case let .idBased(maxIncomingReadId, _, _, _, _):
|
||||
anchor = .message(MessageId(peerId: peerId, namespace: state.0, id: maxIncomingReadId))
|
||||
case let .indexBased(maxIncomingReadIndex, _, _, _):
|
||||
anchor = .index(maxIncomingReadIndex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.anchor != anchor {
|
||||
self.anchor = anchor
|
||||
self.wrappedView = MutableMessageHistoryView(postbox: postbox, orderStatistics: [], peerIds: .single(peerId), anchor: self.anchor, combinedReadStates: nil, transientReadStates: nil, tag: nil, count: self.count, topTaggedMessages: [:], additionalDatas: [], getMessageCountInRange: { _, _ in return 0})
|
||||
return self.updateFromView()
|
||||
} else if self.wrappedView.replay(postbox: postbox, transaction: transaction) {
|
||||
return self.updateFromView()
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func immutableView() -> PostboxView {
|
||||
@ -60,7 +136,7 @@ public final class MessageOfInterestHolesView: PostboxView {
|
||||
public let closestLaterMedia: [HolesViewMedia]
|
||||
|
||||
init(_ view: MutableMessageOfInterestHolesView) {
|
||||
self.closestHole = nil
|
||||
self.closestLaterMedia = []
|
||||
self.closestHole = view.closestHole
|
||||
self.closestLaterMedia = view.closestLaterMedia
|
||||
}
|
||||
}
|
||||
|
@ -695,19 +695,19 @@ public final class Transaction {
|
||||
self.postbox?.setPreferencesEntry(key: key, value: f(self.postbox?.getPreferencesEntry(key: key)))
|
||||
}
|
||||
|
||||
public func getPinnedItemIds() -> [PinnedItemId] {
|
||||
public func getPinnedItemIds(groupId: PeerGroupId?) -> [PinnedItemId] {
|
||||
assert(!self.disposed)
|
||||
if let postbox = self.postbox {
|
||||
return postbox.chatListTable.getPinnedItemIds(messageHistoryTable: postbox.messageHistoryTable, peerChatInterfaceStateTable: postbox.peerChatInterfaceStateTable)
|
||||
return postbox.chatListTable.getPinnedItemIds(groupId: groupId, messageHistoryTable: postbox.messageHistoryTable, peerChatInterfaceStateTable: postbox.peerChatInterfaceStateTable)
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
public func setPinnedItemIds(_ itemIds: [PinnedItemId]) {
|
||||
public func setPinnedItemIds(groupId: PeerGroupId?, itemIds: [PinnedItemId]) {
|
||||
assert(!self.disposed)
|
||||
if let postbox = self.postbox {
|
||||
postbox.setPinnedItemIds(itemIds)
|
||||
postbox.setPinnedItemIds(groupId: groupId, itemIds: itemIds)
|
||||
}
|
||||
}
|
||||
|
||||
@ -928,7 +928,7 @@ public func openPostbox(basePath: String, seedConfiguration: SeedConfiguration,
|
||||
|
||||
#if DEBUG
|
||||
//debugSaveState(basePath: basePath, name: "previous1")
|
||||
//debugRestoreState(basePath: basePath, name: "previous1")
|
||||
debugRestoreState(basePath: basePath, name: "previous1")
|
||||
#endif
|
||||
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
@ -1805,20 +1805,18 @@ public final class Postbox {
|
||||
let previousGroupId = self.groupAssociationTable.get(peerId: id)
|
||||
if previousGroupId != groupId {
|
||||
self.groupAssociationTable.set(peerId: id, groupId: groupId, initialPeerGroupIdsBeforeUpdate: &self.currentInitialPeerGroupIdsBeforeUpdate)
|
||||
if let _ = groupId {
|
||||
if let index = self.chatListTable.getPeerChatListIndex(peerId: id), index.1.pinningIndex != nil {
|
||||
var itemIds = self.chatListTable.getPinnedItemIds(messageHistoryTable: self.messageHistoryTable, peerChatInterfaceStateTable: self.peerChatInterfaceStateTable)
|
||||
if let index = itemIds.index(of: .peer(id)) {
|
||||
itemIds.remove(at: index)
|
||||
self.chatListTable.setPinnedItemIds(itemIds, updatedChatListInclusions: &self.currentUpdatedChatListInclusions, updatedChatListGroupInclusions: &self.currentUpdatedChatListGroupInclusions, messageHistoryTable: self.messageHistoryTable, peerChatInterfaceStateTable: self.peerChatInterfaceStateTable)
|
||||
}
|
||||
if let index = self.chatListTable.getPeerChatListIndex(peerId: id), index.1.pinningIndex != nil {
|
||||
var itemIds = self.chatListTable.getPinnedItemIds(groupId: previousGroupId, messageHistoryTable: self.messageHistoryTable, peerChatInterfaceStateTable: self.peerChatInterfaceStateTable)
|
||||
if let index = itemIds.index(of: .peer(id)) {
|
||||
itemIds.remove(at: index)
|
||||
self.chatListTable.setPinnedItemIds(groupId: previousGroupId, itemIds: itemIds, updatedChatListInclusions: &self.currentUpdatedChatListInclusions, updatedChatListGroupInclusions: &self.currentUpdatedChatListGroupInclusions, messageHistoryTable: self.messageHistoryTable, peerChatInterfaceStateTable: self.peerChatInterfaceStateTable)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate func setPinnedItemIds(_ itemIds: [PinnedItemId]) {
|
||||
self.chatListTable.setPinnedItemIds(itemIds, updatedChatListInclusions: &self.currentUpdatedChatListInclusions, updatedChatListGroupInclusions: &self.currentUpdatedChatListGroupInclusions, messageHistoryTable: self.messageHistoryTable, peerChatInterfaceStateTable: self.peerChatInterfaceStateTable)
|
||||
fileprivate func setPinnedItemIds(groupId: PeerGroupId?, itemIds: [PinnedItemId]) {
|
||||
self.chatListTable.setPinnedItemIds(groupId: groupId, itemIds: itemIds, updatedChatListInclusions: &self.currentUpdatedChatListInclusions, updatedChatListGroupInclusions: &self.currentUpdatedChatListGroupInclusions, messageHistoryTable: self.messageHistoryTable, peerChatInterfaceStateTable: self.peerChatInterfaceStateTable)
|
||||
}
|
||||
|
||||
fileprivate func updateCurrentPeerNotificationSettings(_ notificationSettings: [PeerId: PeerNotificationSettings]) {
|
||||
@ -2348,7 +2346,6 @@ public final class Postbox {
|
||||
return 0
|
||||
}
|
||||
})
|
||||
mutableView.render(postbox: self)
|
||||
|
||||
let initialUpdateType: ViewUpdateType = .Initial
|
||||
|
||||
|
@ -245,7 +245,6 @@ final class ViewTracker {
|
||||
|
||||
for (mutableView, pipe) in self.messageHistoryViews.copyItems() {
|
||||
if mutableView.refreshDueToExternalTransaction(postbox: postbox) {
|
||||
mutableView.render(postbox: postbox)
|
||||
pipe.putNext((MessageHistoryView(mutableView), .Generic))
|
||||
|
||||
updateTrackedHoles = true
|
||||
@ -292,12 +291,11 @@ final class ViewTracker {
|
||||
}
|
||||
|
||||
for (mutableView, pipe) in self.messageHistoryViews.copyItems() {
|
||||
let context = MutableMessageHistoryViewReplayContext()
|
||||
var updated = false
|
||||
|
||||
let previousPeerIds = mutableView.peerIds
|
||||
|
||||
if mutableView.replay(postbox: postbox, transaction: transaction, updatedMedia: transaction.updatedMedia, updatedCachedPeerData: transaction.currentUpdatedCachedPeerData, context: context, renderIntermediateMessage: self.renderMessage) {
|
||||
if mutableView.replay(postbox: postbox, transaction: transaction) {
|
||||
updated = true
|
||||
}
|
||||
|
||||
@ -331,10 +329,6 @@ final class ViewTracker {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if mutableView.updatePeers(transaction.currentUpdatedPeers) {
|
||||
updated = true
|
||||
}
|
||||
|
||||
mutableView.updatePeerIds(transaction: transaction)
|
||||
if mutableView.peerIds != previousPeerIds {
|
||||
@ -346,8 +340,6 @@ final class ViewTracker {
|
||||
|
||||
if updated {
|
||||
updateTrackedHoles = true
|
||||
mutableView.render(postbox: postbox)
|
||||
|
||||
pipe.putNext((MessageHistoryView(mutableView), updateType))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user