This commit is contained in:
Ali
2021-09-03 00:45:22 +04:00
parent 8aefa19d31
commit 1fe0d4a75b
53 changed files with 489 additions and 566 deletions

View File

@@ -1,6 +1,6 @@
import Postbox
public struct AppChangelogState: PreferencesEntry, Equatable {
public struct AppChangelogState: Codable {
public var checkedVersion: String
public var previousVersion: String
@@ -11,21 +11,17 @@ public struct AppChangelogState: PreferencesEntry, Equatable {
self.previousVersion = previousVersion
}
public init(decoder: PostboxDecoder) {
self.checkedVersion = decoder.decodeStringForKey("checkedVersion", orElse: "")
self.previousVersion = decoder.decodeStringForKey("previousVersion", orElse: "")
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
self.checkedVersion = (try? container.decode(String.self, forKey: "checkedVersion")) ?? ""
self.previousVersion = (try? container.decode(String.self, forKey: "previousVersion")) ?? ""
}
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeString(self.checkedVersion, forKey: "checkedVersion")
encoder.encodeString(self.previousVersion, forKey: "previousVersion")
}
public func isEqual(to: PreferencesEntry) -> Bool {
guard let to = to as? AppChangelogState else {
return false
}
return self == to
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: StringCodingKey.self)
try container.encode(self.checkedVersion, forKey: "checkedVersion")
try container.encode(self.previousVersion, forKey: "previousVersion")
}
}

View File

@@ -1,7 +1,7 @@
import Foundation
import Postbox
public struct AppConfiguration: PreferencesEntry, Equatable {
public struct AppConfiguration: Codable {
public var data: JSON?
public static var defaultValue: AppConfiguration {
@@ -23,11 +23,4 @@ public struct AppConfiguration: PreferencesEntry, Equatable {
encoder.encodeNil(forKey: "data")
}
}
public func isEqual(to: PreferencesEntry) -> Bool {
guard let to = to as? AppConfiguration else {
return false
}
return self == to
}
}

View File

@@ -6,7 +6,7 @@ public enum AutodownloadPreset {
case high
}
public struct AutodownloadPresetSettings: PostboxCoding, Equatable {
public struct AutodownloadPresetSettings: Codable {
public let disabled: Bool
public let photoSizeMax: Int32
public let videoSizeMax: Int32
@@ -25,28 +25,32 @@ public struct AutodownloadPresetSettings: PostboxCoding, Equatable {
self.videoUploadMaxbitrate = videoUploadMaxbitrate
}
public init(decoder: PostboxDecoder) {
self.disabled = decoder.decodeInt32ForKey("disabled", orElse: 0) != 0
self.photoSizeMax = decoder.decodeInt32ForKey("photoSizeMax", orElse: 0)
self.videoSizeMax = decoder.decodeInt32ForKey("videoSizeMax", orElse: 0)
self.fileSizeMax = decoder.decodeInt32ForKey("fileSizeMax", orElse: 0)
self.preloadLargeVideo = decoder.decodeInt32ForKey("preloadLargeVideo", orElse: 0) != 0
self.lessDataForPhoneCalls = decoder.decodeInt32ForKey("lessDataForPhoneCalls", orElse: 0) != 0
self.videoUploadMaxbitrate = decoder.decodeInt32ForKey("videoUploadMaxbitrate", orElse: 0)
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
self.disabled = ((try? container.decode(Int32.self, forKey: "disabled")) ?? 0) != 0
self.photoSizeMax = (try? container.decode(Int32.self, forKey: "photoSizeMax")) ?? 0
self.videoSizeMax = (try? container.decode(Int32.self, forKey: "videoSizeMax")) ?? 0
self.fileSizeMax = (try? container.decode(Int32.self, forKey: "fileSizeMax")) ?? 0
self.preloadLargeVideo = ((try? container.decode(Int32.self, forKey: "preloadLargeVideo")) ?? 0) != 0
self.lessDataForPhoneCalls = ((try? container.decode(Int32.self, forKey: "lessDataForPhoneCalls")) ?? 0) != 0
self.videoUploadMaxbitrate = (try? container.decode(Int32.self, forKey: "videoUploadMaxbitrate")) ?? 0
}
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.disabled ? 1 : 0, forKey: "disabled")
encoder.encodeInt32(self.photoSizeMax, forKey: "photoSizeMax")
encoder.encodeInt32(self.videoSizeMax, forKey: "videoSizeMax")
encoder.encodeInt32(self.fileSizeMax, forKey: "fileSizeMax")
encoder.encodeInt32(self.preloadLargeVideo ? 1 : 0, forKey: "preloadLargeVideo")
encoder.encodeInt32(self.lessDataForPhoneCalls ? 1 : 0, forKey: "lessDataForPhoneCalls")
encoder.encodeInt32(self.videoUploadMaxbitrate, forKey: "videoUploadMaxbitrate")
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: StringCodingKey.self)
try container.encode((self.disabled ? 1 : 0) as Int32, forKey: "disabled")
try container.encode(self.photoSizeMax, forKey: "photoSizeMax")
try container.encode(self.videoSizeMax, forKey: "videoSizeMax")
try container.encode(self.fileSizeMax, forKey: "fileSizeMax")
try container.encode((self.preloadLargeVideo ? 1 : 0) as Int32, forKey: "preloadLargeVideo")
try container.encode((self.lessDataForPhoneCalls ? 1 : 0) as Int32, forKey: "lessDataForPhoneCalls")
try container.encode(self.videoUploadMaxbitrate, forKey: "videoUploadMaxbitrate")
}
}
public struct AutodownloadSettings: PreferencesEntry, Equatable {
public struct AutodownloadSettings: Codable {
public let lowPreset: AutodownloadPresetSettings
public let mediumPreset: AutodownloadPresetSettings
public let highPreset: AutodownloadPresetSettings
@@ -64,27 +68,19 @@ public struct AutodownloadSettings: PreferencesEntry, Equatable {
self.highPreset = highPreset
}
public init(decoder: PostboxDecoder) {
self.lowPreset = decoder.decodeObjectForKey("lowPreset", decoder: AutodownloadPresetSettings.init(decoder:)) as! AutodownloadPresetSettings
self.mediumPreset = decoder.decodeObjectForKey("mediumPreset", decoder: AutodownloadPresetSettings.init(decoder:)) as! AutodownloadPresetSettings
self.highPreset = decoder.decodeObjectForKey("highPreset", decoder: AutodownloadPresetSettings.init(decoder:)) as! AutodownloadPresetSettings
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
self.lowPreset = (try? container.decode(AutodownloadPresetSettings.self, forKey: "lowPreset")) ?? AutodownloadSettings.defaultSettings.lowPreset
self.mediumPreset = (try? container.decode(AutodownloadPresetSettings.self, forKey: "mediumPreset")) ?? AutodownloadSettings.defaultSettings.mediumPreset
self.highPreset = (try? container.decode(AutodownloadPresetSettings.self, forKey: "highPreset")) ?? AutodownloadSettings.defaultSettings.highPreset
}
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.lowPreset, forKey: "lowPreset")
encoder.encodeObject(self.mediumPreset, forKey: "mediumPreset")
encoder.encodeObject(self.highPreset, forKey: "highPreset")
}
public func isEqual(to: PreferencesEntry) -> Bool {
if let to = to as? AutodownloadSettings {
return self == to
} else {
return false
}
}
public static func ==(lhs: AutodownloadSettings, rhs: AutodownloadSettings) -> Bool {
return lhs.lowPreset == rhs.lowPreset && lhs.mediumPreset == rhs.mediumPreset && lhs.highPreset == rhs.highPreset
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: StringCodingKey.self)
try container.encode(self.lowPreset, forKey: "lowPreset")
try container.encode(self.mediumPreset, forKey: "mediumPreset")
try container.encode(self.highPreset, forKey: "highPreset")
}
}

View File

@@ -1,6 +1,6 @@
import Postbox
public struct CacheStorageSettings: PreferencesEntry, Equatable {
public struct CacheStorageSettings: Codable {
public let defaultCacheStorageTimeout: Int32
public let defaultCacheStorageLimitGigabytes: Int32
@@ -13,26 +13,18 @@ public struct CacheStorageSettings: PreferencesEntry, Equatable {
self.defaultCacheStorageLimitGigabytes = defaultCacheStorageLimitGigabytes
}
public init(decoder: PostboxDecoder) {
self.defaultCacheStorageTimeout = decoder.decodeInt32ForKey("dt", orElse: Int32.max)
self.defaultCacheStorageLimitGigabytes = decoder.decodeInt32ForKey("dl", orElse: Int32.max)
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
self.defaultCacheStorageTimeout = (try? container.decode(Int32.self, forKey: "dt")) ?? Int32.max
self.defaultCacheStorageLimitGigabytes = (try? container.decode(Int32.self, forKey: "dl")) ?? Int32.max
}
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.defaultCacheStorageTimeout, forKey: "dt")
encoder.encodeInt32(self.defaultCacheStorageLimitGigabytes, forKey: "dl")
}
public func isEqual(to: PreferencesEntry) -> Bool {
if let to = to as? CacheStorageSettings {
return self == to
} else {
return false
}
}
public static func ==(lhs: CacheStorageSettings, rhs: CacheStorageSettings) -> Bool {
return lhs.defaultCacheStorageTimeout == rhs.defaultCacheStorageTimeout && lhs.defaultCacheStorageLimitGigabytes == rhs.defaultCacheStorageLimitGigabytes
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: StringCodingKey.self)
try container.encode(self.defaultCacheStorageTimeout, forKey: "dt")
try container.encode(self.defaultCacheStorageLimitGigabytes, forKey: "dl")
}
public func withUpdatedDefaultCacheStorageTimeout(_ defaultCacheStorageTimeout: Int32) -> CacheStorageSettings {

View File

@@ -1,7 +1,7 @@
import Foundation
import Postbox
public struct ContactsSettings: Equatable, PreferencesEntry {
public struct ContactsSettings: Codable {
public var synchronizeContacts: Bool
public static var defaultSettings: ContactsSettings {
@@ -12,19 +12,15 @@ public struct ContactsSettings: Equatable, PreferencesEntry {
self.synchronizeContacts = synchronizeContacts
}
public init(decoder: PostboxDecoder) {
self.synchronizeContacts = decoder.decodeInt32ForKey("synchronizeContacts", orElse: 0) != 0
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
self.synchronizeContacts = ((try? container.decode(Int32.self, forKey: "synchronizeContacts")) ?? 0) != 0
}
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.synchronizeContacts ? 1 : 0, forKey: "synchronizeContacts")
}
public func isEqual(to: PreferencesEntry) -> Bool {
if let to = to as? ContactsSettings {
return self == to
} else {
return false
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: StringCodingKey.self)
try container.encode((self.synchronizeContacts ? 1 : 0) as Int32, forKey: "synchronizeContacts")
}
}

View File

@@ -1,6 +1,6 @@
import Postbox
public final class ContentPrivacySettings: PreferencesEntry, Equatable {
public final class ContentPrivacySettings: Codable {
public let enableSecretChatWebpagePreviews: Bool?
public static var defaultSettings = ContentPrivacySettings(enableSecretChatWebpagePreviews: nil)
@@ -9,34 +9,27 @@ public final class ContentPrivacySettings: PreferencesEntry, Equatable {
self.enableSecretChatWebpagePreviews = enableSecretChatWebpagePreviews
}
public init(decoder: PostboxDecoder) {
self.enableSecretChatWebpagePreviews = decoder.decodeOptionalInt32ForKey("enableSecretChatWebpagePreviews").flatMap { $0 != 0 }
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
if let value = try? container.decodeIfPresent(Int32.self, forKey: "enableSecretChatWebpagePreviews") {
self.enableSecretChatWebpagePreviews = value != 0
} else {
self.enableSecretChatWebpagePreviews = nil
}
}
public func encode(_ encoder: PostboxEncoder) {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: StringCodingKey.self)
if let enableSecretChatWebpagePreviews = self.enableSecretChatWebpagePreviews {
encoder.encodeInt32(enableSecretChatWebpagePreviews ? 1 : 0, forKey: "enableSecretChatWebpagePreviews")
try container.encode((enableSecretChatWebpagePreviews ? 1 : 0) as Int32, forKey: "enableSecretChatWebpagePreviews")
} else {
encoder.encodeNil(forKey: "enableSecretChatWebpagePreviews")
try container.encodeNil(forKey: "enableSecretChatWebpagePreviews")
}
}
public func withUpdatedEnableSecretChatWebpagePreviews(_ enableSecretChatWebpagePreviews: Bool) -> ContentPrivacySettings {
return ContentPrivacySettings(enableSecretChatWebpagePreviews: enableSecretChatWebpagePreviews)
}
public func isEqual(to: PreferencesEntry) -> Bool {
guard let to = to as? ContentPrivacySettings else {
return false
}
return self == to
}
public static func ==(lhs: ContentPrivacySettings, rhs: ContentPrivacySettings) -> Bool {
if lhs.enableSecretChatWebpagePreviews != rhs.enableSecretChatWebpagePreviews {
return false
}
return true
}
}
}

View File

@@ -1,6 +1,6 @@
import Postbox
public struct MessageNotificationSettings: PostboxCoding, Equatable {
public struct MessageNotificationSettings: Codable {
public var enabled: Bool
public var displayPreviews: Bool
public var sound: PeerMessageSound
@@ -15,10 +15,13 @@ public struct MessageNotificationSettings: PostboxCoding, Equatable {
self.sound = sound
}
public init(decoder: PostboxDecoder) {
self.enabled = decoder.decodeInt32ForKey("e", orElse: 0) != 0
self.displayPreviews = decoder.decodeInt32ForKey("p", orElse: 0) != 0
self.sound = PeerMessageSound.decodeInline(decoder)
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
self.enabled = ((try? container.decode(Int32.self, forKey: "e")) ?? 0) != 0
self.displayPreviews = ((try? container.decode(Int32.self, forKey: "p")) ?? 0) != 0
self.sound = PeerMessageSound.decodeInline(container)
}
public func encode(_ encoder: PostboxEncoder) {
@@ -28,7 +31,7 @@ public struct MessageNotificationSettings: PostboxCoding, Equatable {
}
}
public struct GlobalNotificationSettingsSet: PostboxCoding, Equatable {
public struct GlobalNotificationSettingsSet: Codable {
public var privateChats: MessageNotificationSettings
public var groupChats: MessageNotificationSettings
public var channels: MessageNotificationSettings
@@ -45,7 +48,9 @@ public struct GlobalNotificationSettingsSet: PostboxCoding, Equatable {
self.contactsJoined = contactsJoined
}
public init(decoder: PostboxDecoder) {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
self.privateChats = decoder.decodeObjectForKey("p", decoder: { MessageNotificationSettings(decoder: $0) }) as! MessageNotificationSettings
self.groupChats = decoder.decodeObjectForKey("g", decoder: { MessageNotificationSettings(decoder: $0) }) as! MessageNotificationSettings
self.channels = (decoder.decodeObjectForKey("c", decoder: { MessageNotificationSettings(decoder: $0) }) as? MessageNotificationSettings) ?? MessageNotificationSettings.defaultSettings
@@ -60,7 +65,7 @@ public struct GlobalNotificationSettingsSet: PostboxCoding, Equatable {
}
}
public struct GlobalNotificationSettings: PreferencesEntry, Equatable, PostboxGlobalNotificationSettings {
public struct GlobalNotificationSettings: Codable {
public var toBeSynchronized: GlobalNotificationSettingsSet?
public var remote: GlobalNotificationSettingsSet
@@ -73,8 +78,16 @@ public struct GlobalNotificationSettings: PreferencesEntry, Equatable, PostboxGl
return self.remote
}
}
public var postboxAccessor: PostboxGlobalNotificationSettings {
return PostboxGlobalNotificationSettings(
defaultIncludePeer: { peer in
return self.defaultIncludePeer(peer: peer)
}
)
}
public func defaultIncludePeer(peer: Peer) -> Bool {
private func defaultIncludePeer(peer: Peer) -> Bool {
let settings = self.effective
if peer is TelegramUser || peer is TelegramSecretChat {
return settings.privateChats.enabled
@@ -92,7 +105,7 @@ public struct GlobalNotificationSettings: PreferencesEntry, Equatable, PostboxGl
}
}
public func isEqualInDefaultPeerInclusion(other: PostboxGlobalNotificationSettings) -> Bool {
/*public func isEqualInDefaultPeerInclusion(other: PostboxGlobalNotificationSettings) -> Bool {
guard let other = other as? GlobalNotificationSettings else {
return false
}
@@ -110,19 +123,21 @@ public struct GlobalNotificationSettings: PreferencesEntry, Equatable, PostboxGl
}
return true
}
}*/
public init(toBeSynchronized: GlobalNotificationSettingsSet?, remote: GlobalNotificationSettingsSet) {
self.toBeSynchronized = toBeSynchronized
self.remote = remote
}
public init(decoder: PostboxDecoder) {
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
self.toBeSynchronized = decoder.decodeObjectForKey("s", decoder: { GlobalNotificationSettingsSet(decoder: $0) }) as? GlobalNotificationSettingsSet
self.remote = decoder.decodeObjectForKey("r", decoder: { GlobalNotificationSettingsSet(decoder: $0) }) as! GlobalNotificationSettingsSet
}
public func encode(_ encoder: PostboxEncoder) {
public func encode(to encoder: Encoder) throws {
if let toBeSynchronized = self.toBeSynchronized {
encoder.encodeObject(toBeSynchronized, forKey: "s")
} else {
@@ -130,12 +145,4 @@ public struct GlobalNotificationSettings: PreferencesEntry, Equatable, PostboxGl
}
encoder.encodeObject(self.remote, forKey: "r")
}
public func isEqual(to: PreferencesEntry) -> Bool {
if let to = to as? GlobalNotificationSettings {
return self == to
} else {
return false
}
}
}

View File

@@ -62,7 +62,9 @@ public let telegramPostboxSeedConfiguration: SeedConfiguration = {
assertionFailure()
return .nonContact
}
}, additionalChatListIndexNamespace: Namespaces.Message.Cloud, messageNamespacesRequiringGroupStatsValidation: [Namespaces.Message.Cloud], defaultMessageNamespaceReadStates: [Namespaces.Message.Local: .idBased(maxIncomingReadId: 0, maxOutgoingReadId: 0, maxKnownId: 0, count: 0, markedUnread: false)], chatMessagesNamespaces: Set([Namespaces.Message.Cloud, Namespaces.Message.Local, Namespaces.Message.SecretIncoming]), globalNotificationSettingsPreferencesKey: PreferencesKeys.globalNotifications, defaultGlobalNotificationSettings: GlobalNotificationSettings.defaultSettings)
}, additionalChatListIndexNamespace: Namespaces.Message.Cloud, messageNamespacesRequiringGroupStatsValidation: [Namespaces.Message.Cloud], defaultMessageNamespaceReadStates: [Namespaces.Message.Local: .idBased(maxIncomingReadId: 0, maxOutgoingReadId: 0, maxKnownId: 0, count: 0, markedUnread: false)], chatMessagesNamespaces: Set([Namespaces.Message.Cloud, Namespaces.Message.Local, Namespaces.Message.SecretIncoming]), globalNotificationSettingsPreferencesKey: { transaction in
return transaction.getPreferencesEntry(PreferencesKeys.globalNotifications)?.get(GlobalNotificationSettings.self)
}, defaultGlobalNotificationSettings: GlobalNotificationSettings.defaultSettings)
}()
public enum AccountTransactionError {

View File

@@ -44,14 +44,14 @@ public enum PeerMessageSound: Equatable {
case bundledModern(id: Int32)
case bundledClassic(id: Int32)
static func decodeInline(_ decoder: PostboxDecoder) -> PeerMessageSound {
switch decoder.decodeInt32ForKey("s.v", orElse: 0) {
static func decodeInline(_ container: KeyedDecodingContainer<StringCodingKey>) throws -> PeerMessageSound {
switch try container.decode(Int32.self, forKey: "s.v") {
case PeerMessageSoundValue.none.rawValue:
return .none
case PeerMessageSoundValue.bundledModern.rawValue:
return .bundledModern(id: decoder.decodeInt32ForKey("s.i", orElse: 0))
return .bundledModern(id: (try? container.decode(Int32.self, forKey: "s.i")) ?? 0)
case PeerMessageSoundValue.bundledClassic.rawValue:
return .bundledClassic(id: decoder.decodeInt32ForKey("s.i", orElse: 0))
return .bundledClassic(id: (try? container.decode(Int32.self, forKey: "s.i")) ?? 0)
case PeerMessageSoundValue.default.rawValue:
return .default
default:
@@ -170,7 +170,7 @@ public final class TelegramPeerNotificationSettings: PeerNotificationSettings, E
self.displayPreviews = displayPreviews
}
public init(decoder: PostboxDecoder) {
public init() {
self.muteState = PeerMuteState.decodeInline(decoder)
self.messageSound = PeerMessageSound.decodeInline(decoder)
self.displayPreviews = PeerNotificationDisplayPreviews.decodeInline(decoder)