mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
[WIP] Topics
This commit is contained in:
@@ -68,11 +68,7 @@ public let telegramPostboxSeedConfiguration: SeedConfiguration = {
|
||||
if channel.flags.contains(.isForum) {
|
||||
return []
|
||||
}
|
||||
if channel.username != nil {
|
||||
return .group
|
||||
} else {
|
||||
return .group
|
||||
}
|
||||
return .group
|
||||
}
|
||||
} else {
|
||||
assertionFailure()
|
||||
|
||||
@@ -73,11 +73,41 @@ public func getCloudLegacySound(id: Int64) -> (id: Int32, category: CloudSoundBu
|
||||
return nil
|
||||
}
|
||||
|
||||
public enum PeerMuteState: Equatable {
|
||||
public enum PeerMuteState: Codable, Equatable {
|
||||
case `default`
|
||||
case unmuted
|
||||
case muted(until: Int32)
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
switch try container.decode(Int32.self, forKey: "m.v") {
|
||||
case 0:
|
||||
self = .default
|
||||
case 1:
|
||||
self = .muted(until: try container.decode(Int32.self, forKey: "m.u"))
|
||||
case 2:
|
||||
self = .unmuted
|
||||
default:
|
||||
assertionFailure()
|
||||
self = .default
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
switch self {
|
||||
case .default:
|
||||
try container.encode(0 as Int32, forKey: "m.v")
|
||||
case let .muted(until):
|
||||
try container.encode(1 as Int32, forKey: "m.v")
|
||||
try container.encode(until, forKey: "m.u")
|
||||
case .unmuted:
|
||||
try container.encode(2 as Int32, forKey: "m.v")
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate static func decodeInline(_ decoder: PostboxDecoder) -> PeerMuteState {
|
||||
switch decoder.decodeInt32ForKey("m.v", orElse: 0) {
|
||||
case 0:
|
||||
@@ -104,15 +134,15 @@ public enum PeerMuteState: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
private enum PeerMessageSoundValue: Int32 {
|
||||
case none
|
||||
case bundledModern
|
||||
case bundledClassic
|
||||
case `default`
|
||||
case cloud
|
||||
private enum PeerMessageSoundValue: Int32, Codable {
|
||||
case none = 0
|
||||
case bundledModern = 1
|
||||
case bundledClassic = 2
|
||||
case `default` = 3
|
||||
case cloud = 4
|
||||
}
|
||||
|
||||
public enum PeerMessageSound: Equatable {
|
||||
public enum PeerMessageSound: Equatable, Codable {
|
||||
public enum Id: Hashable {
|
||||
case none
|
||||
case `default`
|
||||
@@ -142,6 +172,30 @@ public enum PeerMessageSound: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
switch try container.decode(Int32.self, forKey: "s.v") {
|
||||
case PeerMessageSoundValue.none.rawValue:
|
||||
self = .none
|
||||
case PeerMessageSoundValue.bundledModern.rawValue:
|
||||
self = .cloud(fileId: getCloudSoundOrDefault(id: (try? container.decode(Int32.self, forKey: "s.i")) ?? 0, isModern: true))
|
||||
case PeerMessageSoundValue.bundledClassic.rawValue:
|
||||
self = .cloud(fileId: getCloudSoundOrDefault(id: (try? container.decode(Int32.self, forKey: "s.i")) ?? 0, isModern: false))
|
||||
case PeerMessageSoundValue.default.rawValue:
|
||||
self = .default
|
||||
case PeerMessageSoundValue.cloud.rawValue:
|
||||
do {
|
||||
self = .cloud(fileId: try container.decode(Int64.self, forKey: "s.cloud.fileId"))
|
||||
} catch {
|
||||
self = .default
|
||||
}
|
||||
default:
|
||||
assertionFailure()
|
||||
self = defaultCloudPeerNotificationSound
|
||||
}
|
||||
}
|
||||
|
||||
static func decodeInline(_ container: KeyedDecodingContainer<StringCodingKey>) throws -> PeerMessageSound {
|
||||
switch try container.decode(Int32.self, forKey: "s.v") {
|
||||
case PeerMessageSoundValue.none.rawValue:
|
||||
@@ -181,6 +235,26 @@ public enum PeerMessageSound: Equatable {
|
||||
return defaultCloudPeerNotificationSound
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
switch self {
|
||||
case .none:
|
||||
try container.encode(PeerMessageSoundValue.none.rawValue, forKey: "s.v")
|
||||
case let .bundledModern(id):
|
||||
try container.encode(PeerMessageSoundValue.bundledModern.rawValue, forKey: "s.v")
|
||||
try container.encode(id, forKey: "s.i")
|
||||
case let .bundledClassic(id):
|
||||
try container.encode(PeerMessageSoundValue.bundledClassic.rawValue, forKey: "s.v")
|
||||
try container.encode(id, forKey: "s.i")
|
||||
case let .cloud(fileId):
|
||||
try container.encode(PeerMessageSoundValue.cloud.rawValue, forKey: "s.v")
|
||||
try container.encode(fileId, forKey: "s.cloud.fileId")
|
||||
case .default:
|
||||
try container.encode(PeerMessageSoundValue.default.rawValue, forKey: "s.v")
|
||||
}
|
||||
}
|
||||
|
||||
func encodeInline(_ container: inout KeyedEncodingContainer<StringCodingKey>) throws {
|
||||
switch self {
|
||||
@@ -254,11 +328,40 @@ public enum PeerMessageSound: Equatable {
|
||||
}
|
||||
}
|
||||
|
||||
public enum PeerNotificationDisplayPreviews {
|
||||
public enum PeerNotificationDisplayPreviews: Equatable, Codable {
|
||||
case `default`
|
||||
case show
|
||||
case hide
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
switch try container.decode(Int32.self, forKey: "p.v") {
|
||||
case 0:
|
||||
self = .default
|
||||
case 1:
|
||||
self = .show
|
||||
case 2:
|
||||
self = .hide
|
||||
default:
|
||||
assertionFailure()
|
||||
self = .default
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
switch self {
|
||||
case .default:
|
||||
try container.encode(0 as Int32, forKey: "p.v")
|
||||
case .show:
|
||||
try container.encode(1 as Int32, forKey: "p.v")
|
||||
case .hide:
|
||||
try container.encode(2 as Int32, forKey: "p.v")
|
||||
}
|
||||
}
|
||||
|
||||
static func decodeInline(_ decoder: PostboxDecoder) -> PeerNotificationDisplayPreviews {
|
||||
switch decoder.decodeInt32ForKey("p.v", orElse: 0) {
|
||||
case 0:
|
||||
@@ -285,7 +388,7 @@ public enum PeerNotificationDisplayPreviews {
|
||||
}
|
||||
}
|
||||
|
||||
public final class TelegramPeerNotificationSettings: PeerNotificationSettings, Equatable {
|
||||
public final class TelegramPeerNotificationSettings: PeerNotificationSettings, Codable, Equatable {
|
||||
public let muteState: PeerMuteState
|
||||
public let messageSound: PeerMessageSound
|
||||
public let displayPreviews: PeerNotificationDisplayPreviews
|
||||
@@ -325,6 +428,22 @@ public final class TelegramPeerNotificationSettings: PeerNotificationSettings, E
|
||||
self.displayPreviews = PeerNotificationDisplayPreviews.decodeInline(decoder)
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
self.muteState = try container.decode(PeerMuteState.self, forKey: "muteState")
|
||||
self.messageSound = try container.decode(PeerMessageSound.self, forKey: "messageSound")
|
||||
self.displayPreviews = try container.decode(PeerNotificationDisplayPreviews.self, forKey: "displayPreviews")
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: StringCodingKey.self)
|
||||
|
||||
try container.encode(self.muteState, forKey: "muteState")
|
||||
try container.encode(self.messageSound, forKey: "messageSound")
|
||||
try container.encode(self.displayPreviews, forKey: "displayPreviews")
|
||||
}
|
||||
|
||||
public func encode(_ encoder: PostboxEncoder) {
|
||||
self.muteState.encodeInline(encoder)
|
||||
self.messageSound.encodeInline(encoder)
|
||||
|
||||
Reference in New Issue
Block a user