mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
refactor and cleanup [skip ci]
This commit is contained in:
40
submodules/Postbox/Sources/PeerNotificationSettings.swift
Normal file
40
submodules/Postbox/Sources/PeerNotificationSettings.swift
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
public enum PeerNotificationSettingsBehavior: PostboxCoding {
|
||||
case none
|
||||
case reset(atTimestamp: Int32, toValue: PeerNotificationSettings)
|
||||
|
||||
public init(decoder: PostboxDecoder) {
|
||||
switch decoder.decodeInt32ForKey("_v", orElse: 0) {
|
||||
case 0:
|
||||
self = .none
|
||||
case 1:
|
||||
if let toValue = decoder.decodeObjectForKey("toValue") as? PeerNotificationSettings {
|
||||
self = .reset(atTimestamp: decoder.decodeInt32ForKey("atTimestamp", orElse: 0), toValue: toValue)
|
||||
} else {
|
||||
assertionFailure()
|
||||
self = .none
|
||||
}
|
||||
default:
|
||||
assertionFailure()
|
||||
self = .none
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
switch self {
|
||||
case .none:
|
||||
encoder.encodeInt32(0, forKey: "_v")
|
||||
case let .reset(atTimestamp, toValue):
|
||||
encoder.encodeInt32(1, forKey: "_v")
|
||||
encoder.encodeInt32(atTimestamp, forKey: "atTimestamp")
|
||||
encoder.encodeObject(toValue, forKey: "toValue")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public protocol PeerNotificationSettings: PostboxCoding {
|
||||
var isRemovedFromTotalUnreadCount: Bool { get }
|
||||
var behavior: PeerNotificationSettingsBehavior { get }
|
||||
|
||||
func isEqual(to: PeerNotificationSettings) -> Bool
|
||||
}
|
||||
Reference in New Issue
Block a user