mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Syntax highlight
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
|
||||
public class DerivedDataMessageAttribute: MessageAttribute {
|
||||
private struct EntryData: PostboxCoding {
|
||||
var data: CodableEntry
|
||||
|
||||
init(data: CodableEntry) {
|
||||
self.data = data
|
||||
}
|
||||
|
||||
init(decoder: PostboxDecoder) {
|
||||
self.data = CodableEntry(data: decoder.decodeDataForKey("d") ?? Data())
|
||||
}
|
||||
|
||||
func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeData(self.data.data, forKey: "d")
|
||||
}
|
||||
}
|
||||
|
||||
public let data: [String: CodableEntry]
|
||||
|
||||
public init(data: [String: CodableEntry]) {
|
||||
self.data = data
|
||||
}
|
||||
|
||||
required public init(decoder: PostboxDecoder) {
|
||||
let data = decoder.decodeObjectDictionaryForKey("d", keyDecoder: { key in
|
||||
return key.decodeStringForKey("k", orElse: "")
|
||||
}, valueDecoder: { value in
|
||||
return EntryData(data: CodableEntry(data: value.decodeDataForKey("d") ?? Data()))
|
||||
})
|
||||
self.data = data.mapValues(\.data)
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObjectDictionary(self.data.mapValues(EntryData.init(data:)), forKey: "d", keyEncoder: { k, e in
|
||||
e.encodeString(k, forKey: "k")
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,13 @@ public let telegramPostboxSeedConfiguration: SeedConfiguration = {
|
||||
break
|
||||
}
|
||||
}
|
||||
var derivedData: DerivedDataMessageAttribute?
|
||||
for attribute in previous {
|
||||
if let attribute = attribute as? DerivedDataMessageAttribute {
|
||||
derivedData = attribute
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if let audioTranscription = audioTranscription {
|
||||
var found = false
|
||||
@@ -127,6 +134,19 @@ public let telegramPostboxSeedConfiguration: SeedConfiguration = {
|
||||
updated.append(audioTranscription)
|
||||
}
|
||||
}
|
||||
if let derivedData = derivedData {
|
||||
var found = false
|
||||
for i in 0 ..< updated.count {
|
||||
if let attribute = updated[i] as? DerivedDataMessageAttribute {
|
||||
updated[i] = derivedData
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
updated.append(derivedData)
|
||||
}
|
||||
}
|
||||
},
|
||||
decodeMessageThreadInfo: { entry in
|
||||
guard let data = entry.get(MessageHistoryThreadData.self) else {
|
||||
|
||||
Reference in New Issue
Block a user