mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-29 03:21:29 +00:00
AccountBackupDataAttribute: handle nil
This commit is contained in:
parent
e62a476550
commit
a55a097d54
@ -930,18 +930,20 @@ public struct AccountBackupData: Codable, Equatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class AccountBackupDataAttribute: AccountRecordAttribute, Equatable {
|
public final class AccountBackupDataAttribute: AccountRecordAttribute, Equatable {
|
||||||
public let data: AccountBackupData
|
public let data: AccountBackupData?
|
||||||
|
|
||||||
public init(data: AccountBackupData) {
|
public init(data: AccountBackupData?) {
|
||||||
self.data = data
|
self.data = data
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(decoder: PostboxDecoder) {
|
public init(decoder: PostboxDecoder) {
|
||||||
self.data = try! JSONDecoder().decode(AccountBackupData.self, from: decoder.decodeDataForKey("data")!)
|
self.data = try? JSONDecoder().decode(AccountBackupData.self, from: decoder.decodeDataForKey("data") ?? Data())
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(_ encoder: PostboxEncoder) {
|
public func encode(_ encoder: PostboxEncoder) {
|
||||||
encoder.encodeData(try! JSONEncoder().encode(self.data), forKey: "data")
|
if let data = self.data, let serializedData = try? JSONEncoder().encode(data) {
|
||||||
|
encoder.encodeData(serializedData, forKey: "data")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func ==(lhs: AccountBackupDataAttribute, rhs: AccountBackupDataAttribute) -> Bool {
|
public static func ==(lhs: AccountBackupDataAttribute, rhs: AccountBackupDataAttribute) -> Bool {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user