mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-28 19:05:49 +00:00
no message
This commit is contained in:
parent
33b2a2e0da
commit
bf311fed75
@ -7,6 +7,31 @@ import Foundation
|
||||
import SwiftSignalKit
|
||||
#endif
|
||||
|
||||
public func togglePeerMuted(account: Account, peerId: PeerId) -> Signal<Void, NoError> {
|
||||
return account.postbox.modify { modifier -> Signal<Void, NoError> 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<Void, NoError> {
|
||||
return account.postbox.loadedPeerWithId(peerId)
|
||||
|> mapToSignal { peer -> Signal<Void, NoError> in
|
||||
|
||||
@ -13,7 +13,12 @@ public func removePeerChat(postbox: Postbox, peerId: PeerId) -> Signal<Void, NoE
|
||||
|
||||
} else {
|
||||
cloudChatAddRemoveChatOperation(modifier: modifier, peerId: peerId)
|
||||
if peerId.namespace == Namespaces.Peer.CloudUser {
|
||||
modifier.updatePeerChatListInclusion(peerId, inclusion: .ifHasMessages)
|
||||
modifier.clearHistory(peerId)
|
||||
} else {
|
||||
modifier.updatePeerChatListInclusion(peerId, inclusion: .never)
|
||||
}
|
||||
}
|
||||
modifier.updatePeerChatListInclusion(peerId, inclusion: .never)
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,6 +152,14 @@ public final class TelegramPeerNotificationSettings: PeerNotificationSettings, E
|
||||
}
|
||||
}
|
||||
|
||||
public func withUpdatedMuteState(_ muteState: PeerMuteState) -> 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
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user