From 08cf916a831ef2e34be64eeb51a2be43d68973c2 Mon Sep 17 00:00:00 2001 From: overtake <> Date: Wed, 21 Nov 2018 02:04:16 +0400 Subject: [PATCH] no message --- TelegramUI/ChannelInfoController.swift | 18 ++++++++--- TelegramUI/GroupInfoController.swift | 30 ++++++++++++------- .../NotificationExceptionControllerNode.swift | 4 +++ .../NotificationMuteSettingsController.swift | 20 ++++++++++--- TelegramUI/UserInfoController.swift | 19 +++++++++--- 5 files changed, 68 insertions(+), 23 deletions(-) diff --git a/TelegramUI/ChannelInfoController.swift b/TelegramUI/ChannelInfoController.swift index 85aaae8a3f..a067415c73 100644 --- a/TelegramUI/ChannelInfoController.swift +++ b/TelegramUI/ChannelInfoController.swift @@ -720,10 +720,20 @@ public func channelInfoController(account: Account, peerId: PeerId) -> ViewContr presentControllerImpl?(channelVisibilityController(account: account, peerId: peerId, mode: .generic), ViewControllerPresentationArguments(presentationAnimation: ViewControllerPresentationAnimation.modalSheet)) }, changeNotificationMuteSettings: { let presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 } - let controller = notificationMuteSettingsController(presentationData: presentationData, updateSettings: { value in - changeMuteSettingsDisposable.set(updatePeerMuteSetting(account: account, peerId: peerId, muteInterval: value).start()) - }) - presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) + actionsDisposable.add((account.postbox.preferencesView(keys: [PreferencesKeys.globalNotifications]) |> take(1) |> deliverOnMainQueue).start(next: { view in + + let viewSettings: GlobalNotificationSettingsSet + if let settings = view.values[PreferencesKeys.globalNotifications] as? GlobalNotificationSettings { + viewSettings = settings.effective + } else { + viewSettings = GlobalNotificationSettingsSet.defaultSettings + } + + let controller = notificationMuteSettingsController(presentationData: presentationData, notificationSettings: viewSettings.privateChats, updateSettings: { value in + changeMuteSettingsDisposable.set(updatePeerMuteSetting(account: account, peerId: peerId, muteInterval: value).start()) + }) + presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) + })) }, changeNotificationSoundSettings: { let _ = (account.postbox.transaction { transaction -> (TelegramPeerNotificationSettings, GlobalNotificationSettings) in let peerSettings: TelegramPeerNotificationSettings = (transaction.getPeerNotificationSettings(peerId) as? TelegramPeerNotificationSettings) ?? TelegramPeerNotificationSettings.defaultSettings diff --git a/TelegramUI/GroupInfoController.swift b/TelegramUI/GroupInfoController.swift index e481a3e4f5..d165bb9cca 100644 --- a/TelegramUI/GroupInfoController.swift +++ b/TelegramUI/GroupInfoController.swift @@ -769,13 +769,11 @@ private func groupInfoEntries(account: Account, presentationData: PresentationDa let peerNotificationSettings: TelegramPeerNotificationSettings = (view.notificationSettings as? TelegramPeerNotificationSettings) ?? TelegramPeerNotificationSettings.defaultSettings let notificationsText: String - switch peerNotificationSettings.muteState { - case .default: - notificationsText = presentationData.strings.UserInfo_NotificationsDefault - case .muted: - notificationsText = presentationData.strings.UserInfo_NotificationsDisabled - case .unmuted: - notificationsText = presentationData.strings.UserInfo_NotificationsEnabled + + if case .muted = peerNotificationSettings.muteState { + notificationsText = presentationData.strings.UserInfo_NotificationsDisabled + } else { + notificationsText = presentationData.strings.UserInfo_NotificationsEnabled } if let editingState = state.editingState { @@ -1281,10 +1279,20 @@ public func groupInfoController(account: Account, peerId: PeerId) -> ViewControl presentControllerImpl?(controller, presentationArguments) }, changeNotificationMuteSettings: { let presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 } - let controller = notificationMuteSettingsController(presentationData: presentationData, updateSettings: { value in - changeMuteSettingsDisposable.set(updatePeerMuteSetting(account: account, peerId: peerId, muteInterval: value).start()) - }) - presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) + actionsDisposable.add((account.postbox.preferencesView(keys: [PreferencesKeys.globalNotifications]) |> take(1) |> deliverOnMainQueue).start(next: { view in + + let viewSettings: GlobalNotificationSettingsSet + if let settings = view.values[PreferencesKeys.globalNotifications] as? GlobalNotificationSettings { + viewSettings = settings.effective + } else { + viewSettings = GlobalNotificationSettingsSet.defaultSettings + } + + let controller = notificationMuteSettingsController(presentationData: presentationData, notificationSettings: viewSettings.privateChats, updateSettings: { value in + changeMuteSettingsDisposable.set(updatePeerMuteSetting(account: account, peerId: peerId, muteInterval: value).start()) + }) + presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) + })) }, changeNotificationSoundSettings: { let _ = (account.postbox.transaction { transaction -> (TelegramPeerNotificationSettings, GlobalNotificationSettings) in let peerSettings: TelegramPeerNotificationSettings = (transaction.getPeerNotificationSettings(peerId) as? TelegramPeerNotificationSettings) ?? TelegramPeerNotificationSettings.defaultSettings diff --git a/TelegramUI/NotificationExceptionControllerNode.swift b/TelegramUI/NotificationExceptionControllerNode.swift index 3c6ef327a6..4d62c5b08c 100644 --- a/TelegramUI/NotificationExceptionControllerNode.swift +++ b/TelegramUI/NotificationExceptionControllerNode.swift @@ -290,6 +290,10 @@ private func notificationsExceptionEntries(presentationData: PresentationData, s let soundName = localizedPeerNotificationSoundString(strings: presentationData.strings, sound: value.settings.messageSound) title += (title.isEmpty ? presentationData.strings.Notification_Exceptions_Sound(soundName).0 : ", \(presentationData.strings.Notification_Exceptions_Sound(soundName).0)") } + if value.peer.displayTitle == "Vyezd Family" { + var bp:Int = 0 + bp += 1 + } entries.append(.peer(index: index, peer: value.peer, theme: presentationData.theme, strings: presentationData.strings, dateFormat: presentationData.dateTimeFormat, description: title, notificationSettings: value.settings, revealed: state.revealedPeerId == value.peer.id, editing: state.editing)) index += 1 } diff --git a/TelegramUI/NotificationMuteSettingsController.swift b/TelegramUI/NotificationMuteSettingsController.swift index 53e041046c..e550b61a2c 100644 --- a/TelegramUI/NotificationMuteSettingsController.swift +++ b/TelegramUI/NotificationMuteSettingsController.swift @@ -1,5 +1,7 @@ import Foundation import Display +import TelegramCore +import Postbox private enum NotificationMuteOption { case `default` @@ -8,7 +10,9 @@ private enum NotificationMuteOption { case disable } -func notificationMuteSettingsController(presentationData: PresentationData, updateSettings: @escaping (Int32?) -> Void) -> ViewController { +func notificationMuteSettingsController(presentationData: PresentationData, notificationSettings: MessageNotificationSettings, updateSettings: @escaping (Int32?) -> Void) -> ViewController { + + let controller = ActionSheetController(presentationTheme: presentationData.theme) let dismissAction: () -> Void = { [weak controller] in controller?.dismissAnimated() @@ -31,7 +35,7 @@ func notificationMuteSettingsController(presentationData: PresentationData, upda } let options: [NotificationMuteOption] = [ - .default, + // .default, .enable, .interval(1 * 60 * 60), .interval(8 * 60 * 60), @@ -51,7 +55,11 @@ func notificationMuteSettingsController(presentationData: PresentationData, upda case .enable: item = ActionSheetButtonItem(title: presentationData.strings.UserInfo_NotificationsEnable, action: { dismissAction() - notificationAction(0) + if notificationSettings.enabled { + notificationAction(nil) + } else { + notificationAction(0) + } }) case let .interval(value): item = ActionSheetButtonItem(title: muteForIntervalString(strings: presentationData.strings, value: value), action: { @@ -61,7 +69,11 @@ func notificationMuteSettingsController(presentationData: PresentationData, upda case .disable: item = ActionSheetButtonItem(title: presentationData.strings.UserInfo_NotificationsDisable, action: { dismissAction() - notificationAction(Int32.max) + if !notificationSettings.enabled { + notificationAction(nil) + } else { + notificationAction(Int32.max) + } }) } items.append(item) diff --git a/TelegramUI/UserInfoController.swift b/TelegramUI/UserInfoController.swift index 17ed359c4e..4a32ae68a2 100644 --- a/TelegramUI/UserInfoController.swift +++ b/TelegramUI/UserInfoController.swift @@ -860,10 +860,21 @@ public func userInfoController(account: Account, peerId: PeerId, mode: UserInfoC startSecretChatImpl?() }, changeNotificationMuteSettings: { let presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 } - let controller = notificationMuteSettingsController(presentationData: presentationData, updateSettings: { value in - changeMuteSettingsDisposable.set(updatePeerMuteSetting(account: account, peerId: peerId, muteInterval: value).start()) - }) - presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) + actionsDisposable.add((account.postbox.preferencesView(keys: [PreferencesKeys.globalNotifications]) |> take(1) |> deliverOnMainQueue).start(next: { view in + + let viewSettings: GlobalNotificationSettingsSet + if let settings = view.values[PreferencesKeys.globalNotifications] as? GlobalNotificationSettings { + viewSettings = settings.effective + } else { + viewSettings = GlobalNotificationSettingsSet.defaultSettings + } + + let controller = notificationMuteSettingsController(presentationData: presentationData, notificationSettings: viewSettings.privateChats, updateSettings: { value in + changeMuteSettingsDisposable.set(updatePeerMuteSetting(account: account, peerId: peerId, muteInterval: value).start()) + }) + presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) + })) + }, changeNotificationSoundSettings: { let _ = (account.postbox.transaction { transaction -> (TelegramPeerNotificationSettings, GlobalNotificationSettings) in let peerSettings: TelegramPeerNotificationSettings = (transaction.getPeerNotificationSettings(peerId) as? TelegramPeerNotificationSettings) ?? TelegramPeerNotificationSettings.defaultSettings