mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Make PresentationThemeSettings codable
This commit is contained in:
parent
40e56e0bb1
commit
ba09489d74
@ -94,7 +94,7 @@ public struct PresentationLocalTheme: PostboxCoding, Equatable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct PresentationCloudTheme: PostboxCoding, Equatable {
|
public struct PresentationCloudTheme: Codable, Equatable {
|
||||||
public let theme: TelegramTheme
|
public let theme: TelegramTheme
|
||||||
public let resolvedWallpaper: TelegramWallpaper?
|
public let resolvedWallpaper: TelegramWallpaper?
|
||||||
public let creatorAccountId: AccountRecordId?
|
public let creatorAccountId: AccountRecordId?
|
||||||
@ -104,25 +104,21 @@ public struct PresentationCloudTheme: PostboxCoding, Equatable {
|
|||||||
self.resolvedWallpaper = resolvedWallpaper
|
self.resolvedWallpaper = resolvedWallpaper
|
||||||
self.creatorAccountId = creatorAccountId
|
self.creatorAccountId = creatorAccountId
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(decoder: PostboxDecoder) {
|
public init(from decoder: Decoder) throws {
|
||||||
self.theme = decoder.decode(TelegramThemeNativeCodable.self, forKey: "theme")!.value
|
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||||
self.resolvedWallpaper = decoder.decode(TelegramWallpaperNativeCodable.self, forKey: "wallpaper")?.value
|
|
||||||
self.creatorAccountId = decoder.decodeOptionalInt64ForKey("account").flatMap { AccountRecordId(rawValue: $0) }
|
self.theme = (try container.decode(TelegramThemeNativeCodable.self, forKey: "theme")).value
|
||||||
|
self.resolvedWallpaper = (try container.decodeIfPresent(TelegramWallpaperNativeCodable.self, forKey: "wallpaper"))?.value
|
||||||
|
self.creatorAccountId = (try container.decodeIfPresent(Int64.self, forKey: "account")).flatMap(AccountRecordId.init(rawValue:))
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(_ encoder: PostboxEncoder) {
|
public func encode(to encoder: Encoder) throws {
|
||||||
encoder.encode(TelegramThemeNativeCodable(self.theme), forKey: "theme")
|
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||||
if let resolvedWallpaper = self.resolvedWallpaper {
|
|
||||||
encoder.encode(TelegramWallpaperNativeCodable(resolvedWallpaper), forKey: "wallpaper")
|
try container.encode(TelegramThemeNativeCodable(self.theme), forKey: "theme")
|
||||||
} else {
|
try container.encodeIfPresent(self.resolvedWallpaper.flatMap(TelegramWallpaperNativeCodable.init), forKey: "wallpaper")
|
||||||
encoder.encodeNil(forKey: "wallpaper")
|
try container.encodeIfPresent(self.creatorAccountId?.int64, forKey: "account")
|
||||||
}
|
|
||||||
if let accountId = self.creatorAccountId {
|
|
||||||
encoder.encodeInt64(accountId.int64, forKey: "account")
|
|
||||||
} else {
|
|
||||||
encoder.encodeNil(forKey: "account")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func ==(lhs: PresentationCloudTheme, rhs: PresentationCloudTheme) -> Bool {
|
public static func ==(lhs: PresentationCloudTheme, rhs: PresentationCloudTheme) -> Bool {
|
||||||
@ -152,7 +148,7 @@ public enum PresentationThemeReference: PostboxCoding, Equatable {
|
|||||||
self = .builtin(.dayClassic)
|
self = .builtin(.dayClassic)
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
if let cloudTheme = decoder.decodeObjectForKey("cloudTheme", decoder: { PresentationCloudTheme(decoder: $0) }) as? PresentationCloudTheme {
|
if let cloudTheme = decoder.decode(PresentationCloudTheme.self, forKey: "cloudTheme") {
|
||||||
self = .cloud(cloudTheme)
|
self = .cloud(cloudTheme)
|
||||||
} else {
|
} else {
|
||||||
self = .builtin(.dayClassic)
|
self = .builtin(.dayClassic)
|
||||||
@ -173,7 +169,7 @@ public enum PresentationThemeReference: PostboxCoding, Equatable {
|
|||||||
encoder.encodeObject(theme, forKey: "localTheme")
|
encoder.encodeObject(theme, forKey: "localTheme")
|
||||||
case let .cloud(theme):
|
case let .cloud(theme):
|
||||||
encoder.encodeInt32(2, forKey: "v")
|
encoder.encodeInt32(2, forKey: "v")
|
||||||
encoder.encodeObject(theme, forKey: "cloudTheme")
|
encoder.encode(theme, forKey: "cloudTheme")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user