From c077f75e7345c91092ef8b44739967e174f0938f Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sun, 27 Nov 2022 23:42:36 +0400 Subject: [PATCH] Autoremove improvements --- .../Telegram-iOS/en.lproj/Localizable.strings | 5 +++- .../ContactMultiselectionController.swift | 4 ++- .../GlobalAutoremoveScreen.swift | 25 +++++++++++++++++++ .../ContactMultiselectionController.swift | 4 ++- .../ContactMultiselectionControllerNode.swift | 5 +++- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index bc27e2960c..ddc2b71676 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -8396,7 +8396,10 @@ Sorry for the inconvenience."; "GlobalAutodeleteSettings.SetConfirmToastEnabled" = "Messages in all new chats you start will be automatically deleted after %@."; "GlobalAutodeleteSettings.SetConfirmToastDisabled" = "Messages in all new chats you start will not be automatically deleted."; "GlobalAutodeleteSettings.ApplyChatsTitle" = "Select Chats"; -"GlobalAutodeleteSettings.ApplyChatsPlaceholder" = "Select chats to apply the %@ self-destruct timer"; +"GlobalAutodeleteSettings.ApplyChatsPlaceholder" = "Select chats to apply a %@ self-destruct timer"; "GlobalAutodeleteSettings.ApplyChatsToast" = "You applied the %1$@ self-destruct timer to %2$@."; "GlobalAutodeleteSettings.ApplyChatsSubject_1" = "%@ chat"; "GlobalAutodeleteSettings.ApplyChatsSubject_any" = "%@ chats"; +"GlobalAutodeleteSettings.AttemptDisabledGroupSelection" = "You need admin rights in this group to enable auto-delete."; +"GlobalAutodeleteSettings.AttemptDisabledChannelSelection" = "You need admin rights in this channel to enable auto-delete."; +"GlobalAutodeleteSettings.AttemptDisabledGenericSelection" = "You can't enable auto-delete in this chat."; diff --git a/submodules/AccountContext/Sources/ContactMultiselectionController.swift b/submodules/AccountContext/Sources/ContactMultiselectionController.swift index 18fb5ade08..31f58f369c 100644 --- a/submodules/AccountContext/Sources/ContactMultiselectionController.swift +++ b/submodules/AccountContext/Sources/ContactMultiselectionController.swift @@ -80,17 +80,19 @@ public final class ContactMultiselectionControllerParams { public let options: [ContactListAdditionalOption] public let filters: [ContactListFilter] public let isPeerEnabled: ((EnginePeer) -> Bool)? + public let attemptDisabledItemSelection: ((EnginePeer) -> Void)? public let alwaysEnabled: Bool public let limit: Int32? public let reachedLimit: ((Int32) -> Void)? - public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, mode: ContactMultiselectionControllerMode, options: [ContactListAdditionalOption], filters: [ContactListFilter] = [.excludeSelf], isPeerEnabled: ((EnginePeer) -> Bool)? = nil, alwaysEnabled: Bool = false, limit: Int32? = nil, reachedLimit: ((Int32) -> Void)? = nil) { + public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal)? = nil, mode: ContactMultiselectionControllerMode, options: [ContactListAdditionalOption], filters: [ContactListFilter] = [.excludeSelf], isPeerEnabled: ((EnginePeer) -> Bool)? = nil, attemptDisabledItemSelection: ((EnginePeer) -> Void)? = nil, alwaysEnabled: Bool = false, limit: Int32? = nil, reachedLimit: ((Int32) -> Void)? = nil) { self.context = context self.updatedPresentationData = updatedPresentationData self.mode = mode self.options = options self.filters = filters self.isPeerEnabled = isPeerEnabled + self.attemptDisabledItemSelection = attemptDisabledItemSelection self.alwaysEnabled = alwaysEnabled self.limit = limit self.reachedLimit = reachedLimit diff --git a/submodules/SettingsUI/Sources/Privacy and Security/GlobalAutoremoveScreen.swift b/submodules/SettingsUI/Sources/Privacy and Security/GlobalAutoremoveScreen.swift index 3e1d9544c7..7e31cef764 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/GlobalAutoremoveScreen.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/GlobalAutoremoveScreen.swift @@ -326,6 +326,31 @@ public func globalAutoremoveScreen(context: AccountContext, initialValue: Int32, canManage = channel.hasPermission(.changeInfo) } return canManage + }, + attemptDisabledItemSelection: { peer in + let presentationData = context.sharedContext.currentPresentationData.with { $0 } + + let text: String + if case let .channel(channel) = peer { + if case .group = channel.info { + text = presentationData.strings.GlobalAutodeleteSettings_AttemptDisabledGroupSelection + } else { + text = presentationData.strings.GlobalAutodeleteSettings_AttemptDisabledChannelSelection + } + } else if case .legacyGroup = peer { + text = presentationData.strings.GlobalAutodeleteSettings_AttemptDisabledGroupSelection + } else { + text = presentationData.strings.GlobalAutodeleteSettings_AttemptDisabledGenericSelection + } + + presentControllerImpl?(standardTextAlertController( + theme: AlertControllerTheme(presentationData: presentationData), + title: nil, + text: text, + actions: [ + TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {}) + ] + ), nil) } )) selectionController.navigationPresentation = .modal diff --git a/submodules/TelegramUI/Sources/ContactMultiselectionController.swift b/submodules/TelegramUI/Sources/ContactMultiselectionController.swift index d8f862acaf..bf260b5240 100644 --- a/submodules/TelegramUI/Sources/ContactMultiselectionController.swift +++ b/submodules/TelegramUI/Sources/ContactMultiselectionController.swift @@ -29,6 +29,7 @@ class ContactMultiselectionControllerImpl: ViewController, ContactMultiselection private let context: AccountContext private let mode: ContactMultiselectionControllerMode private let isPeerEnabled: ((EnginePeer) -> Bool)? + private let attemptDisabledItemSelection: ((EnginePeer) -> Void)? private let titleView: CounterContollerTitleView @@ -85,6 +86,7 @@ class ContactMultiselectionControllerImpl: ViewController, ContactMultiselection self.context = params.context self.mode = params.mode self.isPeerEnabled = params.isPeerEnabled + self.attemptDisabledItemSelection = params.attemptDisabledItemSelection self.options = params.options self.filters = params.filters self.limit = params.limit @@ -222,7 +224,7 @@ class ContactMultiselectionControllerImpl: ViewController, ContactMultiselection } override func loadDisplayNode() { - self.displayNode = ContactMultiselectionControllerNode(navigationBar: self.navigationBar, context: self.context, presentationData: self.presentationData, mode: self.mode, isPeerEnabled: self.isPeerEnabled, options: self.options, filters: self.filters, limit: self.limit, reachedSelectionLimit: self.params.reachedLimit) + self.displayNode = ContactMultiselectionControllerNode(navigationBar: self.navigationBar, context: self.context, presentationData: self.presentationData, mode: self.mode, isPeerEnabled: self.isPeerEnabled, attemptDisabledItemSelection: self.attemptDisabledItemSelection, options: self.options, filters: self.filters, limit: self.limit, reachedSelectionLimit: self.params.reachedLimit) switch self.contactsNode.contentNode { case let .contacts(contactsNode): self._listReady.set(contactsNode.ready) diff --git a/submodules/TelegramUI/Sources/ContactMultiselectionControllerNode.swift b/submodules/TelegramUI/Sources/ContactMultiselectionControllerNode.swift index 96b8579688..da33621ce9 100644 --- a/submodules/TelegramUI/Sources/ContactMultiselectionControllerNode.swift +++ b/submodules/TelegramUI/Sources/ContactMultiselectionControllerNode.swift @@ -71,7 +71,7 @@ final class ContactMultiselectionControllerNode: ASDisplayNode { private let animationCache: AnimationCache private let animationRenderer: MultiAnimationRenderer - init(navigationBar: NavigationBar?, context: AccountContext, presentationData: PresentationData, mode: ContactMultiselectionControllerMode, isPeerEnabled: ((EnginePeer) -> Bool)?, options: [ContactListAdditionalOption], filters: [ContactListFilter], limit: Int32?, reachedSelectionLimit: ((Int32) -> Void)?) { + init(navigationBar: NavigationBar?, context: AccountContext, presentationData: PresentationData, mode: ContactMultiselectionControllerMode, isPeerEnabled: ((EnginePeer) -> Bool)?, attemptDisabledItemSelection: ((EnginePeer) -> Void)?, options: [ContactListAdditionalOption], filters: [ContactListFilter], limit: Int32?, reachedSelectionLimit: ((Int32) -> Void)?) { self.navigationBar = navigationBar self.context = context @@ -102,6 +102,9 @@ final class ContactMultiselectionControllerNode: ASDisplayNode { placeholder = placeholderValue let chatListNode = ChatListNode(context: context, location: .chatList(groupId: .root), previewing: false, fillPreloadItems: false, mode: .peers(filter: [.excludeSecretChats], isSelecting: true, additionalCategories: additionalCategories?.categories ?? [], chatListFilters: chatListFilters, displayAutoremoveTimeout: chatSelection.displayAutoremoveTimeout), isPeerEnabled: isPeerEnabled, theme: self.presentationData.theme, fontSize: self.presentationData.listsFontSize, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, nameSortOrder: self.presentationData.nameSortOrder, nameDisplayOrder: self.presentationData.nameDisplayOrder, animationCache: self.animationCache, animationRenderer: self.animationRenderer, disableAnimations: true, isInlineMode: false) + chatListNode.disabledPeerSelected = { peer, _ in + attemptDisabledItemSelection?(peer) + } if let limit = limit { chatListNode.selectionLimit = limit chatListNode.reachedSelectionLimit = reachedSelectionLimit