From bf311fed756377f7bb36f2ec2c0713a4c5e172ef Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 31 Jan 2017 15:14:48 +0300 Subject: [PATCH] no message --- .../ChangePeerNotificationSettings.swift | 25 +++++++++++++++++ TelegramCore/RemovePeerChat.swift | 7 ++++- .../TelegramPeerNotificationSettings.swift | 8 ++++++ TelegramCore/UpdatePeers.swift | 28 +++++++++++-------- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/TelegramCore/ChangePeerNotificationSettings.swift b/TelegramCore/ChangePeerNotificationSettings.swift index e0cb922895..dc2445316e 100644 --- a/TelegramCore/ChangePeerNotificationSettings.swift +++ b/TelegramCore/ChangePeerNotificationSettings.swift @@ -7,6 +7,31 @@ import Foundation import SwiftSignalKit #endif +public func togglePeerMuted(account: Account, peerId: PeerId) -> Signal { + return account.postbox.modify { modifier -> Signal in + if let peer = modifier.getPeer(peerId), let inputPeer = apiInputPeer(peer) { + let currentSettings = modifier.getPeerNotificationSettings(peerId) as? TelegramPeerNotificationSettings + let previousSettings: TelegramPeerNotificationSettings + if let currentSettings = currentSettings { + previousSettings = currentSettings + } else { + previousSettings = TelegramPeerNotificationSettings.defaultSettings + } + + let updatedSettings: TelegramPeerNotificationSettings + switch previousSettings.muteState { + case .unmuted: + updatedSettings = previousSettings.withUpdatedMuteState(.muted(until: Int32.max)) + case .muted: + updatedSettings = previousSettings.withUpdatedMuteState(.unmuted) + } + return changePeerNotificationSettings(account: account, peerId: peerId, settings: updatedSettings) + } else { + return .complete() + } + } |> switchToLatest +} + public func changePeerNotificationSettings(account: Account, peerId: PeerId, settings: TelegramPeerNotificationSettings) -> Signal { return account.postbox.loadedPeerWithId(peerId) |> mapToSignal { peer -> Signal in diff --git a/TelegramCore/RemovePeerChat.swift b/TelegramCore/RemovePeerChat.swift index 88eb8aed4f..f3e8868fdb 100644 --- a/TelegramCore/RemovePeerChat.swift +++ b/TelegramCore/RemovePeerChat.swift @@ -13,7 +13,12 @@ public func removePeerChat(postbox: Postbox, peerId: PeerId) -> Signal TelegramPeerNotificationSettings { + return TelegramPeerNotificationSettings(muteState: muteState, messageSound: self.messageSound) + } + + public func withUpdatedMessageSound(_ messageSound: PeerMessageSound) -> TelegramPeerNotificationSettings { + return TelegramPeerNotificationSettings(muteState: self.muteState, messageSound: messageSound) + } + public static func ==(lhs: TelegramPeerNotificationSettings, rhs: TelegramPeerNotificationSettings) -> Bool { return lhs.muteState == rhs.muteState && lhs.messageSound == rhs.messageSound } diff --git a/TelegramCore/UpdatePeers.swift b/TelegramCore/UpdatePeers.swift index 5f2c810381..28c2eb52b7 100644 --- a/TelegramCore/UpdatePeers.swift +++ b/TelegramCore/UpdatePeers.swift @@ -18,19 +18,23 @@ public func updatePeers(modifier: Modifier, peers: [Peer], update: (Peer?, Peer) } case Namespaces.Peer.CloudGroup: if let group = updated as? TelegramGroup { - switch group.membership { - case .Member: - if group.creationDate != 0 { - updatedInclusion = currentInclusion.withSetIfHasMessagesOrMaxMinTimestamp(group.creationDate) - } else { - if currentInclusion == .notSpecified { - updatedInclusion = .ifHasMessages + if group.flags.contains(.deactivated) { + updatedInclusion = .never + } else { + switch group.membership { + case .Member: + if group.creationDate != 0 { + updatedInclusion = currentInclusion.withSetIfHasMessagesOrMaxMinTimestamp(group.creationDate) + } else { + if currentInclusion == .notSpecified { + updatedInclusion = .ifHasMessages + } } - } - default: - if currentInclusion == .notSpecified { - updatedInclusion = .never - } + default: + if currentInclusion == .notSpecified { + updatedInclusion = .never + } + } } } else { assertionFailure()