From f8ee1688fcc40ef760b9721d3aa9385efed48c2e Mon Sep 17 00:00:00 2001 From: Peter <> Date: Fri, 26 Apr 2019 22:28:27 +0400 Subject: [PATCH] Fix message group updates --- TelegramCore/ApplyUpdateMessage.swift | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/TelegramCore/ApplyUpdateMessage.swift b/TelegramCore/ApplyUpdateMessage.swift index 34c25c2952..f4a00de1b0 100644 --- a/TelegramCore/ApplyUpdateMessage.swift +++ b/TelegramCore/ApplyUpdateMessage.swift @@ -205,11 +205,21 @@ func applyUpdateGroupMessages(postbox: Postbox, stateManager: AccountStateManage var sentGifs: [TelegramMediaFile] = [] var updatedGroupingKey: Int64? + for (_, _, updatedMessage) in mapping { + if let updatedGroupingKey = updatedGroupingKey { + assert(updatedGroupingKey == updatedMessage.groupingKey) + } + updatedGroupingKey = updatedMessage.groupingKey + } if let latestPreviousId = latestPreviousId, let latestIndex = mapping.last?.1 { transaction.offsetPendingMessagesTimestamps(lowerBound: latestPreviousId, excludeIds: Set(mapping.map { $0.0.id }), timestamp: latestIndex.timestamp) } + if let updatedGroupingKey = updatedGroupingKey { + transaction.updateMessageGroupingKeysAtomically(mapping.map { $0.0.id }, groupingKey: updatedGroupingKey) + } + for (message, _, updatedMessage) in mapping { transaction.updateMessage(message.id, update: { currentMessage in let updatedId: MessageId @@ -258,19 +268,10 @@ func applyUpdateGroupMessages(postbox: Postbox, stateManager: AccountStateManage let (tags, globalTags) = tagsForStoreMessage(incoming: currentMessage.flags.contains(.Incoming), attributes: attributes, media: media, textEntities: entitiesAttribute?.entities) - if let updatedGroupingKey = updatedGroupingKey { - assert(updatedGroupingKey == updatedMessage.groupingKey) - } - updatedGroupingKey = updatedMessage.groupingKey - return .update(StoreMessage(id: updatedId, globallyUniqueId: nil, groupingKey: currentMessage.groupingKey, timestamp: updatedMessage.timestamp, flags: [], tags: tags, globalTags: globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: text, attributes: attributes, media: media)) }) } - if let updatedGroupingKey = updatedGroupingKey { - transaction.updateMessageGroupingKeysAtomically(mapping.map { $0.1.id }, groupingKey: updatedGroupingKey) - } - for file in sentStickers { transaction.addOrMoveToFirstPositionOrderedItemListItem(collectionId: Namespaces.OrderedItemList.CloudRecentStickers, item: OrderedItemListEntry(id: RecentMediaItemId(file.fileId).rawValue, contents: RecentMediaItem(file)), removeTailIfCountExceeds: 20) }