Use global notification settings in mute state resolution

This commit is contained in:
Ali
2020-03-12 15:29:35 +05:30
parent dd380e646b
commit 05c19409f6
19 changed files with 158 additions and 109 deletions

View File

@@ -2948,7 +2948,9 @@ func replayFinalState(accountManager: AccountManager, postbox: Postbox, accountP
let currentInclusion = transaction.getPeerChatListInclusion(peerId)
if let groupId = currentInclusion.groupId, groupId == Namespaces.PeerGroup.archive {
if let peer = transaction.getPeer(peerId) as? TelegramSecretChat {
if let notificationSettings = transaction.getPeerNotificationSettings(peer.regularPeerId) as? TelegramPeerNotificationSettings, !notificationSettings.isRemovedFromTotalUnreadCount(default: !transaction.getGlobalNotificationSettings().defaultIncludePeer(peer: peer)) {
let isRemovedFromTotalUnreadCount = resolvedIsRemovedFromTotalUnreadCount(globalSettings: transaction.getGlobalNotificationSettings(), peer: peer, peerSettings: transaction.getPeerNotificationSettings(peer.regularPeerId))
if !isRemovedFromTotalUnreadCount {
transaction.updatePeerChatListInclusion(peerId, inclusion: currentInclusion.withGroupId(groupId: .root))
}
}

View File

@@ -22,10 +22,17 @@ public func togglePeerMuted(account: Account, peerId: PeerId) -> Signal<Void, No
let updatedSettings: TelegramPeerNotificationSettings
switch previousSettings.muteState {
case .unmuted, .default:
case .default:
let globalNotificationSettings = transaction.getGlobalNotificationSettings()
if resolvedIsRemovedFromTotalUnreadCount(globalSettings: globalNotificationSettings, peer: peer, peerSettings: previousSettings) {
updatedSettings = previousSettings.withUpdatedMuteState(.unmuted)
} else {
updatedSettings = previousSettings.withUpdatedMuteState(.muted(until: Int32.max))
case .muted:
updatedSettings = previousSettings.withUpdatedMuteState(.default)
}
case .unmuted:
updatedSettings = previousSettings.withUpdatedMuteState(.muted(until: Int32.max))
case .muted:
updatedSettings = previousSettings.withUpdatedMuteState(.unmuted)
}
transaction.updatePendingPeerNotificationSettings(peerId: notificationPeerId, settings: updatedSettings)
}