From f1664fa0baf096f94879712a5c31a564a8a0bc4a Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 27 Nov 2019 18:46:32 +0400 Subject: [PATCH] Remove corresponding share suggestion on chat deletion, leaving, archiving and contact removal --- submodules/ChatListUI/BUCK | 1 + .../Sources/ChatListController.swift | 34 ++++++------------- submodules/PeerInfoUI/BUCK | 1 + .../Sources/UserInfoController.swift | 5 +++ .../IntentsSettingsController.swift | 24 +++++++++++-- submodules/ShareController/BUCK | 2 +- .../Sources/ShareControllerNode.swift | 2 +- .../{AppIntents => TelegramIntents}/BUCK | 2 +- .../Info.plist | 0 .../Sources/TelegramIntents.swift} | 5 ++- submodules/TelegramUI/BUCK | 2 +- .../TelegramUI/TelegramUI/AppDelegate.swift | 2 +- .../TelegramUI/ChatController.swift | 2 +- .../Sources/IntentsSettings.swift | 11 ++++-- 14 files changed, 55 insertions(+), 38 deletions(-) rename submodules/{AppIntents => TelegramIntents}/BUCK (95%) rename submodules/{AppIntents => TelegramIntents}/Info.plist (100%) rename submodules/{AppIntents/Sources/AppIntents.swift => TelegramIntents/Sources/TelegramIntents.swift} (97%) diff --git a/submodules/ChatListUI/BUCK b/submodules/ChatListUI/BUCK index 5b26e2660a..3b391fe24e 100644 --- a/submodules/ChatListUI/BUCK +++ b/submodules/ChatListUI/BUCK @@ -41,6 +41,7 @@ static_library( "//submodules/AppBundle:AppBundle", "//submodules/ContextUI:ContextUI", "//submodules/PhoneNumberFormat:PhoneNumberFormat", + "//submodules/TelegramIntents:TelegramIntents", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 86bfd13c60..882937f766 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -20,6 +20,7 @@ import LanguageSuggestionUI import ContextUI import AppBundle import LocalizedPeerData +import TelegramIntents public func useSpecialTabBarIcons() -> Bool { return (Date(timeIntervalSince1970: 1545642000)...Date(timeIntervalSince1970: 1546387200)).contains(Date()) @@ -122,9 +123,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController, private var badgeIconDisposable: Disposable? private var dismissSearchOnDisappear = false - - private var didSetup3dTouch = false - + private var passcodeLockTooltipDisposable = MetaDisposable() private var didShowPasscodeLockTooltipController = false @@ -226,7 +225,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController, } strongSelf.chatListDisplayNode.chatListNode.scrollToPosition(.top) } - //.auto for unread navigation } self.longTapWithTabBar = { [weak self] in guard let strongSelf = self else { @@ -760,17 +758,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController, self.displayNodeDidLoad() } - override public func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { - super.traitCollectionDidChange(previousTraitCollection) - - if #available(iOSApplicationExtension 9.0, iOS 9.0, *) { - if !self.didSetup3dTouch && self.traitCollection.forceTouchCapability != .unknown { - self.didSetup3dTouch = true - //self.registerForPreviewingNonNative(with: self, sourceView: self.view, theme: PeekControllerTheme(presentationTheme: self.presentationData.theme)) - } - } - } - override public func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) @@ -884,13 +871,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController, return true }) } - - if #available(iOSApplicationExtension 9.0, iOS 9.0, *) { - if !self.didSetup3dTouch { - self.didSetup3dTouch = true - //self.registerForPreviewingNonNative(with: self, sourceView: self.view, theme: PeekControllerTheme(presentationTheme: self.presentationData.theme)) - } - } } override public func viewWillDisappear(_ animated: Bool) { @@ -1634,6 +1614,10 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController, } strongSelf.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(nil) + for peerId in peerIds { + deleteSendMessageIntents(account: strongSelf.context.account, peerId: peerId) + } + let action: (Bool) -> Void = { shouldCommit in guard let strongSelf = self else { return @@ -1755,7 +1739,9 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController, state.pendingRemovalPeerIds.remove(peer.peerId) return state }) - self?.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(nil) + strongSelf.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(nil) + + deleteSendMessageIntents(account: strongSelf.context.account, peerId: peerId) }) completion() } else { @@ -1765,7 +1751,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController, state.pendingRemovalPeerIds.remove(peer.peerId) return state }) - self?.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(nil) + strongSelf.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(nil) } }), in: .current) } diff --git a/submodules/PeerInfoUI/BUCK b/submodules/PeerInfoUI/BUCK index abdb71be72..d2c35361ea 100644 --- a/submodules/PeerInfoUI/BUCK +++ b/submodules/PeerInfoUI/BUCK @@ -61,6 +61,7 @@ static_library( "//submodules/AppBundle:AppBundle", "//submodules/Markdown:Markdown", "//submodules/PhoneNumberFormat:PhoneNumberFormat", + "//submodules/TelegramIntents:TelegramIntents", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/PeerInfoUI/Sources/UserInfoController.swift b/submodules/PeerInfoUI/Sources/UserInfoController.swift index 4295034880..7d5fa25992 100644 --- a/submodules/PeerInfoUI/Sources/UserInfoController.swift +++ b/submodules/PeerInfoUI/Sources/UserInfoController.swift @@ -27,6 +27,7 @@ import NotificationSoundSelectionUI import Markdown import LocalizedPeerData import PhoneNumberFormat +import TelegramIntents private final class UserInfoControllerArguments { let account: Account @@ -1026,6 +1027,8 @@ public func userInfoController(context: AccountContext, peerId: PeerId, mode: Pe } else if reportSpam { let _ = reportPeer(account: context.account, peerId: peerId, reason: .spam).start() } + + deleteSendMessageIntents(account: context.account, peerId: peerId) }) ]), ActionSheetItemGroup(items: [ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, action: { dismissAction() })]) @@ -1094,6 +1097,8 @@ public func userInfoController(context: AccountContext, peerId: PeerId, mode: Pe |> deliverOnMainQueue).start(completed: { dismissImpl?() })) + + deleteSendMessageIntents(account: context.account, peerId: peerId) }) }) ]), diff --git a/submodules/SettingsUI/Sources/Data and Storage/IntentsSettingsController.swift b/submodules/SettingsUI/Sources/Data and Storage/IntentsSettingsController.swift index a5b7a22b40..7afe6c6637 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/IntentsSettingsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/IntentsSettingsController.swift @@ -9,7 +9,7 @@ import TelegramUIPreferences import ItemListUI import ItemListPeerItem import AccountContext -import AppIntents +import TelegramIntents import AccountUtils private final class IntentsSettingsControllerArguments { @@ -268,7 +268,27 @@ public func intentsSettingsController(context: AccountContext) -> ViewController let updateDisposable = MetaDisposable() let arguments = IntentsSettingsControllerArguments(context: context, updateSettings: { f in - let _ = updateIntentsSettingsInteractively(accountManager: context.sharedContext.accountManager, f).start() + let _ = updateIntentsSettingsInteractively(accountManager: context.sharedContext.accountManager, f).start(next: { previous, updated in + guard let previous = previous, let updated = updated else { + return + } + let accountPeerId = context.account.peerId + if previous.contacts && !updated.contacts { + deleteAllSendMessageIntents(accountPeerId: accountPeerId, subject: .contact) + } + if previous.savedMessages && !updated.savedMessages { + deleteAllSendMessageIntents(accountPeerId: accountPeerId, subject: .savedMessages) + } + if previous.privateChats && !updated.privateChats { + deleteAllSendMessageIntents(accountPeerId: accountPeerId, subject: .privateChat) + } + if previous.groups && !updated.groups { + deleteAllSendMessageIntents(accountPeerId: accountPeerId, subject: .group) + } + if previous.account != updated.account, let previousAccount = previous.account { + deleteAllSendMessageIntents(accountPeerId: previousAccount) + } + }) }, resetAll: { let presentationData = context.sharedContext.currentPresentationData.with { $0 } let actionSheet = ActionSheetController(presentationData: presentationData) diff --git a/submodules/ShareController/BUCK b/submodules/ShareController/BUCK index 9a5616a4e9..f7f3fc45ac 100644 --- a/submodules/ShareController/BUCK +++ b/submodules/ShareController/BUCK @@ -23,7 +23,7 @@ static_library( "//submodules/ActivityIndicator:ActivityIndicator", "//submodules/AppBundle:AppBundle", "//submodules/TelegramStringFormatting:TelegramStringFormatting", - "//submodules/AppIntents:AppIntents", + "//submodules/TelegramIntents:TelegramIntents", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/ShareController/Sources/ShareControllerNode.swift b/submodules/ShareController/Sources/ShareControllerNode.swift index 9a1a4a3920..1d6daedee1 100644 --- a/submodules/ShareController/Sources/ShareControllerNode.swift +++ b/submodules/ShareController/Sources/ShareControllerNode.swift @@ -8,7 +8,7 @@ import TelegramCore import SyncCore import TelegramPresentationData import AccountContext -import AppIntents +import TelegramIntents enum ShareState { case preparing diff --git a/submodules/AppIntents/BUCK b/submodules/TelegramIntents/BUCK similarity index 95% rename from submodules/AppIntents/BUCK rename to submodules/TelegramIntents/BUCK index 2bc4100875..0c6544dc69 100644 --- a/submodules/AppIntents/BUCK +++ b/submodules/TelegramIntents/BUCK @@ -1,7 +1,7 @@ load("//Config:buck_rule_macros.bzl", "static_library") static_library( - name = "AppIntents", + name = "TelegramIntents", srcs = glob([ "Sources/**/*.swift", ]), diff --git a/submodules/AppIntents/Info.plist b/submodules/TelegramIntents/Info.plist similarity index 100% rename from submodules/AppIntents/Info.plist rename to submodules/TelegramIntents/Info.plist diff --git a/submodules/AppIntents/Sources/AppIntents.swift b/submodules/TelegramIntents/Sources/TelegramIntents.swift similarity index 97% rename from submodules/AppIntents/Sources/AppIntents.swift rename to submodules/TelegramIntents/Sources/TelegramIntents.swift index 7d009ab733..62076cd6da 100644 --- a/submodules/AppIntents/Sources/AppIntents.swift +++ b/submodules/TelegramIntents/Sources/TelegramIntents.swift @@ -82,8 +82,7 @@ public func donateSendMessageIntent(account: Account, sharedContext: SharedAccou continue } subject = .savedMessages - } - if transaction.isPeerContact(peerId: peerId) { + } else if transaction.isPeerContact(peerId: peerId) { if !settings.contacts { continue } @@ -169,7 +168,7 @@ public func donateSendMessageIntent(account: Account, sharedContext: SharedAccou } let interaction = INInteraction(intent: intent, response: nil) interaction.direction = .outgoing - //interaction.identifier = "sendMessage_\(account.peerId.toInt64())_\(peer.id.toInt64)" + interaction.identifier = "sendMessage_\(account.peerId.toInt64())_\(peer.id.toInt64)" interaction.groupIdentifier = "sendMessage_\(subject.toString())_\(account.peerId.toInt64())" interaction.donate() } diff --git a/submodules/TelegramUI/BUCK b/submodules/TelegramUI/BUCK index 893ddfa909..982d26f152 100644 --- a/submodules/TelegramUI/BUCK +++ b/submodules/TelegramUI/BUCK @@ -197,7 +197,7 @@ framework( "//submodules/AppLock:AppLock", "//submodules/NotificationsPresentationData:NotificationsPresentationData", "//submodules/UrlWhitelist:UrlWhitelist", - "//submodules/AppIntents:AppIntents", + "//submodules/TelegramIntents:TelegramIntents", "//submodules/LocationResources:LocationResources", "//submodules/ItemListVenueItem:ItemListVenueItem", "//submodules/SemanticStatusNode:SemanticStatusNode", diff --git a/submodules/TelegramUI/TelegramUI/AppDelegate.swift b/submodules/TelegramUI/TelegramUI/AppDelegate.swift index 522dda49bf..a2ef045366 100644 --- a/submodules/TelegramUI/TelegramUI/AppDelegate.swift +++ b/submodules/TelegramUI/TelegramUI/AppDelegate.swift @@ -33,7 +33,7 @@ import WalletCore import OpenSSLEncryptionProvider import AppLock import PresentationDataUtils -import AppIntents +import TelegramIntents import AccountUtils #if canImport(BackgroundTasks) diff --git a/submodules/TelegramUI/TelegramUI/ChatController.swift b/submodules/TelegramUI/TelegramUI/ChatController.swift index 7c430943f9..581c73bad9 100644 --- a/submodules/TelegramUI/TelegramUI/ChatController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatController.swift @@ -55,7 +55,7 @@ import LocalizedPeerData import PhoneNumberFormat import SettingsUI import UrlWhitelist -import AppIntents +import TelegramIntents public enum ChatControllerPeekActions { case standard diff --git a/submodules/TelegramUIPreferences/Sources/IntentsSettings.swift b/submodules/TelegramUIPreferences/Sources/IntentsSettings.swift index 5683fac254..71d2c427fa 100644 --- a/submodules/TelegramUIPreferences/Sources/IntentsSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/IntentsSettings.swift @@ -88,8 +88,10 @@ public struct IntentsSettings: PreferencesEntry, Equatable { } -public func updateIntentsSettingsInteractively(accountManager: AccountManager, _ f: @escaping (IntentsSettings) -> IntentsSettings) -> Signal { - return accountManager.transaction { transaction -> Void in +public func updateIntentsSettingsInteractively(accountManager: AccountManager, _ f: @escaping (IntentsSettings) -> IntentsSettings) -> Signal<(IntentsSettings?, IntentsSettings?), NoError> { + return accountManager.transaction { transaction -> (IntentsSettings?, IntentsSettings?) in + var previousSettings: IntentsSettings? = nil + var updatedSettings: IntentsSettings? = nil transaction.updateSharedData(ApplicationSpecificSharedDataKeys.intentsSettings, { entry in let currentSettings: IntentsSettings if let entry = entry as? IntentsSettings { @@ -97,7 +99,10 @@ public func updateIntentsSettingsInteractively(accountManager: AccountManager, _ } else { currentSettings = IntentsSettings.defaultSettings } - return f(currentSettings) + previousSettings = currentSettings + updatedSettings = f(currentSettings) + return updatedSettings }) + return (previousSettings, updatedSettings) } }