mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Refactoring
This commit is contained in:
@@ -3,7 +3,7 @@ import Postbox
|
||||
import TelegramCore
|
||||
import SwiftSignalKit
|
||||
|
||||
public struct GeneratedMediaStoreSettings: PreferencesEntry, Equatable {
|
||||
public struct GeneratedMediaStoreSettings: Codable, Equatable {
|
||||
public let storeEditedPhotos: Bool
|
||||
public let storeCapturedMedia: Bool
|
||||
|
||||
@@ -16,22 +16,18 @@ public struct GeneratedMediaStoreSettings: PreferencesEntry, Equatable {
|
||||
self.storeCapturedMedia = storeCapturedMedia
|
||||
}
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
self.storeEditedPhotos = decoder.decodeInt32ForKey("eph", orElse: 0) != 0
|
||||
self.storeCapturedMedia = decoder.decodeInt32ForKey("cpm", orElse: 0) != 0
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.storeEditedPhotos = (try container.decode(Int32.self, forKey: "eph")) != 0
|
||||
self.storeCapturedMedia = (try container.decode(Int32.self, forKey: "cpm")) != 0
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
encoder.encodeInt32(self.storeEditedPhotos ? 1 : 0, forKey: "eph")
|
||||
encoder.encodeInt32(self.storeCapturedMedia ? 1 : 0, forKey: "cpm")
|
||||
}
|
||||
|
||||
public func isEqual(to: PreferencesEntry) -> Bool {
|
||||
if let to = to as? GeneratedMediaStoreSettings {
|
||||
return self == to
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode((self.storeEditedPhotos ? 1 : 0) as Int32, forKey: "eph")
|
||||
try container.encode((self.storeCapturedMedia ? 1 : 0) as Int32, forKey: "cpm")
|
||||
}
|
||||
|
||||
public static func ==(lhs: GeneratedMediaStoreSettings, rhs: GeneratedMediaStoreSettings) -> Bool {
|
||||
@@ -47,12 +43,12 @@ public func updateGeneratedMediaStoreSettingsInteractively(accountManager: Accou
|
||||
return accountManager.transaction { transaction -> Void in
|
||||
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.generatedMediaStoreSettings, { entry in
|
||||
let currentSettings: GeneratedMediaStoreSettings
|
||||
if let entry = entry as? GeneratedMediaStoreSettings {
|
||||
if let entry = entry?.get(GeneratedMediaStoreSettings.self) {
|
||||
currentSettings = entry
|
||||
} else {
|
||||
currentSettings = GeneratedMediaStoreSettings.defaultSettings
|
||||
}
|
||||
return f(currentSettings)
|
||||
return PreferencesEntry(f(currentSettings))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user