mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Merge branch 'master' into postbox-refactoring-1
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
|
||||
public struct AppConfiguration: Codable {
|
||||
public struct AppConfiguration: Codable, Equatable {
|
||||
public var data: JSON?
|
||||
|
||||
public static var defaultValue: AppConfiguration {
|
||||
|
||||
@@ -2,10 +2,10 @@ import Postbox
|
||||
|
||||
public final class CachedStickerQueryResult: PostboxCoding {
|
||||
public let items: [TelegramMediaFile]
|
||||
public let hash: Int32
|
||||
public let hash: Int64
|
||||
public let timestamp: Int32
|
||||
|
||||
public init(items: [TelegramMediaFile], hash: Int32, timestamp: Int32) {
|
||||
public init(items: [TelegramMediaFile], hash: Int64, timestamp: Int32) {
|
||||
self.items = items
|
||||
self.hash = hash
|
||||
self.timestamp = timestamp
|
||||
@@ -13,13 +13,13 @@ public final class CachedStickerQueryResult: PostboxCoding {
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.items = decoder.decodeObjectArrayForKey("it").map { $0 as! TelegramMediaFile }
|
||||
self.hash = decoder.decodeInt32ForKey("h", orElse: 0)
|
||||
self.hash = decoder.decodeInt64ForKey("h6", orElse: 0)
|
||||
self.timestamp = decoder.decodeInt32ForKey("t", orElse: 0)
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObjectArray(self.items, forKey: "it")
|
||||
encoder.encodeInt32(self.hash, forKey: "h")
|
||||
encoder.encodeInt64(self.hash, forKey: "h6")
|
||||
encoder.encodeInt32(self.timestamp, forKey: "t")
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import Postbox
|
||||
|
||||
public final class CachedThemesConfiguration: PostboxCoding {
|
||||
public let hash: Int32
|
||||
public let hash: Int64
|
||||
|
||||
public init(hash: Int32) {
|
||||
public init(hash: Int64) {
|
||||
self.hash = hash
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.hash = decoder.decodeInt32ForKey("hash", orElse: 0)
|
||||
self.hash = decoder.decodeInt64ForKey("hash6", orElse: 0)
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.hash, forKey: "hash")
|
||||
encoder.encodeInt64(self.hash, forKey: "hash6")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import Postbox
|
||||
|
||||
public final class CachedWallpapersConfiguration: PostboxCoding {
|
||||
public let hash: Int32
|
||||
public let hash: Int64
|
||||
|
||||
public init(hash: Int32) {
|
||||
public init(hash: Int64) {
|
||||
self.hash = hash
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.hash = decoder.decodeInt32ForKey("hash", orElse: 0)
|
||||
self.hash = decoder.decodeInt64ForKey("hash6", orElse: 0)
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.hash, forKey: "hash")
|
||||
encoder.encodeInt64(self.hash, forKey: "hash6")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,15 @@ public struct MessageNotificationSettings: Codable {
|
||||
self.sound = PeerMessageSound.decodeInline(container)
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
|
||||
encoder.encodeInt32(self.enabled ? 1 : 0, forKey: "e")
|
||||
encoder.encodeInt32(self.displayPreviews ? 1 : 0, forKey: "p")
|
||||
self.sound.encodeInline(encoder)
|
||||
}
|
||||
}
|
||||
|
||||
public struct GlobalNotificationSettingsSet: Codable {
|
||||
public struct GlobalNotificationSettingsSet: Codable, Equatable {
|
||||
public var privateChats: MessageNotificationSettings
|
||||
public var groupChats: MessageNotificationSettings
|
||||
public var channels: MessageNotificationSettings
|
||||
@@ -57,7 +58,8 @@ public struct GlobalNotificationSettingsSet: Codable {
|
||||
self.contactsJoined = decoder.decodeInt32ForKey("contactsJoined", orElse: 1) != 0
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
|
||||
encoder.encodeObject(self.privateChats, forKey: "p")
|
||||
encoder.encodeObject(self.groupChats, forKey: "g")
|
||||
encoder.encodeObject(self.channels, forKey: "c")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Postbox
|
||||
|
||||
public struct LimitsConfiguration: Equatable, PreferencesEntry {
|
||||
public struct LimitsConfiguration: Codable, Equatable {
|
||||
public static let timeIntervalForever: Int32 = 0x7fffffff
|
||||
|
||||
public var maxPinnedChatCount: Int32
|
||||
@@ -35,40 +35,37 @@ public struct LimitsConfiguration: Equatable, PreferencesEntry {
|
||||
self.maxMessageRevokeIntervalInPrivateChats = maxMessageRevokeIntervalInPrivateChats
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.maxPinnedChatCount = decoder.decodeInt32ForKey("maxPinnedChatCount", orElse: 5)
|
||||
self.maxArchivedPinnedChatCount = decoder.decodeInt32ForKey("maxArchivedPinnedChatCount", orElse: 20)
|
||||
self.maxGroupMemberCount = decoder.decodeInt32ForKey("maxGroupMemberCount", orElse: 200)
|
||||
self.maxSupergroupMemberCount = decoder.decodeInt32ForKey("maxSupergroupMemberCount", orElse: 5000)
|
||||
self.maxMessageForwardBatchSize = decoder.decodeInt32ForKey("maxMessageForwardBatchSize", orElse: 50)
|
||||
self.maxSavedGifCount = decoder.decodeInt32ForKey("maxSavedGifCount", orElse: 200)
|
||||
self.maxRecentStickerCount = decoder.decodeInt32ForKey("maxRecentStickerCount", orElse: 20)
|
||||
self.maxMessageEditingInterval = decoder.decodeInt32ForKey("maxMessageEditingInterval", orElse: 2 * 24 * 60 * 60)
|
||||
self.maxMediaCaptionLength = decoder.decodeInt32ForKey("maxMediaCaptionLength", orElse: 1000)
|
||||
self.canRemoveIncomingMessagesInPrivateChats = decoder.decodeInt32ForKey("canRemoveIncomingMessagesInPrivateChats", orElse: 0) != 0
|
||||
self.maxMessageRevokeInterval = decoder.decodeInt32ForKey("maxMessageRevokeInterval", orElse: 2 * 24 * 60 * 60)
|
||||
self.maxMessageRevokeIntervalInPrivateChats = decoder.decodeInt32ForKey("maxMessageRevokeIntervalInPrivateChats", orElse: 2 * 24 * 60 * 60)
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.maxPinnedChatCount = (try? container.decodeIfPresent(Int32.self, forKey: "maxPinnedChatCount")) ?? 5
|
||||
self.maxArchivedPinnedChatCount = (try? container.decodeIfPresent(Int32.self, forKey: "maxArchivedPinnedChatCount")) ?? 20
|
||||
self.maxGroupMemberCount = (try? container.decodeIfPresent(Int32.self, forKey: "maxGroupMemberCount")) ?? 200
|
||||
self.maxSupergroupMemberCount = (try? container.decodeIfPresent(Int32.self, forKey: "maxSupergroupMemberCount")) ?? 5000
|
||||
self.maxMessageForwardBatchSize = (try? container.decodeIfPresent(Int32.self, forKey: "maxMessageForwardBatchSize")) ?? 50
|
||||
self.maxSavedGifCount = (try? container.decodeIfPresent(Int32.self, forKey: "maxSavedGifCount")) ?? 200
|
||||
self.maxRecentStickerCount = (try? container.decodeIfPresent(Int32.self, forKey: "maxRecentStickerCount")) ?? 20
|
||||
self.maxMessageEditingInterval = (try? container.decodeIfPresent(Int32.self, forKey: "maxMessageEditingInterval")) ?? (2 * 24 * 60 * 60)
|
||||
self.maxMediaCaptionLength = (try? container.decodeIfPresent(Int32.self, forKey: "maxMediaCaptionLength")) ?? 1000
|
||||
self.canRemoveIncomingMessagesInPrivateChats = (try? container.decodeIfPresent(Int32.self, forKey: "canRemoveIncomingMessagesInPrivateChats") ?? 0) != 0
|
||||
self.maxMessageRevokeInterval = (try? container.decodeIfPresent(Int32.self, forKey: "maxMessageRevokeInterval")) ?? (2 * 24 * 60 * 60)
|
||||
self.maxMessageRevokeIntervalInPrivateChats = (try? container.decodeIfPresent(Int32.self, forKey: "maxMessageRevokeIntervalInPrivateChats")) ?? (2 * 24 * 60 * 60)
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.maxPinnedChatCount, forKey: "maxPinnedChatCount")
|
||||
encoder.encodeInt32(self.maxArchivedPinnedChatCount, forKey: "maxArchivedPinnedChatCount")
|
||||
encoder.encodeInt32(self.maxGroupMemberCount, forKey: "maxGroupMemberCount")
|
||||
encoder.encodeInt32(self.maxSupergroupMemberCount, forKey: "maxSupergroupMemberCount")
|
||||
encoder.encodeInt32(self.maxMessageForwardBatchSize, forKey: "maxMessageForwardBatchSize")
|
||||
encoder.encodeInt32(self.maxSavedGifCount, forKey: "maxSavedGifCount")
|
||||
encoder.encodeInt32(self.maxRecentStickerCount, forKey: "maxRecentStickerCount")
|
||||
encoder.encodeInt32(self.maxMessageEditingInterval, forKey: "maxMessageEditingInterval")
|
||||
encoder.encodeInt32(self.maxMediaCaptionLength, forKey: "maxMediaCaptionLength")
|
||||
encoder.encodeInt32(self.canRemoveIncomingMessagesInPrivateChats ? 1 : 0, forKey: "canRemoveIncomingMessagesInPrivateChats")
|
||||
encoder.encodeInt32(self.maxMessageRevokeInterval, forKey: "maxMessageRevokeInterval")
|
||||
encoder.encodeInt32(self.maxMessageRevokeIntervalInPrivateChats, forKey: "maxMessageRevokeIntervalInPrivateChats")
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
guard let to = to as? LimitsConfiguration else {
|
||||
return false
|
||||
}
|
||||
return self == to
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.maxPinnedChatCount, forKey: "maxPinnedChatCount")
|
||||
try container.encode(self.maxArchivedPinnedChatCount, forKey: "maxArchivedPinnedChatCount")
|
||||
try container.encode(self.maxGroupMemberCount, forKey: "maxGroupMemberCount")
|
||||
try container.encode(self.maxSupergroupMemberCount, forKey: "maxSupergroupMemberCount")
|
||||
try container.encode(self.maxMessageForwardBatchSize, forKey: "maxMessageForwardBatchSize")
|
||||
try container.encode(self.maxSavedGifCount, forKey: "maxSavedGifCount")
|
||||
try container.encode(self.maxRecentStickerCount, forKey: "maxRecentStickerCount")
|
||||
try container.encode(self.maxMessageEditingInterval, forKey: "maxMessageEditingInterval")
|
||||
try container.encode(self.maxMediaCaptionLength, forKey: "maxMediaCaptionLength")
|
||||
try container.encode(self.canRemoveIncomingMessagesInPrivateChats ? 1 : 0, forKey: "canRemoveIncomingMessagesInPrivateChats")
|
||||
try container.encode(self.maxMessageRevokeInterval, forKey: "maxMessageRevokeInterval")
|
||||
try container.encode(self.maxMessageRevokeIntervalInPrivateChats, forKey: "maxMessageRevokeIntervalInPrivateChats")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ private func writeString(_ buffer: WriteBuffer, _ string: String) {
|
||||
}
|
||||
}
|
||||
|
||||
public final class Localization: PostboxCoding, Equatable {
|
||||
public final class Localization: Codable, Equatable {
|
||||
public let version: Int32
|
||||
public let entries: [LocalizationEntry]
|
||||
|
||||
@@ -54,11 +54,16 @@ public final class Localization: PostboxCoding, Equatable {
|
||||
self.entries = entries
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.version = decoder.decodeInt32ForKey("v", orElse: 0)
|
||||
let count = decoder.decodeInt32ForKey("c", orElse: 0)
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.version = (try? container.decode(Int32.self, forKey: "v")) ?? 0
|
||||
|
||||
let count = (try? container.decode(Int32.self, forKey: "c")) ?? 0
|
||||
var entries: [LocalizationEntry] = []
|
||||
if let data = decoder.decodeBytesForKey("d") {
|
||||
if let rawData = try? container.decodeIfPresent(Data.self, forKey: "d") {
|
||||
let data = ReadBuffer(data: rawData)
|
||||
|
||||
for _ in 0 ..< count {
|
||||
var flagsValue: Int8 = 0
|
||||
data.read(&flagsValue, offset: 0, length: 1)
|
||||
@@ -150,9 +155,11 @@ public final class Localization: PostboxCoding, Equatable {
|
||||
self.entries = entries
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.version, forKey: "v")
|
||||
encoder.encodeInt32(Int32(self.entries.count), forKey: "c")
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.version, forKey: "v")
|
||||
try container.encode(Int32(self.entries.count), forKey: "c")
|
||||
|
||||
let buffer = WriteBuffer()
|
||||
for entry in self.entries {
|
||||
@@ -205,7 +212,7 @@ public final class Localization: PostboxCoding, Equatable {
|
||||
writeString(buffer, other)
|
||||
}
|
||||
}
|
||||
encoder.encodeBytes(buffer, forKey: "d")
|
||||
try container.encode(buffer.makeData(), forKey: "d")
|
||||
}
|
||||
|
||||
public static func ==(lhs: Localization, rhs: Localization) -> Bool {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Postbox
|
||||
|
||||
public struct LocalizationInfo: PostboxCoding, Equatable {
|
||||
public struct LocalizationInfo: PostboxCoding, Codable, Equatable {
|
||||
public let languageCode: String
|
||||
public let baseLanguageCode: String?
|
||||
public let customPluralizationCode: String?
|
||||
@@ -34,6 +34,20 @@ public struct LocalizationInfo: PostboxCoding, Equatable {
|
||||
self.translatedStringCount = decoder.decodeInt32ForKey("lsc", orElse: 0)
|
||||
self.platformUrl = decoder.decodeStringForKey("platformUrl", orElse: "")
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.languageCode = (try? container.decode(String.self, forKey: "lc")) ?? ""
|
||||
self.baseLanguageCode = try? container.decodeIfPresent(String.self, forKey: "nlc")
|
||||
self.customPluralizationCode = try? container.decodeIfPresent(String.self, forKey: "cpc")
|
||||
self.title = (try? container.decode(String.self, forKey: "t")) ?? ""
|
||||
self.localizedTitle = (try? container.decode(String.self, forKey: "lt")) ?? ""
|
||||
self.isOfficial = ((try? container.decode(Int32.self, forKey: "of")) ?? 0) != 0
|
||||
self.totalStringCount = (try? container.decode(Int32.self, forKey: "tsc")) ?? 0
|
||||
self.translatedStringCount = (try? container.decode(Int32.self, forKey: "lsc")) ?? 0
|
||||
self.platformUrl = (try? container.decode(String.self, forKey: "platformUrl")) ?? ""
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeString(self.languageCode, forKey: "lc")
|
||||
@@ -54,4 +68,18 @@ public struct LocalizationInfo: PostboxCoding, Equatable {
|
||||
encoder.encodeInt32(self.translatedStringCount, forKey: "lsc")
|
||||
encoder.encodeString(self.platformUrl, forKey: "platformUrl")
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.languageCode, forKey: "lc")
|
||||
try container.encodeIfPresent(self.baseLanguageCode, forKey: "nlc")
|
||||
try container.encodeIfPresent(self.customPluralizationCode, forKey: "cpc")
|
||||
try container.encode(self.title, forKey: "t")
|
||||
try container.encode(self.localizedTitle, forKey: "lt")
|
||||
try container.encode((self.isOfficial ? 1 : 0) as Int32, forKey: "of")
|
||||
try container.encode(self.totalStringCount, forKey: "tsc")
|
||||
try container.encode(self.translatedStringCount, forKey: "lsc")
|
||||
try container.encode(self.platformUrl, forKey: "platformUrl")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Postbox
|
||||
|
||||
public struct LocalizationListState: PreferencesEntry, Equatable {
|
||||
public struct LocalizationListState: Codable {
|
||||
public var availableOfficialLocalizations: [LocalizationInfo]
|
||||
public var availableSavedLocalizations: [LocalizationInfo]
|
||||
|
||||
@@ -13,21 +13,17 @@ public struct LocalizationListState: PreferencesEntry, Equatable {
|
||||
self.availableSavedLocalizations = availableSavedLocalizations
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.availableOfficialLocalizations = decoder.decodeObjectArrayWithDecoderForKey("availableOfficialLocalizations")
|
||||
self.availableSavedLocalizations = decoder.decodeObjectArrayWithDecoderForKey("availableSavedLocalizations")
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.availableOfficialLocalizations = (try? container.decode([LocalizationInfo].self, forKey: "availableOfficialLocalizations")) ?? []
|
||||
self.availableSavedLocalizations = (try? container.decode([LocalizationInfo].self, forKey: "availableSavedLocalizations")) ?? []
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObjectArray(self.availableOfficialLocalizations, forKey: "availableOfficialLocalizations")
|
||||
encoder.encodeObjectArray(self.availableSavedLocalizations, forKey: "availableSavedLocalizations")
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
guard let to = to as? LocalizationListState else {
|
||||
return false
|
||||
}
|
||||
|
||||
return self == to
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.availableOfficialLocalizations, forKey: "availableOfficialLocalizations")
|
||||
try container.encode(self.availableSavedLocalizations, forKey: "availableSavedLocalizations")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
|
||||
|
||||
public final class LocalizationComponent: Equatable, PostboxCoding {
|
||||
public final class LocalizationComponent: Equatable, Codable {
|
||||
public let languageCode: String
|
||||
public let localizedName: String
|
||||
public let localization: Localization
|
||||
@@ -15,22 +14,22 @@ public final class LocalizationComponent: Equatable, PostboxCoding {
|
||||
self.customPluralizationCode = customPluralizationCode
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.languageCode = decoder.decodeStringForKey("lc", orElse: "")
|
||||
self.localizedName = decoder.decodeStringForKey("localizedName", orElse: "")
|
||||
self.localization = decoder.decodeObjectForKey("loc", decoder: { Localization(decoder: $0) }) as! Localization
|
||||
self.customPluralizationCode = decoder.decodeOptionalStringForKey("cpl")
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.languageCode = (try? container.decode(String.self, forKey: "lc")) ?? ""
|
||||
self.localizedName = (try? container.decode(String.self, forKey: "localizedName")) ?? ""
|
||||
self.localization = try container.decode(Localization.self, forKey: "loc")
|
||||
self.customPluralizationCode = try container.decodeIfPresent(String.self, forKey: "cpl")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeString(self.languageCode, forKey: "lc")
|
||||
encoder.encodeString(self.localizedName, forKey: "localizedName")
|
||||
encoder.encodeObject(self.localization, forKey: "loc")
|
||||
if let customPluralizationCode = self.customPluralizationCode {
|
||||
encoder.encodeString(customPluralizationCode, forKey: "cpl")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "cpl")
|
||||
}
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.languageCode, forKey: "lc")
|
||||
try container.encode(self.localizedName, forKey: "localizedName")
|
||||
try container.encode(self.localization, forKey: "loc")
|
||||
try container.encodeIfPresent(self.customPluralizationCode, forKey: "cpl")
|
||||
}
|
||||
|
||||
public static func ==(lhs: LocalizationComponent, rhs: LocalizationComponent) -> Bool {
|
||||
@@ -50,7 +49,7 @@ public final class LocalizationComponent: Equatable, PostboxCoding {
|
||||
}
|
||||
}
|
||||
|
||||
public final class LocalizationSettings: PreferencesEntry, Equatable {
|
||||
public final class LocalizationSettings: Codable, Equatable {
|
||||
public let primaryComponent: LocalizationComponent
|
||||
public let secondaryComponent: LocalizationComponent?
|
||||
|
||||
@@ -59,31 +58,28 @@ public final class LocalizationSettings: PreferencesEntry, Equatable {
|
||||
self.secondaryComponent = secondaryComponent
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
if let languageCode = decoder.decodeOptionalStringForKey("lc") {
|
||||
self.primaryComponent = LocalizationComponent(languageCode: languageCode, localizedName: "", localization: decoder.decodeObjectForKey("loc", decoder: { Localization(decoder: $0) }) as! Localization, customPluralizationCode: nil)
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
if let languageCode = try container.decodeIfPresent(String.self, forKey: "lc") {
|
||||
self.primaryComponent = LocalizationComponent(
|
||||
languageCode: languageCode,
|
||||
localizedName: "",
|
||||
localization: try container.decode(Localization.self, forKey: "loc"),
|
||||
customPluralizationCode: nil
|
||||
)
|
||||
self.secondaryComponent = nil
|
||||
} else {
|
||||
self.primaryComponent = decoder.decodeObjectForKey("primaryComponent", decoder: { LocalizationComponent(decoder: $0) }) as! LocalizationComponent
|
||||
self.secondaryComponent = decoder.decodeObjectForKey("secondaryComponent", decoder: { LocalizationComponent(decoder: $0) }) as? LocalizationComponent
|
||||
self.primaryComponent = try container.decode(LocalizationComponent.self, forKey: "primaryComponent")
|
||||
self.secondaryComponent = try container.decodeIfPresent(LocalizationComponent.self, forKey: "secondaryComponent")
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObject(self.primaryComponent, forKey: "primaryComponent")
|
||||
if let secondaryComponent = self.secondaryComponent {
|
||||
encoder.encodeObject(secondaryComponent, forKey: "secondaryComponent")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "secondaryComponent")
|
||||
}
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
if let to = to as? LocalizationSettings {
|
||||
return self == to
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.primaryComponent, forKey: "primaryComponent")
|
||||
try container.encodeIfPresent(self.secondaryComponent, forKey: "secondaryComponent")
|
||||
}
|
||||
|
||||
public static func ==(lhs: LocalizationSettings, rhs: LocalizationSettings) -> Bool {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Postbox
|
||||
|
||||
public final class LoggingSettings: PreferencesEntry, Equatable {
|
||||
public final class LoggingSettings: Codable {
|
||||
public let logToFile: Bool
|
||||
public let logToConsole: Bool
|
||||
public let redactSensitiveData: Bool
|
||||
@@ -17,16 +17,20 @@ public final class LoggingSettings: PreferencesEntry, Equatable {
|
||||
self.redactSensitiveData = redactSensitiveData
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.logToFile = decoder.decodeInt32ForKey("logToFile", orElse: 0) != 0
|
||||
self.logToConsole = decoder.decodeInt32ForKey("logToConsole", orElse: 0) != 0
|
||||
self.redactSensitiveData = decoder.decodeInt32ForKey("redactSensitiveData", orElse: 1) != 0
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.logToFile = ((try? container.decode(Int32.self, forKey: "logToFile")) ?? 0) != 0
|
||||
self.logToConsole = ((try? container.decode(Int32.self, forKey: "logToConsole")) ?? 0) != 0
|
||||
self.redactSensitiveData = ((try? container.decode(Int32.self, forKey: "redactSensitiveData")) ?? 1) != 0
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.logToFile ? 1 : 0, forKey: "logToFile")
|
||||
encoder.encodeInt32(self.logToConsole ? 1 : 0, forKey: "logToConsole")
|
||||
encoder.encodeInt32(self.redactSensitiveData ? 1 : 0, forKey: "redactSensitiveData")
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.logToFile ? 1 : 0, forKey: "logToFile")
|
||||
try container.encode(self.logToConsole ? 1 : 0, forKey: "logToConsole")
|
||||
try container.encode(self.redactSensitiveData ? 1 : 0, forKey: "redactSensitiveData")
|
||||
}
|
||||
|
||||
public func withUpdatedLogToFile(_ logToFile: Bool) -> LoggingSettings {
|
||||
@@ -53,12 +57,4 @@ public final class LoggingSettings: PreferencesEntry, Equatable {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
guard let to = to as? LoggingSettings else {
|
||||
return false
|
||||
}
|
||||
|
||||
return self == to
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,33 @@
|
||||
import Postbox
|
||||
|
||||
public struct NetworkSettings: PreferencesEntry, Equatable {
|
||||
public struct NetworkSettings: Codable {
|
||||
public var reducedBackupDiscoveryTimeout: Bool
|
||||
public var applicationUpdateUrlPrefix: String?
|
||||
public var backupHostOverride: String?
|
||||
public var defaultEnableTempKeys: Bool
|
||||
public var userEnableTempKeys: Bool?
|
||||
|
||||
public static var defaultSettings: NetworkSettings {
|
||||
return NetworkSettings(reducedBackupDiscoveryTimeout: false, applicationUpdateUrlPrefix: nil, backupHostOverride: nil, defaultEnableTempKeys: false, userEnableTempKeys: nil)
|
||||
return NetworkSettings(reducedBackupDiscoveryTimeout: false, applicationUpdateUrlPrefix: nil, backupHostOverride: nil)
|
||||
}
|
||||
|
||||
public init(reducedBackupDiscoveryTimeout: Bool, applicationUpdateUrlPrefix: String?, backupHostOverride: String?, defaultEnableTempKeys: Bool, userEnableTempKeys: Bool?) {
|
||||
public init(reducedBackupDiscoveryTimeout: Bool, applicationUpdateUrlPrefix: String?, backupHostOverride: String?) {
|
||||
self.reducedBackupDiscoveryTimeout = reducedBackupDiscoveryTimeout
|
||||
self.applicationUpdateUrlPrefix = applicationUpdateUrlPrefix
|
||||
self.backupHostOverride = backupHostOverride
|
||||
self.defaultEnableTempKeys = defaultEnableTempKeys
|
||||
self.userEnableTempKeys = userEnableTempKeys
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.reducedBackupDiscoveryTimeout = decoder.decodeInt32ForKey("reducedBackupDiscoveryTimeout", orElse: 0) != 0
|
||||
self.applicationUpdateUrlPrefix = decoder.decodeOptionalStringForKey("applicationUpdateUrlPrefix")
|
||||
self.backupHostOverride = decoder.decodeOptionalStringForKey("backupHostOverride")
|
||||
self.defaultEnableTempKeys = decoder.decodeBoolForKey("defaultEnableTempKeys", orElse: false)
|
||||
self.userEnableTempKeys = decoder.decodeOptionalBoolForKey("userEnableTempKeys")
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.reducedBackupDiscoveryTimeout = ((try? container.decode(Int32.self, forKey: "reducedBackupDiscoveryTimeout")) ?? 0) != 0
|
||||
self.applicationUpdateUrlPrefix = try? container.decodeIfPresent(String.self, forKey: "applicationUpdateUrlPrefix")
|
||||
self.backupHostOverride = try? container.decodeIfPresent(String.self, forKey: "backupHostOverride")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.reducedBackupDiscoveryTimeout ? 1 : 0, forKey: "reducedBackupDiscoveryTimeout")
|
||||
if let applicationUpdateUrlPrefix = self.applicationUpdateUrlPrefix {
|
||||
encoder.encodeString(applicationUpdateUrlPrefix, forKey: "applicationUpdateUrlPrefix")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "applicationUpdateUrlPrefix")
|
||||
}
|
||||
if let backupHostOverride = self.backupHostOverride {
|
||||
encoder.encodeString(backupHostOverride, forKey: "backupHostOverride")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "backupHostOverride")
|
||||
}
|
||||
encoder.encodeBool(self.defaultEnableTempKeys, forKey: "defaultEnableTempKeys")
|
||||
if let userEnableTempKeys = self.userEnableTempKeys {
|
||||
encoder.encodeBool(userEnableTempKeys, forKey: "userEnableTempKeys")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "userEnableTempKeys")
|
||||
}
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
guard let to = to as? NetworkSettings else {
|
||||
return false
|
||||
}
|
||||
|
||||
return self == to
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode((self.reducedBackupDiscoveryTimeout ? 1 : 0) as Int32, forKey: "reducedBackupDiscoveryTimeout")
|
||||
try container.encodeIfPresent(self.applicationUpdateUrlPrefix, forKey: "applicationUpdateUrlPrefix")
|
||||
try container.encodeIfPresent(self.backupHostOverride, forKey: "backupHostOverride")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,36 @@
|
||||
import Postbox
|
||||
|
||||
public enum PeerReference: PostboxCoding, Hashable, Equatable {
|
||||
case user(id: Int32, accessHash: Int64)
|
||||
case group(id: Int32)
|
||||
case channel(id: Int32, accessHash: Int64)
|
||||
case user(id: Int64, accessHash: Int64)
|
||||
case group(id: Int64)
|
||||
case channel(id: Int64, accessHash: Int64)
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
switch decoder.decodeInt32ForKey("_r", orElse: 0) {
|
||||
case 0:
|
||||
self = .user(id: decoder.decodeInt32ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0))
|
||||
let id: Int64
|
||||
if let idValue = decoder.decodeOptionalInt64ForKey("i") {
|
||||
id = idValue
|
||||
} else {
|
||||
id = Int64(decoder.decodeInt32ForKey("i", orElse: 0))
|
||||
}
|
||||
self = .user(id: id, accessHash: decoder.decodeInt64ForKey("h", orElse: 0))
|
||||
case 1:
|
||||
self = .group(id: decoder.decodeInt32ForKey("i", orElse: 0))
|
||||
let id: Int64
|
||||
if let idValue = decoder.decodeOptionalInt64ForKey("i") {
|
||||
id = idValue
|
||||
} else {
|
||||
id = Int64(decoder.decodeInt32ForKey("i", orElse: 0))
|
||||
}
|
||||
self = .group(id: id)
|
||||
case 2:
|
||||
self = .channel(id: decoder.decodeInt32ForKey("i", orElse: 0), accessHash: decoder.decodeInt64ForKey("h", orElse: 0))
|
||||
let id: Int64
|
||||
if let idValue = decoder.decodeOptionalInt64ForKey("i") {
|
||||
id = idValue
|
||||
} else {
|
||||
id = Int64(decoder.decodeInt32ForKey("i", orElse: 0))
|
||||
}
|
||||
self = .channel(id: id, accessHash: decoder.decodeInt64ForKey("h", orElse: 0))
|
||||
default:
|
||||
assertionFailure()
|
||||
self = .user(id: 0, accessHash: 0)
|
||||
@@ -23,14 +41,14 @@ public enum PeerReference: PostboxCoding, Hashable, Equatable {
|
||||
switch self {
|
||||
case let .user(id, accessHash):
|
||||
encoder.encodeInt32(0, forKey: "_r")
|
||||
encoder.encodeInt32(id, forKey: "i")
|
||||
encoder.encodeInt64(id, forKey: "i")
|
||||
encoder.encodeInt64(accessHash, forKey: "h")
|
||||
case let .group(id):
|
||||
encoder.encodeInt32(1, forKey: "_r")
|
||||
encoder.encodeInt32(id, forKey: "i")
|
||||
encoder.encodeInt64(id, forKey: "i")
|
||||
case let .channel(id, accessHash):
|
||||
encoder.encodeInt32(2, forKey: "_r")
|
||||
encoder.encodeInt32(id, forKey: "i")
|
||||
encoder.encodeInt64(id, forKey: "i")
|
||||
encoder.encodeInt64(accessHash, forKey: "h")
|
||||
}
|
||||
}
|
||||
@@ -39,15 +57,15 @@ public enum PeerReference: PostboxCoding, Hashable, Equatable {
|
||||
switch peer {
|
||||
case let user as TelegramUser:
|
||||
if let accessHash = user.accessHash {
|
||||
self = .user(id: user.id.id._internalGetInt32Value(), accessHash: accessHash.value)
|
||||
self = .user(id: user.id.id._internalGetInt64Value(), accessHash: accessHash.value)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
case let group as TelegramGroup:
|
||||
self = .group(id: group.id.id._internalGetInt32Value())
|
||||
self = .group(id: group.id.id._internalGetInt64Value())
|
||||
case let channel as TelegramChannel:
|
||||
if let accessHash = channel.accessHash {
|
||||
self = .channel(id: channel.id.id._internalGetInt32Value(), accessHash: accessHash.value)
|
||||
self = .channel(id: channel.id.id._internalGetInt64Value(), accessHash: accessHash.value)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,43 +1,39 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
|
||||
public enum ProxyServerConnection: Equatable, Hashable, PostboxCoding {
|
||||
public enum ProxyServerConnection: Equatable, Hashable, Codable {
|
||||
case socks5(username: String?, password: String?)
|
||||
case mtp(secret: Data)
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
switch decoder.decodeInt32ForKey("_t", orElse: 0) {
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
switch try container.decode(Int32.self, forKey: "_t") {
|
||||
case 0:
|
||||
self = .socks5(username: decoder.decodeOptionalStringForKey("username"), password: decoder.decodeOptionalStringForKey("password"))
|
||||
self = .socks5(username: try container.decodeIfPresent(String.self, forKey: "username"), password: try container.decodeIfPresent(String.self, forKey: "password"))
|
||||
case 1:
|
||||
self = .mtp(secret: decoder.decodeBytesForKey("secret")?.makeData() ?? Data())
|
||||
self = .mtp(secret: try container.decode(Data.self, forKey: "secret"))
|
||||
default:
|
||||
self = .socks5(username: nil, password: nil)
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
switch self {
|
||||
case let .socks5(username, password):
|
||||
encoder.encodeInt32(0, forKey: "_t")
|
||||
if let username = username {
|
||||
encoder.encodeString(username, forKey: "username")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "username")
|
||||
}
|
||||
if let password = password {
|
||||
encoder.encodeString(password, forKey: "password")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "password")
|
||||
}
|
||||
try container.encode(0 as Int32, forKey: "_t")
|
||||
try container.encodeIfPresent(username, forKey: "username")
|
||||
try container.encodeIfPresent(password, forKey: "password")
|
||||
case let .mtp(secret):
|
||||
encoder.encodeInt32(1, forKey: "_t")
|
||||
encoder.encodeBytes(MemoryBuffer(data: secret), forKey: "secret")
|
||||
try container.encode(1 as Int32, forKey: "_t")
|
||||
try container.encode(secret, forKey: "secret")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct ProxyServerSettings: PostboxCoding, Equatable, Hashable {
|
||||
public struct ProxyServerSettings: Codable, Equatable, Hashable {
|
||||
public let host: String
|
||||
public let port: Int32
|
||||
public let connection: ProxyServerConnection
|
||||
@@ -48,31 +44,33 @@ public struct ProxyServerSettings: PostboxCoding, Equatable, Hashable {
|
||||
self.connection = connection
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.host = decoder.decodeStringForKey("host", orElse: "")
|
||||
self.port = decoder.decodeInt32ForKey("port", orElse: 0)
|
||||
if let username = decoder.decodeOptionalStringForKey("username") {
|
||||
self.connection = .socks5(username: username, password: decoder.decodeOptionalStringForKey("password"))
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.host = (try? container.decode(String.self, forKey: "host")) ?? ""
|
||||
self.port = (try? container.decode(Int32.self, forKey: "port")) ?? 0
|
||||
if let username = try container.decodeIfPresent(String.self, forKey: "username") {
|
||||
self.connection = .socks5(username: username, password: try container.decodeIfPresent(String.self, forKey: "password"))
|
||||
} else {
|
||||
self.connection = decoder.decodeObjectForKey("connection", decoder: ProxyServerConnection.init(decoder:)) as? ProxyServerConnection ?? ProxyServerConnection.socks5(username: nil, password: nil)
|
||||
self.connection = (try? container.decodeIfPresent(ProxyServerConnection.self, forKey: "connection")) ?? ProxyServerConnection.socks5(username: nil, password: nil)
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeString(self.host, forKey: "host")
|
||||
encoder.encodeInt32(self.port, forKey: "port")
|
||||
encoder.encodeObject(self.connection, forKey: "connection")
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.host, forKey: "host")
|
||||
try container.encode(self.port, forKey: "port")
|
||||
try container.encode(self.connection, forKey: "connection")
|
||||
}
|
||||
|
||||
public var hashValue: Int {
|
||||
var hash = self.host.hashValue
|
||||
hash = hash &* 31 &+ self.port.hashValue
|
||||
hash = hash &* 31 &+ self.connection.hashValue
|
||||
return hash
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(self.host)
|
||||
hasher.combine(self.connection)
|
||||
}
|
||||
}
|
||||
|
||||
public struct ProxySettings: PreferencesEntry, Equatable {
|
||||
public struct ProxySettings: Codable, Equatable {
|
||||
public var enabled: Bool
|
||||
public var servers: [ProxyServerSettings]
|
||||
public var activeServer: ProxyServerSettings?
|
||||
@@ -89,41 +87,22 @@ public struct ProxySettings: PreferencesEntry, Equatable {
|
||||
self.useForCalls = useForCalls
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
if let _ = decoder.decodeOptionalStringForKey("host") {
|
||||
let legacyServer = ProxyServerSettings(decoder: decoder)
|
||||
if !legacyServer.host.isEmpty && legacyServer.port != 0 {
|
||||
self.enabled = true
|
||||
self.servers = [legacyServer]
|
||||
} else {
|
||||
self.enabled = false
|
||||
self.servers = []
|
||||
}
|
||||
} else {
|
||||
self.enabled = decoder.decodeInt32ForKey("enabled", orElse: 0) != 0
|
||||
self.servers = decoder.decodeObjectArrayWithDecoderForKey("servers")
|
||||
}
|
||||
self.activeServer = decoder.decodeObjectForKey("activeServer", decoder: ProxyServerSettings.init(decoder:)) as? ProxyServerSettings
|
||||
self.useForCalls = decoder.decodeInt32ForKey("useForCalls", orElse: 0) != 0
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.enabled = ((try? container.decode(Int32.self, forKey: "enabled")) ?? 0) != 0
|
||||
self.servers = try container.decode([ProxyServerSettings].self, forKey: "servers")
|
||||
self.activeServer = try container.decodeIfPresent(ProxyServerSettings.self, forKey: "activeServer")
|
||||
self.useForCalls = ((try? container.decode(Int32.self, forKey: "useForCalls")) ?? 0) != 0
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.enabled ? 1 : 0, forKey: "enabled")
|
||||
encoder.encodeObjectArray(self.servers, forKey: "servers")
|
||||
if let activeServer = self.activeServer {
|
||||
encoder.encodeObject(activeServer, forKey: "activeServer")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "activeServer")
|
||||
}
|
||||
encoder.encodeInt32(self.useForCalls ? 1 : 0, forKey: "useForCalls")
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
guard let to = to as? ProxySettings else {
|
||||
return false
|
||||
}
|
||||
|
||||
return self == to
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode((self.enabled ? 1 : 0) as Int32, forKey: "enabled")
|
||||
try container.encode(self.servers, forKey: "servers")
|
||||
try container.encodeIfPresent(self.activeServer, forKey: "activeServer")
|
||||
try container.encode((self.useForCalls ? 1 : 0) as Int32, forKey: "useForCalls")
|
||||
}
|
||||
|
||||
public var effectiveActiveServer: ProxyServerSettings? {
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
import Postbox
|
||||
|
||||
public final class RemoteStorageConfiguration: PreferencesEntry {
|
||||
public final class RemoteStorageConfiguration: Codable, Equatable {
|
||||
public let webDocumentsHostDatacenterId: Int32
|
||||
|
||||
public init(webDocumentsHostDatacenterId: Int32) {
|
||||
self.webDocumentsHostDatacenterId = webDocumentsHostDatacenterId
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.webDocumentsHostDatacenterId = decoder.decodeInt32ForKey("webDocumentsHostDatacenterId", orElse: 4)
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.webDocumentsHostDatacenterId = try container.decode(Int32.self, forKey: "webDocumentsHostDatacenterId")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.webDocumentsHostDatacenterId, forKey: "webDocumentsHostDatacenterId")
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.webDocumentsHostDatacenterId, forKey: "webDocumentsHostDatacenterId")
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
guard let to = to as? RemoteStorageConfiguration else {
|
||||
return false
|
||||
}
|
||||
if self.webDocumentsHostDatacenterId != to.webDocumentsHostDatacenterId {
|
||||
|
||||
public static func ==(lhs: RemoteStorageConfiguration, rhs: RemoteStorageConfiguration) -> Bool {
|
||||
if lhs.webDocumentsHostDatacenterId != rhs.webDocumentsHostDatacenterId {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
|
||||
public struct SearchBotsConfiguration: Equatable, PreferencesEntry {
|
||||
public struct SearchBotsConfiguration: Equatable, Codable {
|
||||
public let imageBotUsername: String?
|
||||
public let gifBotUsername: String?
|
||||
public let venueBotUsername: String?
|
||||
@@ -16,40 +16,25 @@ public struct SearchBotsConfiguration: Equatable, PreferencesEntry {
|
||||
self.venueBotUsername = venueBotUsername
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.imageBotUsername = decoder.decodeOptionalStringForKey("img")
|
||||
self.gifBotUsername = decoder.decodeOptionalStringForKey("gif")
|
||||
self.venueBotUsername = decoder.decodeOptionalStringForKey("venue")
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.imageBotUsername = try container.decodeIfPresent(String.self, forKey: "img")
|
||||
self.gifBotUsername = try container.decodeIfPresent(String.self, forKey: "gif")
|
||||
self.venueBotUsername = try container.decodeIfPresent(String.self, forKey: "venue")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
if let imageBotUsername = self.imageBotUsername {
|
||||
encoder.encodeString(imageBotUsername, forKey: "img")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "img")
|
||||
}
|
||||
if let gifBotUsername = self.gifBotUsername {
|
||||
encoder.encodeString(gifBotUsername, forKey: "gif")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "gif")
|
||||
}
|
||||
if let venueBotUsername = self.venueBotUsername {
|
||||
encoder.encodeString(venueBotUsername, forKey: "venue")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "venue")
|
||||
}
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
guard let to = to as? SearchBotsConfiguration else {
|
||||
return false
|
||||
}
|
||||
return self == to
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encodeIfPresent(self.imageBotUsername, forKey: "img")
|
||||
try container.encodeIfPresent(self.gifBotUsername, forKey: "gif")
|
||||
try container.encodeIfPresent(self.venueBotUsername, forKey: "venue")
|
||||
}
|
||||
}
|
||||
|
||||
public func currentSearchBotsConfiguration(transaction: Transaction) -> SearchBotsConfiguration {
|
||||
if let entry = transaction.getPreferencesEntry(key: PreferencesKeys.searchBotsConfiguration) as? SearchBotsConfiguration {
|
||||
if let entry = transaction.getPreferencesEntry(key: PreferencesKeys.searchBotsConfiguration)?.get(SearchBotsConfiguration.self) {
|
||||
return entry
|
||||
} else {
|
||||
return SearchBotsConfiguration.defaultValue
|
||||
@@ -57,7 +42,7 @@ public func currentSearchBotsConfiguration(transaction: Transaction) -> SearchBo
|
||||
}
|
||||
|
||||
public func updateSearchBotsConfiguration(transaction: Transaction, configuration: SearchBotsConfiguration) {
|
||||
if !currentSearchBotsConfiguration(transaction: transaction).isEqual(to: configuration) {
|
||||
transaction.setPreferencesEntry(key: PreferencesKeys.searchBotsConfiguration, value: configuration)
|
||||
if currentSearchBotsConfiguration(transaction: transaction) != configuration {
|
||||
transaction.setPreferencesEntry(key: PreferencesKeys.searchBotsConfiguration, value: PreferencesEntry(configuration))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import Foundation
|
||||
import Postbox
|
||||
|
||||
|
||||
public struct SecretChatSettings: Equatable, PreferencesEntry {
|
||||
public struct SecretChatSettings: Equatable, Codable {
|
||||
public private(set) var acceptOnThisDevice: Bool
|
||||
|
||||
public static var defaultSettings: SecretChatSettings {
|
||||
@@ -13,19 +13,15 @@ public struct SecretChatSettings: Equatable, PreferencesEntry {
|
||||
self.acceptOnThisDevice = acceptOnThisDevice
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.acceptOnThisDevice = decoder.decodeInt32ForKey("acceptOnThisDevice", orElse: 1) != 0
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.acceptOnThisDevice = ((try? container.decode(Int32.self, forKey: "acceptOnThisDevice")) ?? 1) != 0
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.acceptOnThisDevice ? 1 : 0, forKey: "acceptOnThisDevice")
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
if let to = to as? SecretChatSettings {
|
||||
return self == to
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode((self.acceptOnThisDevice ? 1 : 0) as Int32, forKey: "acceptOnThisDevice")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public let telegramPostboxSeedConfiguration: SeedConfiguration = {
|
||||
globalMessageIdsPeerIdNamespaces.insert(GlobalMessageIdsNamespace(peerIdNamespace: peerIdNamespace, messageIdNamespace: Namespaces.Message.Cloud))
|
||||
}
|
||||
|
||||
return SeedConfiguration(globalMessageIdsPeerIdNamespaces: globalMessageIdsPeerIdNamespaces, initializeChatListWithHole: (topLevel: ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: PeerId.Id._internalFromInt32Value(0)), namespace: Namespaces.Message.Cloud, id: 1), timestamp: Int32.max - 1)), groups: ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: PeerId.Id._internalFromInt32Value(0)), namespace: Namespaces.Message.Cloud, id: 1), timestamp: Int32.max - 1))), messageHoles: messageHoles, upgradedMessageHoles: upgradedMessageHoles, messageThreadHoles: messageThreadHoles, existingMessageTags: MessageTags.all, messageTagsWithSummary: [.unseenPersonalMessage, .pinned], existingGlobalMessageTags: GlobalMessageTags.all, peerNamespacesRequiringMessageTextIndex: [Namespaces.Peer.SecretChat], peerSummaryCounterTags: { peer, isContact in
|
||||
return SeedConfiguration(globalMessageIdsPeerIdNamespaces: globalMessageIdsPeerIdNamespaces, initializeChatListWithHole: (topLevel: ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: PeerId.Id._internalFromInt64Value(0)), namespace: Namespaces.Message.Cloud, id: 1), timestamp: Int32.max - 1)), groups: ChatListHole(index: MessageIndex(id: MessageId(peerId: PeerId(namespace: Namespaces.Peer.Empty, id: PeerId.Id._internalFromInt64Value(0)), namespace: Namespaces.Message.Cloud, id: 1), timestamp: Int32.max - 1))), messageHoles: messageHoles, upgradedMessageHoles: upgradedMessageHoles, messageThreadHoles: messageThreadHoles, existingMessageTags: MessageTags.all, messageTagsWithSummary: [.unseenPersonalMessage, .pinned], existingGlobalMessageTags: GlobalMessageTags.all, peerNamespacesRequiringMessageTextIndex: [Namespaces.Peer.SecretChat], peerSummaryCounterTags: { peer, isContact in
|
||||
if let peer = peer as? TelegramUser {
|
||||
if peer.botInfo != nil {
|
||||
return .bot
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Postbox
|
||||
|
||||
public final class SuggestedLocalizationEntry: PreferencesEntry {
|
||||
public final class SuggestedLocalizationEntry: Codable {
|
||||
public let languageCode: String
|
||||
public let isSeen: Bool
|
||||
|
||||
@@ -9,22 +9,18 @@ public final class SuggestedLocalizationEntry: PreferencesEntry {
|
||||
self.isSeen = isSeen
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.languageCode = decoder.decodeStringForKey("lc", orElse: "en")
|
||||
self.isSeen = decoder.decodeInt32ForKey("s", orElse: 0) != 0
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.languageCode = try container.decode(String.self, forKey: "lc")
|
||||
self.isSeen = (try container.decode(Int32.self, forKey: "s")) != 0
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeString(self.languageCode, forKey: "lc")
|
||||
encoder.encodeInt32(self.isSeen ? 1 : 0, forKey: "s")
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
if let to = to as? SuggestedLocalizationEntry {
|
||||
return self == to
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.languageCode, forKey: "lc")
|
||||
try container.encode((self.isSeen ? 1 : 0) as Int32, forKey: "s")
|
||||
}
|
||||
|
||||
public static func ==(lhs: SuggestedLocalizationEntry, rhs: SuggestedLocalizationEntry) -> Bool {
|
||||
|
||||
@@ -48,7 +48,7 @@ public func addSynchronizePinnedChatsOperation(transaction: Transaction, groupId
|
||||
var previousItemIds = transaction.getPinnedItemIds(groupId: groupId)
|
||||
var updateLocalIndex: Int32?
|
||||
|
||||
transaction.operationLogEnumerateEntries(peerId: PeerId(namespace: PeerId.Namespace._internalFromInt32Value(0), id: PeerId.Id._internalFromInt32Value(rawId)), tag: OperationLogTags.SynchronizePinnedChats, { entry in
|
||||
transaction.operationLogEnumerateEntries(peerId: PeerId(namespace: PeerId.Namespace._internalFromInt32Value(0), id: PeerId.Id._internalFromInt64Value(Int64(rawId))), tag: OperationLogTags.SynchronizePinnedChats, { entry in
|
||||
updateLocalIndex = entry.tagLocalIndex
|
||||
if let contents = entry.contents as? SynchronizePinnedChatsOperation {
|
||||
previousItemIds = contents.previousItemIds
|
||||
@@ -57,7 +57,7 @@ public func addSynchronizePinnedChatsOperation(transaction: Transaction, groupId
|
||||
})
|
||||
let operationContents = SynchronizePinnedChatsOperation(previousItemIds: previousItemIds)
|
||||
if let updateLocalIndex = updateLocalIndex {
|
||||
let _ = transaction.operationLogRemoveEntry(peerId: PeerId(namespace: PeerId.Namespace._internalFromInt32Value(0), id: PeerId.Id._internalFromInt32Value(rawId)), tag: OperationLogTags.SynchronizePinnedChats, tagLocalIndex: updateLocalIndex)
|
||||
let _ = transaction.operationLogRemoveEntry(peerId: PeerId(namespace: PeerId.Namespace._internalFromInt32Value(0), id: PeerId.Id._internalFromInt64Value(Int64(rawId))), tag: OperationLogTags.SynchronizePinnedChats, tagLocalIndex: updateLocalIndex)
|
||||
}
|
||||
transaction.operationLogAddEntry(peerId: PeerId(namespace: PeerId.Namespace._internalFromInt32Value(0), id: PeerId.Id._internalFromInt32Value(rawId)), tag: OperationLogTags.SynchronizePinnedChats, tagLocalIndex: .automatic, tagMergedIndex: .automatic, contents: operationContents)
|
||||
transaction.operationLogAddEntry(peerId: PeerId(namespace: PeerId.Namespace._internalFromInt32Value(0), id: PeerId.Id._internalFromInt64Value(Int64(rawId))), tag: OperationLogTags.SynchronizePinnedChats, tagLocalIndex: .automatic, tagMergedIndex: .automatic, contents: operationContents)
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public final class TelegramPeerNotificationSettings: PeerNotificationSettings, E
|
||||
self.displayPreviews = displayPreviews
|
||||
}
|
||||
|
||||
public init() {
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.muteState = PeerMuteState.decodeInline(decoder)
|
||||
self.messageSound = PeerMessageSound.decodeInline(decoder)
|
||||
self.displayPreviews = PeerNotificationDisplayPreviews.decodeInline(decoder)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
|
||||
public enum TelegramBaseTheme: Int32 {
|
||||
@@ -13,7 +14,7 @@ public extension UInt32 {
|
||||
}
|
||||
}
|
||||
|
||||
public final class TelegramThemeSettings: PostboxCoding, Equatable {
|
||||
public final class TelegramThemeSettings: PostboxCoding, Codable, Equatable {
|
||||
public static func == (lhs: TelegramThemeSettings, rhs: TelegramThemeSettings) -> Bool {
|
||||
if lhs.baseTheme != rhs.baseTheme {
|
||||
return false
|
||||
@@ -63,6 +64,21 @@ public final class TelegramThemeSettings: PostboxCoding, Equatable {
|
||||
self.animateMessageColors = decoder.decodeInt32ForKey("animateMessageColors", orElse: 0) != 0
|
||||
self.wallpaper = decoder.decodeObjectForKey("wallpaper", decoder: { TelegramWallpaper(decoder: $0) }) as? TelegramWallpaper
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.baseTheme = TelegramBaseTheme(rawValue: try container.decode(Int32.self, forKey: "baseTheme")) ?? .classic
|
||||
self.accentColor = UInt32(bitPattern: try container.decode(Int32.self, forKey: "accent"))
|
||||
self.messageColors = (try container.decode([Int32].self, forKey: "messageColors")).map(UInt32.init(bitPattern:))
|
||||
self.animateMessageColors = (try container.decode(Int32.self, forKey: "animateMessageColors")) != 0
|
||||
|
||||
if let wallpaperData = try container.decodeIfPresent(Data.self, forKey: "wallpaper") {
|
||||
self.wallpaper = TelegramWallpaper(decoder: PostboxDecoder(buffer: MemoryBuffer(data: wallpaperData)))
|
||||
} else {
|
||||
self.wallpaper = nil
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.baseTheme.rawValue, forKey: "baseTheme")
|
||||
@@ -75,9 +91,26 @@ public final class TelegramThemeSettings: PostboxCoding, Equatable {
|
||||
encoder.encodeNil(forKey: "wallpaper")
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.baseTheme.rawValue, forKey: "baseTheme")
|
||||
try container.encode(Int32(bitPattern: self.accentColor), forKey: "accent")
|
||||
try container.encode(self.messageColors.map(Int32.init(bitPattern:)), forKey: "messageColors")
|
||||
try container.encode((self.animateMessageColors ? 1 : 0) as Int32, forKey: "animateMessageColors")
|
||||
|
||||
if let wallpaper = self.wallpaper {
|
||||
let innerEncoder = PostboxEncoder()
|
||||
wallpaper.encode(innerEncoder)
|
||||
try container.encode(innerEncoder.makeData(), forKey: "wallpaper")
|
||||
} else {
|
||||
try container.encodeNil(forKey: "wallpaper")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final class TelegramTheme: OrderedItemListEntryContents, Equatable {
|
||||
public final class TelegramTheme: Codable, OrderedItemListEntryContents, Equatable {
|
||||
public let id: Int64
|
||||
public let accessHash: Int64
|
||||
public let slug: String
|
||||
@@ -111,6 +144,27 @@ public final class TelegramTheme: OrderedItemListEntryContents, Equatable {
|
||||
self.isDefault = decoder.decodeInt32ForKey("isDefault", orElse: 0) != 0
|
||||
self.installCount = decoder.decodeOptionalInt32ForKey("installCount")
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.id = try container.decode(Int64.self, forKey: "id")
|
||||
self.accessHash = try container.decode(Int64.self, forKey: "accessHash")
|
||||
self.slug = try container.decode(String.self, forKey: "slug")
|
||||
self.title = try container.decode(String.self, forKey: "title")
|
||||
|
||||
if let fileData = try container.decodeIfPresent(Data.self, forKey: "file") {
|
||||
self.file = TelegramMediaFile(decoder: PostboxDecoder(buffer: MemoryBuffer(data: fileData)))
|
||||
} else {
|
||||
self.file = nil
|
||||
}
|
||||
|
||||
self.settings = try container.decodeIfPresent(TelegramThemeSettings.self, forKey: "settings")
|
||||
|
||||
self.isCreator = (try container.decode(Int32.self, forKey: "isCreator")) != 0
|
||||
self.isDefault = (try container.decode(Int32.self, forKey: "isDefault")) != 0
|
||||
self.installCount = try container.decodeIfPresent(Int32.self, forKey: "installCount")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt64(self.id, forKey: "id")
|
||||
@@ -135,6 +189,26 @@ public final class TelegramTheme: OrderedItemListEntryContents, Equatable {
|
||||
encoder.encodeNil(forKey: "installCount")
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.id, forKey: "id")
|
||||
try container.encode(self.accessHash, forKey: "accessHash")
|
||||
try container.encode(self.slug, forKey: "slug")
|
||||
try container.encode(self.title, forKey: "title")
|
||||
if let file = self.file {
|
||||
let innerEncoder = PostboxEncoder()
|
||||
file.encode(innerEncoder)
|
||||
try container.encode(innerEncoder.makeData(), forKey: "file")
|
||||
} else {
|
||||
try container.encodeNil(forKey: "file")
|
||||
}
|
||||
try container.encodeIfPresent(self.settings, forKey: "settings")
|
||||
try container.encode((self.isCreator ? 1 : 0) as Int32, forKey: "isCreator")
|
||||
try container.encode((self.isDefault ? 1 : 0) as Int32, forKey: "isDefault")
|
||||
try container.encodeIfPresent(self.installCount, forKey: "installCount")
|
||||
}
|
||||
|
||||
public static func ==(lhs: TelegramTheme, rhs: TelegramTheme) -> Bool {
|
||||
if lhs.id != rhs.id {
|
||||
|
||||
@@ -1,30 +1,22 @@
|
||||
import Postbox
|
||||
|
||||
public final class ThemeSettings: PreferencesEntry, Equatable {
|
||||
public final class ThemeSettings: Codable, Equatable {
|
||||
public let currentTheme: TelegramTheme?
|
||||
|
||||
public init(currentTheme: TelegramTheme?) {
|
||||
self.currentTheme = currentTheme
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.currentTheme = decoder.decodeObjectForKey("t", decoder: { TelegramTheme(decoder: $0) }) as? TelegramTheme
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.currentTheme = try container.decodeIfPresent(TelegramTheme.self, forKey: "t")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
if let currentTheme = currentTheme {
|
||||
encoder.encodeObject(currentTheme, forKey: "t")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "t")
|
||||
}
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
if let to = to as? ThemeSettings {
|
||||
return self == to
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encodeIfPresent(self.currentTheme, forKey: "t")
|
||||
}
|
||||
|
||||
public static func ==(lhs: ThemeSettings, rhs: ThemeSettings) -> Bool {
|
||||
|
||||
@@ -7,7 +7,7 @@ public enum VoiceCallP2PMode: Int32 {
|
||||
case always = 2
|
||||
}
|
||||
|
||||
public struct VoipConfiguration: PreferencesEntry, Equatable {
|
||||
public struct VoipConfiguration: Codable, Equatable {
|
||||
public var serializedData: String?
|
||||
|
||||
public static var defaultValue: VoipConfiguration {
|
||||
@@ -18,22 +18,15 @@ public struct VoipConfiguration: PreferencesEntry, Equatable {
|
||||
self.serializedData = serializedData
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.serializedData = decoder.decodeOptionalStringForKey("serializedData")
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.serializedData = try container.decodeIfPresent(String.self, forKey: "serializedData")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
if let serializedData = self.serializedData {
|
||||
encoder.encodeString(serializedData, forKey: "serializedData")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "serializedData")
|
||||
}
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
guard let to = to as? VoipConfiguration else {
|
||||
return false
|
||||
}
|
||||
return self == to
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encodeIfPresent(self.serializedData, forKey: "serializedData")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
|
||||
public struct WalletCollectionItem: Equatable, PostboxCoding {
|
||||
public let info: Data
|
||||
public var exportCompleted: Bool
|
||||
public var state: Data?
|
||||
|
||||
public init(info: Data, exportCompleted: Bool, state: Data?) {
|
||||
self.info = info
|
||||
self.exportCompleted = exportCompleted
|
||||
self.state = state
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.info = decoder.decodeDataForKey("info") ?? Data()
|
||||
self.exportCompleted = decoder.decodeInt32ForKey("exportCompleted", orElse: 0) != 0
|
||||
self.state = decoder.decodeDataForKey("state")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeData(self.info, forKey: "info")
|
||||
encoder.encodeInt32(self.exportCompleted ? 1 : 0, forKey: "exportCompleted")
|
||||
if let state = self.state {
|
||||
encoder.encodeData(state, forKey: "state")
|
||||
} else {
|
||||
encoder.encodeNil(forKey: "state")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct WalletCollection: PreferencesEntry {
|
||||
public var wallets: [WalletCollectionItem]
|
||||
|
||||
public init(wallets: [WalletCollectionItem]) {
|
||||
self.wallets = wallets
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.wallets = decoder.decodeObjectArrayWithDecoderForKey("wallets")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObjectArray(self.wallets, forKey: "wallets")
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
guard let other = to as? WalletCollection else {
|
||||
return false
|
||||
}
|
||||
if self.wallets != other.wallets {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import Foundation
|
||||
import Postbox
|
||||
import SwiftSignalKit
|
||||
|
||||
public struct WallpapersState: PreferencesEntry, Equatable {
|
||||
public struct WallpapersState: Codable, Equatable {
|
||||
public var wallpapers: [TelegramWallpaper]
|
||||
|
||||
public static var `default`: WallpapersState {
|
||||
@@ -12,24 +13,33 @@ public struct WallpapersState: PreferencesEntry, Equatable {
|
||||
self.wallpapers = wallpapers
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.wallpapers = decoder.decodeObjectArrayWithDecoderForKey("wallpapers")
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
let wallpapersData = try container.decode([Data].self, forKey: "wallpapers")
|
||||
self.wallpapers = wallpapersData.map { data in
|
||||
return TelegramWallpaper(decoder: PostboxDecoder(buffer: MemoryBuffer(data: data)))
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeObjectArray(self.wallpapers, forKey: "wallpapers")
|
||||
}
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
return self == (to as? WallpapersState)
|
||||
let wallpapersData: [Data] = self.wallpapers.map { wallpaper in
|
||||
let innerEncoder = PostboxEncoder()
|
||||
wallpaper.encode(innerEncoder)
|
||||
return innerEncoder.makeData()
|
||||
}
|
||||
|
||||
try container.encode(wallpapersData, forKey: "wallpapers")
|
||||
}
|
||||
}
|
||||
|
||||
public extension WallpapersState {
|
||||
static func update(transaction: AccountManagerModifier<TelegramAccountManagerTypes>, _ f: (WallpapersState) -> WallpapersState) {
|
||||
transaction.updateSharedData(SharedDataKeys.wallapersState, { current in
|
||||
let item = (transaction.getSharedData(SharedDataKeys.wallapersState) as? WallpapersState) ?? WallpapersState(wallpapers: [])
|
||||
return f(item)
|
||||
let item = (transaction.getSharedData(SharedDataKeys.wallapersState)?.get(WallpapersState.self)) ?? WallpapersState(wallpapers: [])
|
||||
return PreferencesEntry(f(item))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user