Syntax highlight

This commit is contained in:
Ali
2023-10-31 16:47:10 +04:00
parent 6bc7b4f663
commit eb15434a8e
138 changed files with 49922 additions and 218 deletions

View File

@@ -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")
})
}
}

View File

@@ -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 {