From f9185cc40171567ad2247b09137500008be5c88b Mon Sep 17 00:00:00 2001 From: Mikhail Filimonov Date: Fri, 3 May 2024 19:05:37 +0400 Subject: [PATCH] - poll result translate --- .../SyncCore_TranslationMessageAttribute.swift | 13 +++++++++++++ .../Sources/TelegramEngine/Messages/Translate.swift | 13 ++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TranslationMessageAttribute.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TranslationMessageAttribute.swift index 4b64fd60ad..50b4191e9b 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TranslationMessageAttribute.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TranslationMessageAttribute.swift @@ -29,6 +29,7 @@ public class TranslationMessageAttribute: MessageAttribute, Equatable { public let toLang: String public let additional:[Additional] + public let pollSolution: Additional? public var associatedPeerIds: [PeerId] { return [] @@ -38,12 +39,14 @@ public class TranslationMessageAttribute: MessageAttribute, Equatable { text: String, entities: [MessageTextEntity], additional:[Additional] = [], + pollSolution: Additional? = nil, toLang: String ) { self.text = text self.entities = entities self.toLang = toLang self.additional = additional + self.pollSolution = pollSolution } required public init(decoder: PostboxDecoder) { @@ -51,6 +54,7 @@ public class TranslationMessageAttribute: MessageAttribute, Equatable { self.entities = decoder.decodeObjectArrayWithDecoderForKey("entities") self.additional = decoder.decodeObjectArrayWithDecoderForKey("additional") self.toLang = decoder.decodeStringForKey("toLang", orElse: "") + self.pollSolution = decoder.decodeObjectForKey("pollSolution") as? Additional } public func encode(_ encoder: PostboxEncoder) { @@ -58,6 +62,12 @@ public class TranslationMessageAttribute: MessageAttribute, Equatable { encoder.encodeObjectArray(self.entities, forKey: "entities") encoder.encodeString(self.toLang, forKey: "toLang") encoder.encodeObjectArray(self.additional, forKey: "additional") + + if let pollSolution { + encoder.encodeObject(pollSolution, forKey: "pollSolution") + } else { + encoder.encodeNil(forKey: "pollSolution") + } } public static func ==(lhs: TranslationMessageAttribute, rhs: TranslationMessageAttribute) -> Bool { @@ -73,6 +83,9 @@ public class TranslationMessageAttribute: MessageAttribute, Equatable { if lhs.additional != rhs.additional { return false } + if lhs.pollSolution != rhs.pollSolution { + return false + } return true } } diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Messages/Translate.swift b/submodules/TelegramCore/Sources/TelegramEngine/Messages/Translate.swift index 304d8963fd..928d1bc36e 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Messages/Translate.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Messages/Translate.swift @@ -111,6 +111,9 @@ func _internal_translateMessages(account: Account, messageIds: [EngineMessage.Id for option in poll.options { texts.append((option.text, option.entities)) } + if let solution = poll.results.solution { + texts.append((solution.text, solution.entities)) + } return _internal_translate_texts(network: account.network, texts: texts, toLang: toLang) } @@ -175,7 +178,15 @@ func _internal_translateMessages(account: Account, messageIds: [EngineMessage.Id let translated = result[i + 1] attrOptions.append(.init(text: translated.0, entities: translated.1)) } - let updatedAttribute: TranslationMessageAttribute = TranslationMessageAttribute(text: result[0].0, entities: result[0].1, additional: attrOptions, toLang: toLang) + + let solution: TranslationMessageAttribute.Additional? + if result.count > 1 + poll.0.options.count { + solution = .init(text: result[result.count - 1].0, entities: result[result.count - 1].1) + } else { + solution = nil + } + + let updatedAttribute: TranslationMessageAttribute = TranslationMessageAttribute(text: result[0].0, entities: result[0].1, additional: attrOptions, pollSolution: solution, toLang: toLang) attributes.append(updatedAttribute) return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, threadId: currentMessage.threadId, timestamp: currentMessage.timestamp, flags: StoreMessageFlags(currentMessage.flags), tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: attributes, media: currentMessage.media))