mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Fix immediate sharing flow
This commit is contained in:
@@ -279,6 +279,7 @@ public final class ShareController: ViewController {
|
||||
private let immediateExternalShare: Bool
|
||||
private let subject: ShareControllerSubject
|
||||
private let switchableAccounts: [AccountWithInfo]
|
||||
private let immediatePeerId: PeerId?
|
||||
|
||||
private let peers = Promise<([(RenderedPeer, PeerPresence?)], Peer)>()
|
||||
private let peersDisposable = MetaDisposable()
|
||||
@@ -289,11 +290,11 @@ public final class ShareController: ViewController {
|
||||
|
||||
public var dismissed: ((Bool) -> Void)?
|
||||
|
||||
public convenience init(context: AccountContext, subject: ShareControllerSubject, preferredAction: ShareControllerPreferredAction = .default, showInChat: ((Message) -> Void)? = nil, externalShare: Bool = true, immediateExternalShare: Bool = false, switchableAccounts: [AccountWithInfo] = []) {
|
||||
self.init(sharedContext: context.sharedContext, currentContext: context, subject: subject, preferredAction: preferredAction, showInChat: showInChat, externalShare: externalShare, immediateExternalShare: immediateExternalShare, switchableAccounts: switchableAccounts)
|
||||
public convenience init(context: AccountContext, subject: ShareControllerSubject, preferredAction: ShareControllerPreferredAction = .default, showInChat: ((Message) -> Void)? = nil, externalShare: Bool = true, immediateExternalShare: Bool = false, switchableAccounts: [AccountWithInfo] = [], immediatePeerId: PeerId? = nil) {
|
||||
self.init(sharedContext: context.sharedContext, currentContext: context, subject: subject, preferredAction: preferredAction, showInChat: showInChat, externalShare: externalShare, immediateExternalShare: immediateExternalShare, switchableAccounts: switchableAccounts, immediatePeerId: immediatePeerId)
|
||||
}
|
||||
|
||||
public init(sharedContext: SharedAccountContext, currentContext: AccountContext, subject: ShareControllerSubject, preferredAction: ShareControllerPreferredAction = .default, showInChat: ((Message) -> Void)? = nil, externalShare: Bool = true, immediateExternalShare: Bool = false, switchableAccounts: [AccountWithInfo] = []) {
|
||||
public init(sharedContext: SharedAccountContext, currentContext: AccountContext, subject: ShareControllerSubject, preferredAction: ShareControllerPreferredAction = .default, showInChat: ((Message) -> Void)? = nil, externalShare: Bool = true, immediateExternalShare: Bool = false, switchableAccounts: [AccountWithInfo] = [], immediatePeerId: PeerId? = nil) {
|
||||
self.sharedContext = sharedContext
|
||||
self.currentContext = currentContext
|
||||
self.currentAccount = currentContext.account
|
||||
@@ -301,6 +302,7 @@ public final class ShareController: ViewController {
|
||||
self.externalShare = externalShare
|
||||
self.immediateExternalShare = immediateExternalShare
|
||||
self.switchableAccounts = switchableAccounts
|
||||
self.immediatePeerId = immediatePeerId
|
||||
|
||||
self.presentationData = self.sharedContext.currentPresentationData.with { $0 }
|
||||
|
||||
@@ -701,12 +703,16 @@ public final class ShareController: ViewController {
|
||||
strongSelf.present(controller, in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
|
||||
}
|
||||
self.displayNodeDidLoad()
|
||||
|
||||
if let _ = self.immediatePeerId {
|
||||
} else {
|
||||
self.peersDisposable.set((self.peers.get()
|
||||
|> deliverOnMainQueue).start(next: { [weak self] next in
|
||||
if let strongSelf = self {
|
||||
strongSelf.controllerNode.updatePeers(account: strongSelf.currentAccount, switchableAccounts: strongSelf.switchableAccounts, peers: next.0, accountPeer: next.1, defaultAction: strongSelf.defaultAction)
|
||||
}
|
||||
}))
|
||||
}
|
||||
self._ready.set(self.controllerNode.ready.get())
|
||||
}
|
||||
|
||||
@@ -821,6 +827,9 @@ public final class ShareController: ViewController {
|
||||
return (resultPeers, accountPeer)
|
||||
}
|
||||
})
|
||||
if let immediatePeerId = self.immediatePeerId {
|
||||
self.sendImmediately(peerId: immediatePeerId)
|
||||
} else {
|
||||
self.peersDisposable.set((self.peers.get()
|
||||
|> deliverOnMainQueue).start(next: { [weak self] next in
|
||||
if let strongSelf = self {
|
||||
@@ -840,8 +849,9 @@ public final class ShareController: ViewController {
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
public func sendImmediately(peerId: PeerId) {
|
||||
private func sendImmediately(peerId: PeerId) {
|
||||
self.controllerNode.send(peerId: peerId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,7 +519,12 @@ final class ShareControllerNode: ViewControllerTracingNode, UIScrollViewDelegate
|
||||
}
|
||||
|
||||
self.inputFieldNode.deactivateInput()
|
||||
let transition = ContainedViewLayoutTransition.animated(duration: 0.12, curve: .easeInOut)
|
||||
let transition: ContainedViewLayoutTransition
|
||||
if peerId == nil {
|
||||
transition = .animated(duration: 0.12, curve: .easeInOut)
|
||||
} else {
|
||||
transition = .immediate
|
||||
}
|
||||
transition.updateAlpha(node: self.actionButtonNode, alpha: 0.0)
|
||||
transition.updateAlpha(node: self.inputFieldNode, alpha: 0.0)
|
||||
transition.updateAlpha(node: self.actionSeparatorNode, alpha: 0.0)
|
||||
|
||||
@@ -278,6 +278,16 @@ public class ShareRootControllerImpl {
|
||||
|> then(.single(.done))
|
||||
}
|
||||
|
||||
var immediatePeerId: PeerId?
|
||||
if #available(iOS 13.0, *), let sendMessageIntent = self?.getExtensionContext()?.intent as? INSendMessageIntent {
|
||||
if let contact = sendMessageIntent.recipients?.first, let handle = contact.customIdentifier, handle.hasPrefix("tg") {
|
||||
let string = handle.suffix(from: handle.index(handle.startIndex, offsetBy: 2))
|
||||
if let userId = Int32(string) {
|
||||
immediatePeerId = PeerId(namespace: Namespaces.Peer.CloudUser, id: userId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let shareController = ShareController(context: context, subject: .fromExternal({ peerIds, additionalText, account in
|
||||
if let strongSelf = self, let inputItems = strongSelf.getExtensionContext()?.inputItems, !inputItems.isEmpty, !peerIds.isEmpty {
|
||||
let rawSignals = TGItemProviderSignals.itemSignals(forInputItems: inputItems)!
|
||||
@@ -307,7 +317,7 @@ public class ShareRootControllerImpl {
|
||||
} else {
|
||||
return .single(.done)
|
||||
}
|
||||
}), externalShare: false, switchableAccounts: otherAccounts)
|
||||
}), externalShare: false, switchableAccounts: otherAccounts, immediatePeerId: immediatePeerId)
|
||||
shareController.presentationArguments = ViewControllerPresentationArguments(presentationAnimation: .modalSheet)
|
||||
shareController.dismissed = { _ in
|
||||
self?.getExtensionContext()?.completeRequest(returningItems: nil, completionHandler: nil)
|
||||
@@ -327,15 +337,6 @@ public class ShareRootControllerImpl {
|
||||
strongSelf.mainWindow?.present(shareController, on: .root)
|
||||
}
|
||||
|
||||
if #available(iOS 13.0, *), let sendMessageIntent = self?.getExtensionContext()?.intent as? INSendMessageIntent {
|
||||
if let contact = sendMessageIntent.recipients?.first, let handle = contact.customIdentifier, handle.hasPrefix("tg") {
|
||||
let string = handle.suffix(from: handle.index(handle.startIndex, offsetBy: 2))
|
||||
if let userId = Int32(string) {
|
||||
shareController.sendImmediately(peerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: userId))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.account.resetStateManagement()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user