This commit is contained in:
Ali
2020-03-11 16:13:03 +05:30
parent 773ed45e7b
commit 6f0598a7ab
27 changed files with 477 additions and 324 deletions

View File

@@ -60,7 +60,7 @@ public struct GlobalNotificationSettingsSet: PostboxCoding, Equatable {
}
}
public struct GlobalNotificationSettings: PreferencesEntry, Equatable {
public struct GlobalNotificationSettings: PreferencesEntry, Equatable, PostboxGlobalNotificationSettings {
public var toBeSynchronized: GlobalNotificationSettingsSet?
public var remote: GlobalNotificationSettingsSet
@@ -74,6 +74,44 @@ public struct GlobalNotificationSettings: PreferencesEntry, Equatable {
}
}
public func defaultIncludePeer(peer: Peer) -> Bool {
let settings = self.effective
if peer is TelegramUser || peer is TelegramSecretChat {
return settings.privateChats.enabled
} else if peer is TelegramGroup {
return settings.groupChats.enabled
} else if let channel = peer as? TelegramChannel {
switch channel.info {
case .group:
return settings.groupChats.enabled
case .broadcast:
return settings.channels.enabled
}
} else {
return false
}
}
public func isEqualInDefaultPeerInclusion(other: PostboxGlobalNotificationSettings) -> Bool {
guard let other = other as? GlobalNotificationSettings else {
return false
}
let settings = self.effective
let otherSettings = other.effective
if settings.privateChats.enabled != otherSettings.privateChats.enabled {
return false
}
if settings.groupChats.enabled != otherSettings.groupChats.enabled {
return false
}
if settings.channels.enabled != otherSettings.channels.enabled {
return false
}
return true
}
public init(toBeSynchronized: GlobalNotificationSettingsSet?, remote: GlobalNotificationSettingsSet) {
self.toBeSynchronized = toBeSynchronized
self.remote = remote

View File

@@ -46,7 +46,7 @@ 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]))
}, 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)
}()
public func accountTransaction<T>(rootPath: String, id: AccountRecordId, encryptionParameters: ValueBoxEncryptionParameters, transaction: @escaping (Transaction) -> T) -> Signal<T, NoError> {

View File

@@ -145,14 +145,14 @@ public final class TelegramPeerNotificationSettings: PeerNotificationSettings, E
return TelegramPeerNotificationSettings(muteState: .unmuted, messageSound: .default, displayPreviews: .default)
}
public var isRemovedFromTotalUnreadCount: Bool {
public func isRemovedFromTotalUnreadCount(`default`: Bool) -> Bool {
switch self.muteState {
case .unmuted:
return false
case .muted:
return true
case .default:
return false
return `default`
}
}