mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
Refactor SyncCore
This commit is contained in:
45
submodules/SyncCore/Sources/AccountBackupDataAttribute.swift
Normal file
45
submodules/SyncCore/Sources/AccountBackupDataAttribute.swift
Normal file
@@ -0,0 +1,45 @@
|
||||
import Postbox
|
||||
|
||||
public struct AccountBackupData: Codable, Equatable {
|
||||
public var masterDatacenterId: Int32
|
||||
public var peerId: Int64
|
||||
public var masterDatacenterKey: Data
|
||||
public var masterDatacenterKeyId: Int64
|
||||
|
||||
public init(masterDatacenterId: Int32, peerId: Int64, masterDatacenterKey: Data, masterDatacenterKeyId: Int64) {
|
||||
self.masterDatacenterId = masterDatacenterId
|
||||
self.peerId = peerId
|
||||
self.masterDatacenterKey = masterDatacenterKey
|
||||
self.masterDatacenterKeyId = masterDatacenterKeyId
|
||||
}
|
||||
}
|
||||
|
||||
public final class AccountBackupDataAttribute: AccountRecordAttribute, Equatable {
|
||||
public let data: AccountBackupData?
|
||||
|
||||
public init(data: AccountBackupData?) {
|
||||
self.data = data
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.data = try? JSONDecoder().decode(AccountBackupData.self, from: decoder.decodeDataForKey("data") ?? Data())
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
if let data = self.data, let serializedData = try? JSONEncoder().encode(data) {
|
||||
encoder.encodeData(serializedData, forKey: "data")
|
||||
}
|
||||
}
|
||||
|
||||
public static func ==(lhs: AccountBackupDataAttribute, rhs: AccountBackupDataAttribute) -> Bool {
|
||||
return lhs.data == rhs.data
|
||||
}
|
||||
|
||||
public func isEqual(to: AccountRecordAttribute) -> Bool {
|
||||
if let to = to as? AccountBackupDataAttribute {
|
||||
return self == to
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user