mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-10-09 11:23:48 +00:00
- poll result translate
This commit is contained in:
parent
410f970d99
commit
f9185cc401
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user