Fix immediate sharing flow

This commit is contained in:
Ilya Laktyushin
2019-10-31 04:10:43 +04:00
parent 1fa2ce9320
commit 8f55c4d62e
3 changed files with 55 additions and 39 deletions

View File

@@ -279,6 +279,7 @@ public final class ShareController: ViewController {
private let immediateExternalShare: Bool private let immediateExternalShare: Bool
private let subject: ShareControllerSubject private let subject: ShareControllerSubject
private let switchableAccounts: [AccountWithInfo] private let switchableAccounts: [AccountWithInfo]
private let immediatePeerId: PeerId?
private let peers = Promise<([(RenderedPeer, PeerPresence?)], Peer)>() private let peers = Promise<([(RenderedPeer, PeerPresence?)], Peer)>()
private let peersDisposable = MetaDisposable() private let peersDisposable = MetaDisposable()
@@ -289,11 +290,11 @@ public final class ShareController: ViewController {
public var dismissed: ((Bool) -> Void)? 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] = []) { 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) 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.sharedContext = sharedContext
self.currentContext = currentContext self.currentContext = currentContext
self.currentAccount = currentContext.account self.currentAccount = currentContext.account
@@ -301,6 +302,7 @@ public final class ShareController: ViewController {
self.externalShare = externalShare self.externalShare = externalShare
self.immediateExternalShare = immediateExternalShare self.immediateExternalShare = immediateExternalShare
self.switchableAccounts = switchableAccounts self.switchableAccounts = switchableAccounts
self.immediatePeerId = immediatePeerId
self.presentationData = self.sharedContext.currentPresentationData.with { $0 } 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)) strongSelf.present(controller, in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet))
} }
self.displayNodeDidLoad() self.displayNodeDidLoad()
self.peersDisposable.set((self.peers.get()
|> deliverOnMainQueue).start(next: { [weak self] next in if let _ = self.immediatePeerId {
if let strongSelf = self { } else {
strongSelf.controllerNode.updatePeers(account: strongSelf.currentAccount, switchableAccounts: strongSelf.switchableAccounts, peers: next.0, accountPeer: next.1, defaultAction: strongSelf.defaultAction) 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()) self._ready.set(self.controllerNode.ready.get())
} }
@@ -821,27 +827,31 @@ public final class ShareController: ViewController {
return (resultPeers, accountPeer) return (resultPeers, accountPeer)
} }
}) })
self.peersDisposable.set((self.peers.get() if let immediatePeerId = self.immediatePeerId {
|> deliverOnMainQueue).start(next: { [weak self] next in self.sendImmediately(peerId: immediatePeerId)
if let strongSelf = self { } else {
strongSelf.controllerNode.updatePeers(account: strongSelf.currentAccount, switchableAccounts: strongSelf.switchableAccounts, peers: next.0, accountPeer: next.1, defaultAction: strongSelf.defaultAction) self.peersDisposable.set((self.peers.get()
|> deliverOnMainQueue).start(next: { [weak self] next in
if animateIn { if let strongSelf = self {
strongSelf.readyDisposable.set((strongSelf.controllerNode.ready.get() strongSelf.controllerNode.updatePeers(account: strongSelf.currentAccount, switchableAccounts: strongSelf.switchableAccounts, peers: next.0, accountPeer: next.1, defaultAction: strongSelf.defaultAction)
|> filter({ $0 })
|> take(1) if animateIn {
|> deliverOnMainQueue).start(next: { [weak self] _ in strongSelf.readyDisposable.set((strongSelf.controllerNode.ready.get()
guard let strongSelf = self else { |> filter({ $0 })
return |> take(1)
} |> deliverOnMainQueue).start(next: { [weak self] _ in
strongSelf.controllerNode.animateIn() guard let strongSelf = self else {
})) return
}
strongSelf.controllerNode.animateIn()
}))
}
} }
} }))
})) }
} }
public func sendImmediately(peerId: PeerId) { private func sendImmediately(peerId: PeerId) {
self.controllerNode.send(peerId: peerId) self.controllerNode.send(peerId: peerId)
} }
} }

View File

@@ -519,7 +519,12 @@ final class ShareControllerNode: ViewControllerTracingNode, UIScrollViewDelegate
} }
self.inputFieldNode.deactivateInput() 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.actionButtonNode, alpha: 0.0)
transition.updateAlpha(node: self.inputFieldNode, alpha: 0.0) transition.updateAlpha(node: self.inputFieldNode, alpha: 0.0)
transition.updateAlpha(node: self.actionSeparatorNode, alpha: 0.0) transition.updateAlpha(node: self.actionSeparatorNode, alpha: 0.0)

View File

@@ -278,6 +278,16 @@ public class ShareRootControllerImpl {
|> then(.single(.done)) |> 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 let shareController = ShareController(context: context, subject: .fromExternal({ peerIds, additionalText, account in
if let strongSelf = self, let inputItems = strongSelf.getExtensionContext()?.inputItems, !inputItems.isEmpty, !peerIds.isEmpty { if let strongSelf = self, let inputItems = strongSelf.getExtensionContext()?.inputItems, !inputItems.isEmpty, !peerIds.isEmpty {
let rawSignals = TGItemProviderSignals.itemSignals(forInputItems: inputItems)! let rawSignals = TGItemProviderSignals.itemSignals(forInputItems: inputItems)!
@@ -307,7 +317,7 @@ public class ShareRootControllerImpl {
} else { } else {
return .single(.done) return .single(.done)
} }
}), externalShare: false, switchableAccounts: otherAccounts) }), externalShare: false, switchableAccounts: otherAccounts, immediatePeerId: immediatePeerId)
shareController.presentationArguments = ViewControllerPresentationArguments(presentationAnimation: .modalSheet) shareController.presentationArguments = ViewControllerPresentationArguments(presentationAnimation: .modalSheet)
shareController.dismissed = { _ in shareController.dismissed = { _ in
self?.getExtensionContext()?.completeRequest(returningItems: nil, completionHandler: nil) self?.getExtensionContext()?.completeRequest(returningItems: nil, completionHandler: nil)
@@ -326,16 +336,7 @@ public class ShareRootControllerImpl {
strongSelf.currentShareController = shareController strongSelf.currentShareController = shareController
strongSelf.mainWindow?.present(shareController, on: .root) 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() context.account.resetStateManagement()
} }