Refactoring

This commit is contained in:
Ali
2021-09-07 13:09:06 +04:00
parent f0f02dc4b9
commit 1141e09c1b
257 changed files with 1894 additions and 1720 deletions

View File

@@ -9,7 +9,7 @@ public enum EmojiStickerSuggestionMode: Int32 {
case installed
}
public struct StickerSettings: PreferencesEntry, Equatable {
public struct StickerSettings: Codable, Equatable {
public var emojiStickerSuggestionMode: EmojiStickerSuggestionMode
public var loopAnimatedStickers: Bool
@@ -22,22 +22,18 @@ public struct StickerSettings: PreferencesEntry, Equatable {
self.loopAnimatedStickers = loopAnimatedStickers
}
public init(decoder: PostboxDecoder) {
self.emojiStickerSuggestionMode = EmojiStickerSuggestionMode(rawValue: decoder.decodeInt32ForKey("emojiStickerSuggestionMode", orElse: 0))!
self.loopAnimatedStickers = decoder.decodeBoolForKey("loopAnimatedStickers", orElse: true)
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: StringCodingKey.self)
self.emojiStickerSuggestionMode = EmojiStickerSuggestionMode(rawValue: try container.decode(Int32.self, forKey: "emojiStickerSuggestionMode"))!
self.loopAnimatedStickers = try container.decodeIfPresent(Bool.self, forKey: "loopAnimatedStickers") ?? true
}
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.emojiStickerSuggestionMode.rawValue, forKey: "emojiStickerSuggestionMode")
encoder.encodeBool(self.loopAnimatedStickers, forKey: "loopAnimatedStickers")
}
public func isEqual(to: PreferencesEntry) -> Bool {
if let to = to as? StickerSettings {
return self == to
} else {
return false
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: StringCodingKey.self)
try container.encode(self.emojiStickerSuggestionMode.rawValue, forKey: "emojiStickerSuggestionMode")
try container.encode(self.loopAnimatedStickers, forKey: "loopAnimatedStickers")
}
public static func ==(lhs: StickerSettings, rhs: StickerSettings) -> Bool {
@@ -57,12 +53,12 @@ public func updateStickerSettingsInteractively(accountManager: AccountManager<Te
return accountManager.transaction { transaction -> Void in
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.stickerSettings, { entry in
let currentSettings: StickerSettings
if let entry = entry as? StickerSettings {
if let entry = entry?.get(StickerSettings.self) {
currentSettings = entry
} else {
currentSettings = StickerSettings.defaultSettings
}
return f(currentSettings)
return PreferencesEntry(f(currentSettings))
})
}
}