mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Comments update
This commit is contained in:
@@ -3,9 +3,16 @@ import Foundation
|
||||
public struct MessageHistoryViewPeerHole: Equatable, Hashable, CustomStringConvertible {
|
||||
public let peerId: PeerId
|
||||
public let namespace: MessageId.Namespace
|
||||
public let threadId: Int64?
|
||||
|
||||
public init(peerId: PeerId, namespace: MessageId.Namespace, threadId: Int64?) {
|
||||
self.peerId = peerId
|
||||
self.namespace = namespace
|
||||
self.threadId = threadId
|
||||
}
|
||||
|
||||
public var description: String {
|
||||
return "peerId: \(self.peerId), namespace: \(self.namespace)"
|
||||
return "peerId: \(self.peerId), namespace: \(self.namespace), threadId: \(String(describing: self.threadId))"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,18 +133,18 @@ enum MutableMessageHistoryEntry {
|
||||
func updatedTimestamp(_ timestamp: Int32) -> MutableMessageHistoryEntry {
|
||||
switch self {
|
||||
case let .IntermediateMessageEntry(message, location, monthLocation):
|
||||
let updatedMessage = IntermediateMessage(stableId: message.stableId, stableVersion: message.stableVersion, id: message.id, globallyUniqueId: message.globallyUniqueId, groupingKey: message.groupingKey, groupInfo: message.groupInfo, timestamp: timestamp, flags: message.flags, tags: message.tags, globalTags: message.globalTags, localTags: message.localTags, forwardInfo: message.forwardInfo, authorId: message.authorId, text: message.text, attributesData: message.attributesData, embeddedMediaData: message.embeddedMediaData, referencedMedia: message.referencedMedia)
|
||||
let updatedMessage = IntermediateMessage(stableId: message.stableId, stableVersion: message.stableVersion, id: message.id, globallyUniqueId: message.globallyUniqueId, groupingKey: message.groupingKey, groupInfo: message.groupInfo, threadId: message.threadId, timestamp: timestamp, flags: message.flags, tags: message.tags, globalTags: message.globalTags, localTags: message.localTags, forwardInfo: message.forwardInfo, authorId: message.authorId, text: message.text, attributesData: message.attributesData, embeddedMediaData: message.embeddedMediaData, referencedMedia: message.referencedMedia)
|
||||
return .IntermediateMessageEntry(updatedMessage, location, monthLocation)
|
||||
case let .MessageEntry(value, reloadAssociatedMessages, reloadPeers):
|
||||
let message = value.message
|
||||
let updatedMessage = Message(stableId: message.stableId, stableVersion: message.stableVersion, id: message.id, globallyUniqueId: message.globallyUniqueId, groupingKey: message.groupingKey, groupInfo: message.groupInfo, timestamp: 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: message.media, peers: message.peers, associatedMessages: message.associatedMessages, associatedMessageIds: message.associatedMessageIds)
|
||||
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: 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: message.media, peers: message.peers, associatedMessages: message.associatedMessages, associatedMessageIds: message.associatedMessageIds)
|
||||
return .MessageEntry(MessageHistoryMessageEntry(message: updatedMessage, location: value.location, monthLocation: value.monthLocation, attributes: value.attributes), reloadAssociatedMessages: reloadAssociatedMessages, reloadPeers: reloadPeers)
|
||||
}
|
||||
}
|
||||
|
||||
func getAssociatedMessageIds() -> [MessageId] {
|
||||
switch self {
|
||||
case let .IntermediateMessageEntry(message, location, monthLocation):
|
||||
case .IntermediateMessageEntry:
|
||||
return []
|
||||
case let .MessageEntry(value, _, _):
|
||||
return value.message.associatedMessageIds
|
||||
@@ -236,15 +243,42 @@ public struct MessageHistoryViewOrderStatistics: OptionSet {
|
||||
public static let locationWithinMonth = MessageHistoryViewOrderStatistics(rawValue: 1 << 1)
|
||||
}
|
||||
|
||||
public protocol MessageHistoryViewExternalInput: class {
|
||||
func getNamespaces() -> [MessageId.Namespace]
|
||||
func getMessageIds(namespace: MessageId.Namespace) -> [MessageId]
|
||||
func getHoleIndices(namespace: MessageId.Namespace) -> IndexSet
|
||||
public final class MessageHistoryViewExternalInput: Equatable {
|
||||
public let peerId: PeerId
|
||||
public let threadId: Int64
|
||||
public let holes: [MessageId.Namespace: IndexSet]
|
||||
|
||||
public init(
|
||||
peerId: PeerId,
|
||||
threadId: Int64,
|
||||
holes: [MessageId.Namespace: IndexSet]
|
||||
) {
|
||||
self.peerId = peerId
|
||||
self.threadId = threadId
|
||||
self.holes = holes
|
||||
}
|
||||
|
||||
public static func ==(lhs: MessageHistoryViewExternalInput, rhs: MessageHistoryViewExternalInput) -> Bool {
|
||||
if lhs === rhs {
|
||||
return true
|
||||
}
|
||||
if lhs.peerId != rhs.peerId {
|
||||
return false
|
||||
}
|
||||
if lhs.threadId != rhs.threadId {
|
||||
return false
|
||||
}
|
||||
if lhs.holes != rhs.holes {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
public enum MessageHistoryViewInput: Equatable {
|
||||
case single(PeerId)
|
||||
case associated(PeerId, MessageId?)
|
||||
case external(MessageHistoryViewExternalInput)
|
||||
}
|
||||
|
||||
public enum MessageHistoryViewReadState {
|
||||
@@ -294,14 +328,14 @@ final class MutableMessageHistoryView {
|
||||
self.topTaggedMessages = topTaggedMessages
|
||||
self.additionalDatas = additionalDatas
|
||||
|
||||
let mainPeerId: PeerId
|
||||
switch peerIds {
|
||||
case let .associated(peerId, _):
|
||||
mainPeerId = peerId
|
||||
self.isAddedToChatList = postbox.chatListTable.getPeerChatListIndex(peerId: peerId) != nil
|
||||
case let .single(peerId):
|
||||
mainPeerId = peerId
|
||||
self.isAddedToChatList = postbox.chatListTable.getPeerChatListIndex(peerId: peerId) != nil
|
||||
case let .external(input):
|
||||
self.isAddedToChatList = postbox.chatListTable.getPeerChatListIndex(peerId: input.peerId) != nil
|
||||
}
|
||||
self.isAddedToChatList = postbox.chatListTable.getPeerChatListIndex(peerId: mainPeerId) != nil
|
||||
|
||||
self.state = HistoryViewState(postbox: postbox, inputAnchor: inputAnchor, tag: tag, namespaces: namespaces, statistics: self.orderStatistics, halfLimit: count + 1, locations: peerIds)
|
||||
if case let .loading(loadingState) = self.state {
|
||||
@@ -361,12 +395,14 @@ final class MutableMessageHistoryView {
|
||||
self.peerIds = .associated(peerId, updatedData.associatedHistoryMessageId)
|
||||
}
|
||||
}
|
||||
case .external:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func replay(postbox: Postbox, transaction: PostboxTransaction) -> Bool {
|
||||
var operations: [[MessageHistoryOperation]] = []
|
||||
var peerIdsSet = Set<PeerId>()
|
||||
var holePeerIdsSet = Set<PeerId>()
|
||||
|
||||
if !transaction.chatListOperations.isEmpty {
|
||||
let mainPeerId: PeerId
|
||||
@@ -375,52 +411,67 @@ final class MutableMessageHistoryView {
|
||||
mainPeerId = peerId
|
||||
case let .single(peerId):
|
||||
mainPeerId = peerId
|
||||
case let .external(input):
|
||||
mainPeerId = input.peerId
|
||||
}
|
||||
self.isAddedToChatList = postbox.chatListTable.getPeerChatListIndex(peerId: mainPeerId) != nil
|
||||
}
|
||||
|
||||
switch self.peerIds {
|
||||
case let .single(peerId):
|
||||
peerIdsSet.insert(peerId)
|
||||
holePeerIdsSet.insert(peerId)
|
||||
if let value = transaction.currentOperationsByPeerId[peerId] {
|
||||
operations.append(value)
|
||||
}
|
||||
case .associated:
|
||||
switch self.peerIds {
|
||||
case .single:
|
||||
case .single, .external:
|
||||
assertionFailure()
|
||||
case let .associated(mainPeerId, associatedPeerId):
|
||||
peerIdsSet.insert(mainPeerId)
|
||||
holePeerIdsSet.insert(mainPeerId)
|
||||
if let associatedPeerId = associatedPeerId {
|
||||
peerIdsSet.insert(associatedPeerId.peerId)
|
||||
holePeerIdsSet.insert(associatedPeerId.peerId)
|
||||
}
|
||||
}
|
||||
|
||||
for (peerId, value) in transaction.currentOperationsByPeerId {
|
||||
if peerIdsSet.contains(peerId) {
|
||||
if holePeerIdsSet.contains(peerId) {
|
||||
operations.append(value)
|
||||
}
|
||||
}
|
||||
case let .external(input):
|
||||
if let value = transaction.currentOperationsByPeerId[input.peerId] {
|
||||
operations.append(value)
|
||||
}
|
||||
}
|
||||
|
||||
var hasChanges = false
|
||||
|
||||
let unwrappedTag: MessageTags = self.tag ?? []
|
||||
let threadId: Int64?
|
||||
switch self.peerIds {
|
||||
case .single, .associated:
|
||||
threadId = nil
|
||||
case let .external(input):
|
||||
threadId = input.threadId
|
||||
}
|
||||
|
||||
switch self.state {
|
||||
case let .loading(loadingState):
|
||||
for (key, holeOperations) in transaction.currentPeerHoleOperations {
|
||||
var matchesSpace = false
|
||||
switch key.space {
|
||||
case .everywhere:
|
||||
matchesSpace = unwrappedTag.isEmpty
|
||||
case let .tag(tag):
|
||||
if let currentTag = self.tag, currentTag == tag {
|
||||
matchesSpace = true
|
||||
if threadId == nil {
|
||||
switch key.space {
|
||||
case .everywhere:
|
||||
matchesSpace = unwrappedTag.isEmpty
|
||||
case let .tag(tag):
|
||||
if let currentTag = self.tag, currentTag == tag {
|
||||
matchesSpace = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if matchesSpace {
|
||||
if peerIdsSet.contains(key.peerId) {
|
||||
if holePeerIdsSet.contains(key.peerId) {
|
||||
for operation in holeOperations {
|
||||
switch operation {
|
||||
case let .insert(range):
|
||||
@@ -453,13 +504,22 @@ final class MutableMessageHistoryView {
|
||||
for operation in operationSet {
|
||||
switch operation {
|
||||
case let .InsertMessage(message):
|
||||
var matches = false
|
||||
if unwrappedTag.isEmpty || message.tags.contains(unwrappedTag) {
|
||||
if self.namespaces.contains(message.id.namespace) {
|
||||
if loadedState.add(entry: .IntermediateMessageEntry(message, nil, nil)) {
|
||||
hasChanges = true
|
||||
if threadId == nil || message.threadId == threadId {
|
||||
if self.namespaces.contains(message.id.namespace) {
|
||||
matches = true
|
||||
if loadedState.add(entry: .IntermediateMessageEntry(message, nil, nil)) {
|
||||
hasChanges = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if !matches {
|
||||
if loadedState.addAssociated(entry: .IntermediateMessageEntry(message, nil, nil)) {
|
||||
hasChanges = true
|
||||
}
|
||||
}
|
||||
case let .Remove(indicesAndTags):
|
||||
for (index, _) in indicesAndTags {
|
||||
if self.namespaces.contains(index.id.namespace) {
|
||||
@@ -497,16 +557,18 @@ final class MutableMessageHistoryView {
|
||||
}
|
||||
for (key, holeOperations) in transaction.currentPeerHoleOperations {
|
||||
var matchesSpace = false
|
||||
switch key.space {
|
||||
case .everywhere:
|
||||
matchesSpace = unwrappedTag.isEmpty
|
||||
case let .tag(tag):
|
||||
if let currentTag = self.tag, currentTag == tag {
|
||||
matchesSpace = true
|
||||
if threadId == nil {
|
||||
switch key.space {
|
||||
case .everywhere:
|
||||
matchesSpace = unwrappedTag.isEmpty
|
||||
case let .tag(tag):
|
||||
if let currentTag = self.tag, currentTag == tag {
|
||||
matchesSpace = true
|
||||
}
|
||||
}
|
||||
}
|
||||
if matchesSpace {
|
||||
if peerIdsSet.contains(key.peerId) {
|
||||
if holePeerIdsSet.contains(key.peerId) {
|
||||
for operation in holeOperations {
|
||||
switch operation {
|
||||
case let .insert(range):
|
||||
@@ -585,6 +647,50 @@ final class MutableMessageHistoryView {
|
||||
}
|
||||
case .cachedPeerDataMessages:
|
||||
break
|
||||
case let .message(id, _):
|
||||
if let operations = transaction.currentOperationsByPeerId[id.peerId] {
|
||||
var updateMessage = false
|
||||
findOperation: for operation in operations {
|
||||
switch operation {
|
||||
case let .InsertMessage(message):
|
||||
if message.id == id {
|
||||
updateMessage = true
|
||||
break findOperation
|
||||
}
|
||||
case let .Remove(indices):
|
||||
for (index, _) in indices {
|
||||
if index.id == id {
|
||||
updateMessage = true
|
||||
break findOperation
|
||||
}
|
||||
}
|
||||
case let .UpdateEmbeddedMedia(index, _):
|
||||
if index.id == id {
|
||||
updateMessage = true
|
||||
break findOperation
|
||||
}
|
||||
case let .UpdateGroupInfos(dict):
|
||||
if dict[id] != nil {
|
||||
updateMessage = true
|
||||
break findOperation
|
||||
}
|
||||
case let .UpdateTimestamp(index, _):
|
||||
if index.id == id {
|
||||
updateMessage = true
|
||||
break findOperation
|
||||
}
|
||||
case .UpdateReadState:
|
||||
break
|
||||
}
|
||||
}
|
||||
if updateMessage {
|
||||
let message = postbox.messageHistoryIndexTable.getIndex(id).flatMap(postbox.messageHistoryTable.getMessage).flatMap { message in
|
||||
postbox.messageHistoryTable.renderMessage(message, peerTable: postbox.peerTable)
|
||||
}
|
||||
self.additionalDatas[i] = .message(id, message)
|
||||
hasChanges = true
|
||||
}
|
||||
}
|
||||
case let .peerChatState(peerId, _):
|
||||
if transaction.currentUpdatedPeerChatStates.contains(peerId) {
|
||||
self.additionalDatas[i] = .peerChatState(peerId, postbox.peerChatStateTable.get(peerId) as? PeerChatState)
|
||||
@@ -673,19 +779,21 @@ final class MutableMessageHistoryView {
|
||||
}
|
||||
|
||||
if !transaction.currentPeerHoleOperations.isEmpty {
|
||||
var peerIdsSet: [PeerId] = []
|
||||
switch peerIds {
|
||||
var holePeerIdsSet: [PeerId] = []
|
||||
switch self.peerIds {
|
||||
case let .single(peerId):
|
||||
peerIdsSet.append(peerId)
|
||||
holePeerIdsSet.append(peerId)
|
||||
case let .associated(peerId, associatedId):
|
||||
peerIdsSet.append(peerId)
|
||||
holePeerIdsSet.append(peerId)
|
||||
if let associatedId = associatedId {
|
||||
peerIdsSet.append(associatedId.peerId)
|
||||
holePeerIdsSet.append(associatedId.peerId)
|
||||
}
|
||||
case .external:
|
||||
break
|
||||
}
|
||||
let space: MessageHistoryHoleSpace = self.tag.flatMap(MessageHistoryHoleSpace.tag) ?? .everywhere
|
||||
for key in transaction.currentPeerHoleOperations.keys {
|
||||
if peerIdsSet.contains(key.peerId) && key.space == space {
|
||||
if holePeerIdsSet.contains(key.peerId) && key.space == space {
|
||||
hasChanges = true
|
||||
}
|
||||
}
|
||||
@@ -713,8 +821,8 @@ final class MutableMessageHistoryView {
|
||||
switch loadingSample {
|
||||
case .ready:
|
||||
return nil
|
||||
case let .loadHole(peerId, namespace, _, id):
|
||||
return (.peer(MessageHistoryViewPeerHole(peerId: peerId, namespace: namespace)), .aroundId(MessageId(peerId: peerId, namespace: namespace, id: id)), self.fillCount * 2)
|
||||
case let .loadHole(peerId, namespace, _, threadId, id):
|
||||
return (.peer(MessageHistoryViewPeerHole(peerId: peerId, namespace: namespace, threadId: threadId)), .aroundId(MessageId(peerId: peerId, namespace: namespace, id: id)), self.fillCount * 2)
|
||||
}
|
||||
case let .loaded(loadedSample):
|
||||
if let hole = loadedSample.hole {
|
||||
@@ -724,7 +832,7 @@ final class MutableMessageHistoryView {
|
||||
} else {
|
||||
direction = .aroundId(MessageId(peerId: hole.peerId, namespace: hole.namespace, id: hole.startId))
|
||||
}
|
||||
return (.peer(MessageHistoryViewPeerHole(peerId: hole.peerId, namespace: hole.namespace)), direction, self.fillCount * 2)
|
||||
return (.peer(MessageHistoryViewPeerHole(peerId: hole.peerId, namespace: hole.namespace, threadId: hole.threadId)), direction, self.fillCount * 2)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user