mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 03:20:48 +00:00
Bot updates
This commit is contained in:
parent
4c42c4d5a4
commit
92156ffec0
@ -20,7 +20,7 @@ final class MutableCachedPeerDataView: MutablePostboxView {
|
||||
}
|
||||
|
||||
func replay(postbox: PostboxImpl, transaction: PostboxTransaction) -> Bool {
|
||||
if let cachedPeerData = transaction.currentUpdatedCachedPeerData[self.peerId] {
|
||||
if let cachedPeerData = transaction.currentUpdatedCachedPeerData[self.peerId]?.updated {
|
||||
self.cachedPeerData = cachedPeerData
|
||||
if self.trackAssociatedMessages {
|
||||
self.associatedMessages.removeAll()
|
||||
|
@ -373,7 +373,7 @@ final class ChatListTable: Table {
|
||||
return result
|
||||
}
|
||||
|
||||
func replay(postbox: PostboxImpl, historyOperationsByPeerId: [PeerId: [MessageHistoryOperation]], updatedPeerChatListEmbeddedStates: Set<PeerId>, updatedPeers: [PeerId: Peer], updatedChatListInclusions: [PeerId: PeerChatListInclusion], messageHistoryTable: MessageHistoryTable, peerChatInterfaceStateTable: PeerChatInterfaceStateTable, operations: inout [PeerGroupId: [ChatListOperation]]) {
|
||||
func replay(postbox: PostboxImpl, historyOperationsByPeerId: [PeerId: [MessageHistoryOperation]], updatedPeerChatListEmbeddedStates: Set<PeerId>, updatedPeerCachedData: [PeerId: (previous: CachedPeerData?, updated: CachedPeerData)], updatedChatListInclusions: [PeerId: PeerChatListInclusion], messageHistoryTable: MessageHistoryTable, peerChatInterfaceStateTable: PeerChatInterfaceStateTable, operations: inout [PeerGroupId: [ChatListOperation]]) {
|
||||
var changedPeerIds = Set<PeerId>()
|
||||
for peerId in historyOperationsByPeerId.keys {
|
||||
changedPeerIds.insert(peerId)
|
||||
@ -384,12 +384,23 @@ final class ChatListTable: Table {
|
||||
for peerId in updatedChatListInclusions.keys {
|
||||
changedPeerIds.insert(peerId)
|
||||
}
|
||||
/*for peerId in updatedPeers.keys {
|
||||
changedPeerIds.insert(peerId)
|
||||
if let peer = postbox.peerTable.get(peerId), let targetPeerId = self.seedConfiguration.chatListPeerMergeIntoTargetId(peer) {
|
||||
changedPeerIds.insert(targetPeerId)
|
||||
for (peerId, update) in updatedPeerCachedData {
|
||||
if let previous = update.previous {
|
||||
if self.seedConfiguration.decodeAssociatedChatListPeerId(previous) != self.seedConfiguration.decodeAssociatedChatListPeerId(update.updated) {
|
||||
changedPeerIds.insert(peerId)
|
||||
}
|
||||
} else {
|
||||
changedPeerIds.insert(peerId)
|
||||
}
|
||||
}*/
|
||||
}
|
||||
var additionalChangedPeerIds = Set<PeerId>()
|
||||
for peerId in changedPeerIds {
|
||||
//TODO:release move this to seed configuration
|
||||
if let peer = postbox.peerTable.get(peerId), peer.id.namespace._internalGetInt32Value() == 2, let associatedPeerId = peer.associatedPeerId, associatedPeerId.namespace._internalGetInt32Value() == 0 {
|
||||
additionalChangedPeerIds.insert(associatedPeerId)
|
||||
}
|
||||
}
|
||||
changedPeerIds.formUnion(additionalChangedPeerIds)
|
||||
|
||||
self.ensureInitialized(groupId: .root)
|
||||
|
||||
@ -419,21 +430,17 @@ final class ChatListTable: Table {
|
||||
rawTopMessageIndex = nil
|
||||
}
|
||||
|
||||
/*for associatedId in postbox.reverseAssociatedPeerTable.get(peerId: peerId) {
|
||||
if let peer = postbox.peerTable.get(associatedId), let targetPeerId = self.seedConfiguration.chatListPeerMergeIntoTargetId(peer), targetPeerId == peerId {
|
||||
if let associatedTopMessage = messageHistoryTable.topIndex(peerId: associatedId) {
|
||||
if let currentTopMessageIndex = topMessage {
|
||||
if associatedTopMessage > currentTopMessageIndex {
|
||||
topMessageIndex = associatedTopMessage
|
||||
rawTopMessageIndex = associatedTopMessage
|
||||
}
|
||||
} else {
|
||||
topMessageIndex = associatedTopMessage
|
||||
rawTopMessageIndex = associatedTopMessage
|
||||
if let cachedData = postbox.cachedPeerDataTable.get(peerId), let associatedChatListPeerId = self.seedConfiguration.decodeAssociatedChatListPeerId(cachedData) {
|
||||
if let associatedTopMessage = messageHistoryTable.topIndex(peerId: associatedChatListPeerId) {
|
||||
if let currentTopMessageIndex = topMessageIndex {
|
||||
if currentTopMessageIndex.timestamp < associatedTopMessage.timestamp {
|
||||
topMessageIndex = MessageIndex(id: currentTopMessageIndex.id, timestamp: associatedTopMessage.timestamp)
|
||||
}
|
||||
} else {
|
||||
topMessageIndex = MessageIndex(id: MessageId(peerId: peerId, namespace: 0, id: 1), timestamp: associatedTopMessage.timestamp)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
var updatedIndex = self.indexTable.setTopMessageIndex(peerId: peerId, index: topMessageIndex)
|
||||
if let updatedInclusion = updatedChatListInclusions[peerId] {
|
||||
|
@ -1043,15 +1043,17 @@ public final class ChatListView {
|
||||
|
||||
//TODO:release
|
||||
var linkedEntries: [PeerId: [MutableChatListEntry.MessageEntryData]] = [:]
|
||||
for entry in mutableView.sampledState.entries {
|
||||
guard case let .MessageEntry(entryData) = entry else {
|
||||
continue
|
||||
}
|
||||
if let peer = entryData.renderedPeer.peer, peer.id.namespace._internalGetInt32Value() == 2, let associatedPeerId = peer.associatedPeerId, associatedPeerId.namespace._internalGetInt32Value() == 0 {
|
||||
if linkedEntries[associatedPeerId] == nil {
|
||||
linkedEntries[associatedPeerId] = []
|
||||
if "".isEmpty {
|
||||
for entry in mutableView.sampledState.entries {
|
||||
guard case let .MessageEntry(entryData) = entry else {
|
||||
continue
|
||||
}
|
||||
if let peer = entryData.renderedPeer.peer, peer.id.namespace._internalGetInt32Value() == 2, let associatedPeerId = peer.associatedPeerId, associatedPeerId.namespace._internalGetInt32Value() == 0 {
|
||||
if linkedEntries[associatedPeerId] == nil {
|
||||
linkedEntries[associatedPeerId] = []
|
||||
}
|
||||
linkedEntries[associatedPeerId]?.append(entryData)
|
||||
}
|
||||
linkedEntries[associatedPeerId]?.append(entryData)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1069,7 +1071,7 @@ public final class ChatListView {
|
||||
var forumTopicData = entryData.displayAsRegularChat ? nil : entryData.forumTopicData
|
||||
if let linkedEntries = linkedEntries[entryData.index.messageIndex.id.peerId] {
|
||||
for entry in linkedEntries {
|
||||
if entry.index > index {
|
||||
if entry.index.messageIndex.timestamp >= index.messageIndex.timestamp {
|
||||
index = ChatListIndex(pinningIndex: index.pinningIndex, messageIndex: MessageIndex(id: index.messageIndex.id, timestamp: entry.index.messageIndex.timestamp))
|
||||
messages = entry.messages
|
||||
forumTopicData = entry.forumTopicData
|
||||
|
@ -452,14 +452,14 @@ final class MutableMessageHistoryView: MutablePostboxView {
|
||||
switch self.peerIds {
|
||||
case let .single(peerId, threadId):
|
||||
if threadId == nil {
|
||||
if let updatedData = transaction.currentUpdatedCachedPeerData[peerId] {
|
||||
if let updatedData = transaction.currentUpdatedCachedPeerData[peerId]?.updated {
|
||||
if updatedData.associatedHistoryMessageId != nil {
|
||||
self.peerIds = .associated(peerId, updatedData.associatedHistoryMessageId)
|
||||
}
|
||||
}
|
||||
}
|
||||
case let .associated(peerId, associatedId):
|
||||
if let updatedData = transaction.currentUpdatedCachedPeerData[peerId] {
|
||||
if let updatedData = transaction.currentUpdatedCachedPeerData[peerId]?.updated {
|
||||
if updatedData.associatedHistoryMessageId != associatedId {
|
||||
self.peerIds = .associated(peerId, updatedData.associatedHistoryMessageId)
|
||||
}
|
||||
@ -844,7 +844,7 @@ final class MutableMessageHistoryView: MutablePostboxView {
|
||||
switch additionalDatas[i] {
|
||||
case let .cachedPeerData(peerId, currentData):
|
||||
currentCachedPeerData = currentData
|
||||
if let updatedData = transaction.currentUpdatedCachedPeerData[peerId] {
|
||||
if let updatedData = transaction.currentUpdatedCachedPeerData[peerId]?.updated {
|
||||
if currentData?.messageIds != updatedData.messageIds {
|
||||
updatedCachedPeerDataMessages = true
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ final class MutablePeerView: MutablePostboxView {
|
||||
var peersUpdated = false
|
||||
var updateMessages = false
|
||||
|
||||
if let cachedData = updatedCachedPeerData[self.contactPeerId], self.cachedData == nil || !self.cachedData!.isEqual(to: cachedData) {
|
||||
if let cachedData = updatedCachedPeerData[self.contactPeerId]?.updated, self.cachedData == nil || !self.cachedData!.isEqual(to: cachedData) {
|
||||
if self.cachedData?.messageIds != cachedData.messageIds {
|
||||
updateMessages = true
|
||||
}
|
||||
@ -286,7 +286,7 @@ final class MutablePeerView: MutablePostboxView {
|
||||
}
|
||||
|
||||
if let associatedPeerId = peer.associatedPeerId {
|
||||
if let value = updatedCachedPeerData[associatedPeerId] {
|
||||
if let value = updatedCachedPeerData[associatedPeerId]?.updated {
|
||||
if let current = self.associatedCachedData[associatedPeerId] {
|
||||
if !current.isEqual(to: value) {
|
||||
self.associatedCachedData[associatedPeerId] = value
|
||||
|
@ -1615,7 +1615,7 @@ final class PostboxImpl {
|
||||
private var currentUpdatedPeers: [PeerId: Peer] = [:]
|
||||
private var currentUpdatedPeerNotificationSettings: [PeerId: (PeerNotificationSettings?, PeerNotificationSettings)] = [:]
|
||||
private var currentUpdatedPeerNotificationBehaviorTimestamps: [PeerId: PeerNotificationSettingsBehaviorTimestamp] = [:]
|
||||
private var currentUpdatedCachedPeerData: [PeerId: CachedPeerData] = [:]
|
||||
private var currentUpdatedCachedPeerData: [PeerId: (previous: CachedPeerData?, updated: CachedPeerData)] = [:]
|
||||
private var currentUpdatedPeerPresences: [PeerId: PeerPresence] = [:]
|
||||
private var currentUpdatedPeerChatListEmbeddedStates = Set<PeerId>()
|
||||
private var currentUpdatedTotalUnreadStates: [PeerGroupId: ChatListTotalUnreadState] = [:]
|
||||
@ -2597,7 +2597,7 @@ final class PostboxImpl {
|
||||
}
|
||||
|
||||
private func beforeCommit(currentTransaction: Transaction) -> (updatedTransactionStateVersion: Int64?, updatedMasterClientId: Int64?) {
|
||||
self.chatListTable.replay(postbox: self, historyOperationsByPeerId: self.currentOperationsByPeerId, updatedPeerChatListEmbeddedStates: self.currentUpdatedPeerChatListEmbeddedStates, updatedPeers: self.currentUpdatedPeers, updatedChatListInclusions: self.currentUpdatedChatListInclusions, messageHistoryTable: self.messageHistoryTable, peerChatInterfaceStateTable: self.peerChatInterfaceStateTable, operations: &self.currentChatListOperations)
|
||||
self.chatListTable.replay(postbox: self, historyOperationsByPeerId: self.currentOperationsByPeerId, updatedPeerChatListEmbeddedStates: self.currentUpdatedPeerChatListEmbeddedStates, updatedPeerCachedData: self.currentUpdatedCachedPeerData, updatedChatListInclusions: self.currentUpdatedChatListInclusions, messageHistoryTable: self.messageHistoryTable, peerChatInterfaceStateTable: self.peerChatInterfaceStateTable, operations: &self.currentChatListOperations)
|
||||
|
||||
self.peerChatTopTaggedMessageIdsTable.replay(historyOperationsByPeerId: self.currentOperationsByPeerId)
|
||||
|
||||
@ -2936,7 +2936,7 @@ final class PostboxImpl {
|
||||
let currentData = self.cachedPeerDataTable.get(peerId)
|
||||
if let updatedData = update(peerId, currentData) {
|
||||
self.cachedPeerDataTable.set(id: peerId, data: updatedData)
|
||||
self.currentUpdatedCachedPeerData[peerId] = updatedData
|
||||
self.currentUpdatedCachedPeerData[peerId] = (currentData, updatedData)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ final class PostboxTransaction {
|
||||
let currentUpdatedPeers: [PeerId: Peer]
|
||||
let currentUpdatedPeerNotificationSettings: [PeerId: (PeerNotificationSettings?, PeerNotificationSettings)]
|
||||
let currentUpdatedPeerNotificationBehaviorTimestamps: [PeerId: PeerNotificationSettingsBehaviorTimestamp]
|
||||
let currentUpdatedCachedPeerData: [PeerId: CachedPeerData]
|
||||
let currentUpdatedCachedPeerData: [PeerId: (previous: CachedPeerData?, updated: CachedPeerData)]
|
||||
let currentUpdatedPeerPresences: [PeerId: PeerPresence]
|
||||
let currentUpdatedPeerChatListEmbeddedStates: Set<PeerId>
|
||||
let currentUpdatedTotalUnreadStates: [PeerGroupId: ChatListTotalUnreadState]
|
||||
@ -240,7 +240,7 @@ final class PostboxTransaction {
|
||||
currentUpdatedPeerNotificationSettings: [PeerId: (PeerNotificationSettings?,
|
||||
PeerNotificationSettings)],
|
||||
currentUpdatedPeerNotificationBehaviorTimestamps: [PeerId: PeerNotificationSettingsBehaviorTimestamp],
|
||||
currentUpdatedCachedPeerData: [PeerId: CachedPeerData],
|
||||
currentUpdatedCachedPeerData: [PeerId: (previous: CachedPeerData?, updated: CachedPeerData)],
|
||||
currentUpdatedPeerPresences: [PeerId: PeerPresence],
|
||||
currentUpdatedPeerChatListEmbeddedStates: Set<PeerId>,
|
||||
currentUpdatedTotalUnreadStates: [PeerGroupId: ChatListTotalUnreadState],
|
||||
|
@ -77,11 +77,11 @@ public final class SeedConfiguration {
|
||||
public let decodeMessageThreadInfo: (CodableEntry) -> Message.AssociatedThreadInfo?
|
||||
public let decodeAutoremoveTimeout: (CachedPeerData) -> Int32?
|
||||
public let decodeDisplayPeerAsRegularChat: (CachedPeerData) -> Bool
|
||||
public let decodeAssociatedChatListPeerId: (CachedPeerData) -> PeerId?
|
||||
public let isPeerUpgradeMessage: (Message) -> Bool
|
||||
public let automaticThreadIndexInfo: (PeerId, Int64) -> StoredMessageHistoryThreadInfo?
|
||||
public let customTagsFromAttributes: ([MessageAttribute]) -> [MemoryBuffer]
|
||||
public let displaySavedMessagesAsTopicListPreferencesKey: ValueBoxKey
|
||||
public let chatListPeerMergeIntoTargetId: (Peer) -> PeerId?
|
||||
|
||||
public init(
|
||||
globalMessageIdsPeerIdNamespaces: Set<GlobalMessageIdsNamespace>,
|
||||
@ -109,11 +109,11 @@ public final class SeedConfiguration {
|
||||
decodeMessageThreadInfo: @escaping (CodableEntry) -> Message.AssociatedThreadInfo?,
|
||||
decodeAutoremoveTimeout: @escaping (CachedPeerData) -> Int32?,
|
||||
decodeDisplayPeerAsRegularChat: @escaping (CachedPeerData) -> Bool,
|
||||
decodeAssociatedChatListPeerId: @escaping (CachedPeerData) -> PeerId?,
|
||||
isPeerUpgradeMessage: @escaping (Message) -> Bool,
|
||||
automaticThreadIndexInfo: @escaping (PeerId, Int64) -> StoredMessageHistoryThreadInfo?,
|
||||
customTagsFromAttributes: @escaping ([MessageAttribute]) -> [MemoryBuffer],
|
||||
displaySavedMessagesAsTopicListPreferencesKey: ValueBoxKey,
|
||||
chatListPeerMergeIntoTargetId: @escaping (Peer) -> PeerId?
|
||||
displaySavedMessagesAsTopicListPreferencesKey: ValueBoxKey
|
||||
) {
|
||||
self.globalMessageIdsPeerIdNamespaces = globalMessageIdsPeerIdNamespaces
|
||||
self.initializeChatListWithHole = initializeChatListWithHole
|
||||
@ -136,10 +136,10 @@ public final class SeedConfiguration {
|
||||
self.decodeMessageThreadInfo = decodeMessageThreadInfo
|
||||
self.decodeAutoremoveTimeout = decodeAutoremoveTimeout
|
||||
self.decodeDisplayPeerAsRegularChat = decodeDisplayPeerAsRegularChat
|
||||
self.decodeAssociatedChatListPeerId = decodeAssociatedChatListPeerId
|
||||
self.isPeerUpgradeMessage = isPeerUpgradeMessage
|
||||
self.automaticThreadIndexInfo = automaticThreadIndexInfo
|
||||
self.customTagsFromAttributes = customTagsFromAttributes
|
||||
self.displaySavedMessagesAsTopicListPreferencesKey = displaySavedMessagesAsTopicListPreferencesKey
|
||||
self.chatListPeerMergeIntoTargetId = chatListPeerMergeIntoTargetId
|
||||
}
|
||||
}
|
||||
|
@ -187,6 +187,14 @@ public let telegramPostboxSeedConfiguration: SeedConfiguration = {
|
||||
}
|
||||
return false
|
||||
},
|
||||
decodeAssociatedChatListPeerId: { cachedData in
|
||||
if let cachedData = cachedData as? CachedUserData {
|
||||
if case let .known(value) = cachedData.linkedBotChannelId {
|
||||
return value
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
isPeerUpgradeMessage: { message in
|
||||
for media in message.media {
|
||||
if let action = media as? TelegramMediaAction {
|
||||
@ -245,13 +253,7 @@ public let telegramPostboxSeedConfiguration: SeedConfiguration = {
|
||||
|
||||
return result
|
||||
},
|
||||
displaySavedMessagesAsTopicListPreferencesKey: PreferencesKeys.displaySavedChatsAsTopics(),
|
||||
chatListPeerMergeIntoTargetId: { peer in
|
||||
if let peer = peer as? TelegramChannel, let linkedBotId = peer.linkedBotId {
|
||||
return linkedBotId
|
||||
}
|
||||
return nil
|
||||
}
|
||||
displaySavedMessagesAsTopicListPreferencesKey: PreferencesKeys.displaySavedChatsAsTopics()
|
||||
)
|
||||
}()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user