diff --git a/TelegramCore.xcodeproj/project.pbxproj b/TelegramCore.xcodeproj/project.pbxproj index 4f3ce10231..90f856b1db 100644 --- a/TelegramCore.xcodeproj/project.pbxproj +++ b/TelegramCore.xcodeproj/project.pbxproj @@ -648,6 +648,8 @@ D0E8B8B32044706300605593 /* ForwardGame.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0E8B8B22044706300605593 /* ForwardGame.swift */; }; D0E8B8B42044706300605593 /* ForwardGame.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0E8B8B22044706300605593 /* ForwardGame.swift */; }; D0EA188220D3D2B1001AEE19 /* RemoteStorageConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EA188120D3D2B1001AEE19 /* RemoteStorageConfiguration.swift */; }; + D0EC559A2101ED0800D1992C /* DeleteMessages.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC55992101ED0800D1992C /* DeleteMessages.swift */; }; + D0EC559B2101ED0800D1992C /* DeleteMessages.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EC55992101ED0800D1992C /* DeleteMessages.swift */; }; D0EE7FC120986BF400981319 /* SecureIdInternalPassportValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EE7FC020986BF400981319 /* SecureIdInternalPassportValue.swift */; }; D0EE7FC220986BF400981319 /* SecureIdInternalPassportValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EE7FC020986BF400981319 /* SecureIdInternalPassportValue.swift */; }; D0EE7FC420986C5300981319 /* SecureIdPassportRegistrationValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0EE7FC320986C5300981319 /* SecureIdPassportRegistrationValue.swift */; }; @@ -1087,6 +1089,7 @@ D0E817482010E7E300B82BBB /* ChannelAdminEventLogContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelAdminEventLogContext.swift; sourceTree = ""; }; D0E8B8B22044706300605593 /* ForwardGame.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForwardGame.swift; sourceTree = ""; }; D0EA188120D3D2B1001AEE19 /* RemoteStorageConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteStorageConfiguration.swift; sourceTree = ""; }; + D0EC55992101ED0800D1992C /* DeleteMessages.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteMessages.swift; sourceTree = ""; }; D0EE7FC020986BF400981319 /* SecureIdInternalPassportValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureIdInternalPassportValue.swift; sourceTree = ""; }; D0EE7FC320986C5300981319 /* SecureIdPassportRegistrationValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureIdPassportRegistrationValue.swift; sourceTree = ""; }; D0EE7FC62098853100981319 /* SecureIdTemporaryRegistrationValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureIdTemporaryRegistrationValue.swift; sourceTree = ""; }; @@ -1521,6 +1524,7 @@ isa = PBXGroup; children = ( D03B0D711D631ABA00955575 /* SearchMessages.swift */, + D0EC55992101ED0800D1992C /* DeleteMessages.swift */, D01AC91C1DD5DA5E00E8160F /* RequestMessageActionCallback.swift */, D01AC9201DD5E7E500E8160F /* RequestEditMessage.swift */, D0DC354D1DE368F7000195EB /* RequestChatContextResults.swift */, @@ -2205,6 +2209,7 @@ D0F8C3A02017AF2700236FC5 /* GlobalTelegramCoreConfiguration.swift in Sources */, D01C06B71FBBA269001561AB /* CanSendMessagesToPeer.swift in Sources */, D0B843B51DA7FF30005F29E1 /* NBMetadataCore.m in Sources */, + D0EC559A2101ED0800D1992C /* DeleteMessages.swift in Sources */, D0C26D691FE02402004ABF18 /* ManagedSynchronizeGroupedPeersOperations.swift in Sources */, D03B0CD61D62245300955575 /* TelegramUser.swift in Sources */, D02395D61F8D09A50070F5C2 /* ChannelHistoryAvailabilitySettings.swift in Sources */, @@ -2651,6 +2656,7 @@ D0B418941D7E0580004562A4 /* TelegramMediaAction.swift in Sources */, D0B8442C1DAB91E0005F29E1 /* NBMetadataCoreMapper.m in Sources */, D0FA8BB71E223C16001E855B /* SecretApiLayer8.swift in Sources */, + D0EC559B2101ED0800D1992C /* DeleteMessages.swift in Sources */, D073CE6A1DCBCF17007511FD /* ViewCountMessageAttribute.swift in Sources */, C27982511E72C97800262BFD /* MacosLegacy.swift in Sources */, D0B418AB1D7E0597004562A4 /* MultipartFetch.swift in Sources */, diff --git a/TelegramCore/AccountStateManagementUtils.swift b/TelegramCore/AccountStateManagementUtils.swift index 180cad57fc..ad05a9a699 100644 --- a/TelegramCore/AccountStateManagementUtils.swift +++ b/TelegramCore/AccountStateManagementUtils.swift @@ -1895,7 +1895,7 @@ func replayFinalState(accountPeerId: PeerId, mediaBox: MediaBox, transaction: Tr case let .DeleteMessagesWithGlobalIds(ids): transaction.deleteMessagesWithGlobalIds(ids) case let .DeleteMessages(ids): - transaction.deleteMessages(ids) + deleteMessages(transaction: transaction, mediaBox: mediaBox, ids: ids) case let .UpdateMinAvailableMessage(id): transaction.deleteMessagesInRange(peerId: id.peerId, namespace: id.namespace, minId: 1, maxId: id.id) case let .EditMessage(id, message): diff --git a/TelegramCore/DeleteMessages.swift b/TelegramCore/DeleteMessages.swift new file mode 100644 index 0000000000..2d857d0dda --- /dev/null +++ b/TelegramCore/DeleteMessages.swift @@ -0,0 +1,26 @@ +import Foundation +#if os(macOS) +import PostboxMac +import SwiftSignalKitMac +#else +import Postbox +import SwiftSignalKit +#endif + +public func deleteMessages(transaction: Transaction, mediaBox: MediaBox, ids: [MessageId]) { + for id in ids { + if id.peerId.namespace == Namespaces.Peer.SecretChat { + if let message = transaction.getMessage(id) { + for media in message.media { + if let image = media as? TelegramMediaImage { + let _ = mediaBox.removeCachedResources(Set(image.representations.map({ WrappedMediaResourceId($0.resource.id) }))) + } else if let file = media as? TelegramMediaFile { + let _ = mediaBox.removeCachedResources(Set(file.previewRepresentations.map({ WrappedMediaResourceId($0.resource.id) }))) + let _ = mediaBox.removeCachedResources(Set([WrappedMediaResourceId(file.resource.id)])) + } + } + } + } + } + transaction.deleteMessages(ids) +} diff --git a/TelegramCore/DeleteMessagesInteractively.swift b/TelegramCore/DeleteMessagesInteractively.swift index c6f13b0a8d..560b2ed8f7 100644 --- a/TelegramCore/DeleteMessagesInteractively.swift +++ b/TelegramCore/DeleteMessagesInteractively.swift @@ -53,7 +53,7 @@ public func deleteMessagesInteractively(postbox: Postbox, messageIds: [MessageId } } } - transaction.deleteMessages(messageIds) + deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: messageIds) } } diff --git a/TelegramCore/EnqueueMessage.swift b/TelegramCore/EnqueueMessage.swift index c11c7773aa..e85f973db5 100644 --- a/TelegramCore/EnqueueMessage.swift +++ b/TelegramCore/EnqueueMessage.swift @@ -177,7 +177,7 @@ public func resendMessages(account: Account, messageIds: [MessageId]) -> Signal< } let _ = enqueueMessages(transaction: transaction, account: account, peerId: peerId, messages: messages.map { (false, $0) }) } - transaction.deleteMessages(removeMessageIds) + deleteMessages(transaction: transaction, mediaBox: account.postbox.mediaBox, ids: removeMessageIds) } } diff --git a/TelegramCore/HistoryViewChannelStateValidation.swift b/TelegramCore/HistoryViewChannelStateValidation.swift index 4ad627ea38..b89c7accbd 100644 --- a/TelegramCore/HistoryViewChannelStateValidation.swift +++ b/TelegramCore/HistoryViewChannelStateValidation.swift @@ -507,7 +507,7 @@ private func validateBatch(postbox: Postbox, network: Network, accountPeerId: Pe if !validMessageIds.contains(id) { switch historyState { case .channel: - transaction.deleteMessages([id]) + deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [id]) case let .group(groupId, _): transaction.removeMessagesFromGroupFeedIndex(groupId: groupId, ids: [id]) } diff --git a/TelegramCore/ManagedAutoremoveMessageOperations.swift b/TelegramCore/ManagedAutoremoveMessageOperations.swift index cd1cc7d011..8a8e6438a5 100644 --- a/TelegramCore/ManagedAutoremoveMessageOperations.swift +++ b/TelegramCore/ManagedAutoremoveMessageOperations.swift @@ -66,7 +66,7 @@ func managedAutoremoveMessageOperations(postbox: Postbox) -> Signal then(postbox.transaction { transaction -> Void in if let message = transaction.getMessage(entry.messageId) { if message.id.peerId.namespace == Namespaces.Peer.SecretChat { - transaction.deleteMessages([entry.messageId]) + deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [entry.messageId]) } else { transaction.updateMessage(message.id, update: { currentMessage in var storeForwardInfo: StoreMessageForwardInfo? diff --git a/TelegramCore/ManagedSecretChatOutgoingOperations.swift b/TelegramCore/ManagedSecretChatOutgoingOperations.swift index 63ddfdf033..21dc2235b3 100644 --- a/TelegramCore/ManagedSecretChatOutgoingOperations.swift +++ b/TelegramCore/ManagedSecretChatOutgoingOperations.swift @@ -1090,7 +1090,7 @@ private func sendMessage(postbox: Postbox, network: Network, messageId: MessageI } } else { replaceOutgoingOperationWithEmptyMessage(transaction: transaction, peerId: messageId.peerId, tagLocalIndex: tagLocalIndex, globallyUniqueId: arc4random64()) - transaction.deleteMessages([messageId]) + deleteMessages(transaction: transaction, mediaBox: postbox.mediaBox, ids: [messageId]) //assertionFailure() return .complete() } diff --git a/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift b/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift index 3f8a506271..5bada86560 100644 --- a/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift +++ b/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift @@ -243,7 +243,7 @@ func processSecretChatIncomingDecryptedOperations(mediaBox: MediaBox, transactio } } if !messageIds.isEmpty { - transaction.deleteMessages(messageIds) + deleteMessages(transaction: transaction, mediaBox: mediaBox, ids: messageIds) } case .clearHistory: transaction.clearHistory(peerId)