From 63c36a394ead093072be41e50beff42d840dcf69 Mon Sep 17 00:00:00 2001 From: Mikhail Filimonov Date: Fri, 17 May 2024 09:04:51 +0400 Subject: [PATCH] InvertMediaAttribute --- .../Sources/Account/AccountManager.swift | 1 + .../ApiUtils/StoreMessage_Telegram.swift | 6 +++++ .../TelegramInvertMediaMessageAttribute.swift | 23 +++++++++++++++++++ .../PendingMessages/EnqueueMessage.swift | 2 ++ .../Sources/State/PendingMessageManager.swift | 6 +++++ .../Sources/Utils/MessageUtils.swift | 8 +++++++ 6 files changed, 46 insertions(+) create mode 100644 submodules/TelegramCore/Sources/ApiUtils/TelegramInvertMediaMessageAttribute.swift diff --git a/submodules/TelegramCore/Sources/Account/AccountManager.swift b/submodules/TelegramCore/Sources/Account/AccountManager.swift index 15abf9236d..2d7b1e5fdd 100644 --- a/submodules/TelegramCore/Sources/Account/AccountManager.swift +++ b/submodules/TelegramCore/Sources/Account/AccountManager.swift @@ -219,6 +219,7 @@ private var declaredEncodables: Void = { declareEncodable(TelegramMediaGiveaway.self, f: { TelegramMediaGiveaway(decoder: $0) }) declareEncodable(TelegramMediaGiveawayResults.self, f: { TelegramMediaGiveawayResults(decoder: $0) }) declareEncodable(WebpagePreviewMessageAttribute.self, f: { WebpagePreviewMessageAttribute(decoder: $0) }) + declareEncodable(InvertMediaMessageAttribute.self, f: { InvertMediaMessageAttribute(decoder: $0) }) declareEncodable(DerivedDataMessageAttribute.self, f: { DerivedDataMessageAttribute(decoder: $0) }) declareEncodable(TelegramApplicationIcons.self, f: { TelegramApplicationIcons(decoder: $0) }) declareEncodable(OutgoingQuickReplyMessageAttribute.self, f: { OutgoingQuickReplyMessageAttribute(decoder: $0) }) diff --git a/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift b/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift index 37817e5f03..1a8628c783 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/StoreMessage_Telegram.swift @@ -781,6 +781,12 @@ extension StoreMessage { attributes.append(WebpagePreviewMessageAttribute(leadingPreview: leadingPreview, forceLargeMedia: webpageAttributes.forceLargeMedia, isManuallyAdded: webpageAttributes.isManuallyAdded, isSafe: webpageAttributes.isSafe)) } } + + let leadingPreview = (flags & (1 << 27)) != 0 + if leadingPreview { + attributes.append(InvertMediaMessageAttribute()) + } + } } diff --git a/submodules/TelegramCore/Sources/ApiUtils/TelegramInvertMediaMessageAttribute.swift b/submodules/TelegramCore/Sources/ApiUtils/TelegramInvertMediaMessageAttribute.swift new file mode 100644 index 0000000000..d0b0617272 --- /dev/null +++ b/submodules/TelegramCore/Sources/ApiUtils/TelegramInvertMediaMessageAttribute.swift @@ -0,0 +1,23 @@ + +import Foundation +import Postbox +import TelegramApi + +public class InvertMediaMessageAttribute: MessageAttribute, Equatable { + public let associatedPeerIds: [PeerId] = [] + public let associatedMediaIds: [MediaId] = [] + + + public init() { + } + + required public init(decoder: PostboxDecoder) { + } + + public func encode(_ encoder: PostboxEncoder) { + } + + public static func ==(lhs: InvertMediaMessageAttribute, rhs: InvertMediaMessageAttribute) -> Bool { + return true + } +} diff --git a/submodules/TelegramCore/Sources/PendingMessages/EnqueueMessage.swift b/submodules/TelegramCore/Sources/PendingMessages/EnqueueMessage.swift index 26de3f9e10..3c178747f7 100644 --- a/submodules/TelegramCore/Sources/PendingMessages/EnqueueMessage.swift +++ b/submodules/TelegramCore/Sources/PendingMessages/EnqueueMessage.swift @@ -248,6 +248,8 @@ private func filterMessageAttributesForOutgoingMessage(_ attributes: [MessageAtt return true case _ as WebpagePreviewMessageAttribute: return true + case _ as InvertMediaMessageAttribute: + return true case _ as EffectMessageAttribute: return true default: diff --git a/submodules/TelegramCore/Sources/State/PendingMessageManager.swift b/submodules/TelegramCore/Sources/State/PendingMessageManager.swift index f67e5f9529..b5a9b693a3 100644 --- a/submodules/TelegramCore/Sources/State/PendingMessageManager.swift +++ b/submodules/TelegramCore/Sources/State/PendingMessageManager.swift @@ -1328,6 +1328,9 @@ public final class PendingMessageManager { flags |= 1 << 16 } } + if message.invertMedia { + flags |= 1 << 16 + } var quickReplyShortcut: Api.InputQuickReplyShortcut? if let quickReply { @@ -1409,6 +1412,9 @@ public final class PendingMessageManager { flags |= 1 << 16 } } + if message.invertMedia { + flags |= 1 << 16 + } var quickReplyShortcut: Api.InputQuickReplyShortcut? if let quickReply { diff --git a/submodules/TelegramCore/Sources/Utils/MessageUtils.swift b/submodules/TelegramCore/Sources/Utils/MessageUtils.swift index e234e47eff..a5ecf0ff4e 100644 --- a/submodules/TelegramCore/Sources/Utils/MessageUtils.swift +++ b/submodules/TelegramCore/Sources/Utils/MessageUtils.swift @@ -523,6 +523,14 @@ public extension Message { } return nil } + var invertMedia: Bool { + for attribute in self.attributes { + if let _ = attribute as? InvertMediaMessageAttribute { + return true + } + } + return false + } } public extension Message {