Remove corresponding share suggestion on chat deletion, leaving, archiving and contact removal

This commit is contained in:
Ilya Laktyushin 2019-11-27 18:46:32 +04:00
parent 8162bd5ae8
commit f1664fa0ba
14 changed files with 55 additions and 38 deletions

View File

@ -41,6 +41,7 @@ static_library(
"//submodules/AppBundle:AppBundle", "//submodules/AppBundle:AppBundle",
"//submodules/ContextUI:ContextUI", "//submodules/ContextUI:ContextUI",
"//submodules/PhoneNumberFormat:PhoneNumberFormat", "//submodules/PhoneNumberFormat:PhoneNumberFormat",
"//submodules/TelegramIntents:TelegramIntents",
], ],
frameworks = [ frameworks = [
"$SDKROOT/System/Library/Frameworks/Foundation.framework", "$SDKROOT/System/Library/Frameworks/Foundation.framework",

View File

@ -20,6 +20,7 @@ import LanguageSuggestionUI
import ContextUI import ContextUI
import AppBundle import AppBundle
import LocalizedPeerData import LocalizedPeerData
import TelegramIntents
public func useSpecialTabBarIcons() -> Bool { public func useSpecialTabBarIcons() -> Bool {
return (Date(timeIntervalSince1970: 1545642000)...Date(timeIntervalSince1970: 1546387200)).contains(Date()) return (Date(timeIntervalSince1970: 1545642000)...Date(timeIntervalSince1970: 1546387200)).contains(Date())
@ -123,8 +124,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController,
private var dismissSearchOnDisappear = false private var dismissSearchOnDisappear = false
private var didSetup3dTouch = false
private var passcodeLockTooltipDisposable = MetaDisposable() private var passcodeLockTooltipDisposable = MetaDisposable()
private var didShowPasscodeLockTooltipController = false private var didShowPasscodeLockTooltipController = false
@ -226,7 +225,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController,
} }
strongSelf.chatListDisplayNode.chatListNode.scrollToPosition(.top) strongSelf.chatListDisplayNode.chatListNode.scrollToPosition(.top)
} }
//.auto for unread navigation
} }
self.longTapWithTabBar = { [weak self] in self.longTapWithTabBar = { [weak self] in
guard let strongSelf = self else { guard let strongSelf = self else {
@ -760,17 +758,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController,
self.displayNodeDidLoad() 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) { override public func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated) super.viewDidAppear(animated)
@ -884,13 +871,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController,
return true 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) { override public func viewWillDisappear(_ animated: Bool) {
@ -1634,6 +1614,10 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController,
} }
strongSelf.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(nil) strongSelf.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(nil)
for peerId in peerIds {
deleteSendMessageIntents(account: strongSelf.context.account, peerId: peerId)
}
let action: (Bool) -> Void = { shouldCommit in let action: (Bool) -> Void = { shouldCommit in
guard let strongSelf = self else { guard let strongSelf = self else {
return return
@ -1755,7 +1739,9 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController,
state.pendingRemovalPeerIds.remove(peer.peerId) state.pendingRemovalPeerIds.remove(peer.peerId)
return state return state
}) })
self?.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(nil) strongSelf.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(nil)
deleteSendMessageIntents(account: strongSelf.context.account, peerId: peerId)
}) })
completion() completion()
} else { } else {
@ -1765,7 +1751,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController,
state.pendingRemovalPeerIds.remove(peer.peerId) state.pendingRemovalPeerIds.remove(peer.peerId)
return state return state
}) })
self?.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(nil) strongSelf.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(nil)
} }
}), in: .current) }), in: .current)
} }

View File

@ -61,6 +61,7 @@ static_library(
"//submodules/AppBundle:AppBundle", "//submodules/AppBundle:AppBundle",
"//submodules/Markdown:Markdown", "//submodules/Markdown:Markdown",
"//submodules/PhoneNumberFormat:PhoneNumberFormat", "//submodules/PhoneNumberFormat:PhoneNumberFormat",
"//submodules/TelegramIntents:TelegramIntents",
], ],
frameworks = [ frameworks = [
"$SDKROOT/System/Library/Frameworks/Foundation.framework", "$SDKROOT/System/Library/Frameworks/Foundation.framework",

View File

@ -27,6 +27,7 @@ import NotificationSoundSelectionUI
import Markdown import Markdown
import LocalizedPeerData import LocalizedPeerData
import PhoneNumberFormat import PhoneNumberFormat
import TelegramIntents
private final class UserInfoControllerArguments { private final class UserInfoControllerArguments {
let account: Account let account: Account
@ -1026,6 +1027,8 @@ public func userInfoController(context: AccountContext, peerId: PeerId, mode: Pe
} else if reportSpam { } else if reportSpam {
let _ = reportPeer(account: context.account, peerId: peerId, reason: .spam).start() 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() })]) 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: { |> deliverOnMainQueue).start(completed: {
dismissImpl?() dismissImpl?()
})) }))
deleteSendMessageIntents(account: context.account, peerId: peerId)
}) })
}) })
]), ]),

View File

@ -9,7 +9,7 @@ import TelegramUIPreferences
import ItemListUI import ItemListUI
import ItemListPeerItem import ItemListPeerItem
import AccountContext import AccountContext
import AppIntents import TelegramIntents
import AccountUtils import AccountUtils
private final class IntentsSettingsControllerArguments { private final class IntentsSettingsControllerArguments {
@ -268,7 +268,27 @@ public func intentsSettingsController(context: AccountContext) -> ViewController
let updateDisposable = MetaDisposable() let updateDisposable = MetaDisposable()
let arguments = IntentsSettingsControllerArguments(context: context, updateSettings: { f in 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: { }, resetAll: {
let presentationData = context.sharedContext.currentPresentationData.with { $0 } let presentationData = context.sharedContext.currentPresentationData.with { $0 }
let actionSheet = ActionSheetController(presentationData: presentationData) let actionSheet = ActionSheetController(presentationData: presentationData)

View File

@ -23,7 +23,7 @@ static_library(
"//submodules/ActivityIndicator:ActivityIndicator", "//submodules/ActivityIndicator:ActivityIndicator",
"//submodules/AppBundle:AppBundle", "//submodules/AppBundle:AppBundle",
"//submodules/TelegramStringFormatting:TelegramStringFormatting", "//submodules/TelegramStringFormatting:TelegramStringFormatting",
"//submodules/AppIntents:AppIntents", "//submodules/TelegramIntents:TelegramIntents",
], ],
frameworks = [ frameworks = [
"$SDKROOT/System/Library/Frameworks/Foundation.framework", "$SDKROOT/System/Library/Frameworks/Foundation.framework",

View File

@ -8,7 +8,7 @@ import TelegramCore
import SyncCore import SyncCore
import TelegramPresentationData import TelegramPresentationData
import AccountContext import AccountContext
import AppIntents import TelegramIntents
enum ShareState { enum ShareState {
case preparing case preparing

View File

@ -1,7 +1,7 @@
load("//Config:buck_rule_macros.bzl", "static_library") load("//Config:buck_rule_macros.bzl", "static_library")
static_library( static_library(
name = "AppIntents", name = "TelegramIntents",
srcs = glob([ srcs = glob([
"Sources/**/*.swift", "Sources/**/*.swift",
]), ]),

View File

@ -82,8 +82,7 @@ public func donateSendMessageIntent(account: Account, sharedContext: SharedAccou
continue continue
} }
subject = .savedMessages subject = .savedMessages
} } else if transaction.isPeerContact(peerId: peerId) {
if transaction.isPeerContact(peerId: peerId) {
if !settings.contacts { if !settings.contacts {
continue continue
} }
@ -169,7 +168,7 @@ public func donateSendMessageIntent(account: Account, sharedContext: SharedAccou
} }
let interaction = INInteraction(intent: intent, response: nil) let interaction = INInteraction(intent: intent, response: nil)
interaction.direction = .outgoing 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.groupIdentifier = "sendMessage_\(subject.toString())_\(account.peerId.toInt64())"
interaction.donate() interaction.donate()
} }

View File

@ -197,7 +197,7 @@ framework(
"//submodules/AppLock:AppLock", "//submodules/AppLock:AppLock",
"//submodules/NotificationsPresentationData:NotificationsPresentationData", "//submodules/NotificationsPresentationData:NotificationsPresentationData",
"//submodules/UrlWhitelist:UrlWhitelist", "//submodules/UrlWhitelist:UrlWhitelist",
"//submodules/AppIntents:AppIntents", "//submodules/TelegramIntents:TelegramIntents",
"//submodules/LocationResources:LocationResources", "//submodules/LocationResources:LocationResources",
"//submodules/ItemListVenueItem:ItemListVenueItem", "//submodules/ItemListVenueItem:ItemListVenueItem",
"//submodules/SemanticStatusNode:SemanticStatusNode", "//submodules/SemanticStatusNode:SemanticStatusNode",

View File

@ -33,7 +33,7 @@ import WalletCore
import OpenSSLEncryptionProvider import OpenSSLEncryptionProvider
import AppLock import AppLock
import PresentationDataUtils import PresentationDataUtils
import AppIntents import TelegramIntents
import AccountUtils import AccountUtils
#if canImport(BackgroundTasks) #if canImport(BackgroundTasks)

View File

@ -55,7 +55,7 @@ import LocalizedPeerData
import PhoneNumberFormat import PhoneNumberFormat
import SettingsUI import SettingsUI
import UrlWhitelist import UrlWhitelist
import AppIntents import TelegramIntents
public enum ChatControllerPeekActions { public enum ChatControllerPeekActions {
case standard case standard

View File

@ -88,8 +88,10 @@ public struct IntentsSettings: PreferencesEntry, Equatable {
} }
public func updateIntentsSettingsInteractively(accountManager: AccountManager, _ f: @escaping (IntentsSettings) -> IntentsSettings) -> Signal<Void, NoError> { public func updateIntentsSettingsInteractively(accountManager: AccountManager, _ f: @escaping (IntentsSettings) -> IntentsSettings) -> Signal<(IntentsSettings?, IntentsSettings?), NoError> {
return accountManager.transaction { transaction -> Void in return accountManager.transaction { transaction -> (IntentsSettings?, IntentsSettings?) in
var previousSettings: IntentsSettings? = nil
var updatedSettings: IntentsSettings? = nil
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.intentsSettings, { entry in transaction.updateSharedData(ApplicationSpecificSharedDataKeys.intentsSettings, { entry in
let currentSettings: IntentsSettings let currentSettings: IntentsSettings
if let entry = entry as? IntentsSettings { if let entry = entry as? IntentsSettings {
@ -97,7 +99,10 @@ public func updateIntentsSettingsInteractively(accountManager: AccountManager, _
} else { } else {
currentSettings = IntentsSettings.defaultSettings currentSettings = IntentsSettings.defaultSettings
} }
return f(currentSettings) previousSettings = currentSettings
updatedSettings = f(currentSettings)
return updatedSettings
}) })
return (previousSettings, updatedSettings)
} }
} }