From 039faa90076bae837e742faa04ef8745211ad3fd Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 23 Sep 2018 18:43:33 -0400 Subject: [PATCH] Add x-callback-url response data --- Tusker/Screens/Compose/ComposeViewController.swift | 5 ++++- Tusker/XCallbackURL/XCBSession.swift | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Compose/ComposeViewController.swift b/Tusker/Screens/Compose/ComposeViewController.swift index a12c9348..a3eb3c85 100644 --- a/Tusker/Screens/Compose/ComposeViewController.swift +++ b/Tusker/Screens/Compose/ComposeViewController.swift @@ -252,7 +252,10 @@ class ComposeViewController: UIViewController { self.progressView.step() self.performSegue(withIdentifier: "postComplete", sender: self) - self.xcbSession?.complete(with: .success) + self.xcbSession?.complete(with: .success, additionalData: [ + "statusURL": status.url!.absoluteString, + "statusURI": status.uri + ]) } } } diff --git a/Tusker/XCallbackURL/XCBSession.swift b/Tusker/XCallbackURL/XCBSession.swift index fa1f156e..8d51eff2 100644 --- a/Tusker/XCallbackURL/XCBSession.swift +++ b/Tusker/XCallbackURL/XCBSession.swift @@ -21,9 +21,15 @@ class XCBSession { self.cancel = cancel } - func complete(with result: XCBSessionResult) { + func complete(with result: XCBSessionResult, additionalData: [String: String?]? = nil) { let url = result == .success ? success : result == .error ? error : cancel - if let url = url { + if var url = url { + if let additionalData = additionalData { + var components = URLComponents(url: url, resolvingAgainstBaseURL: true)! + components.queryItems = components.queryItems ?? [] + components.queryItems!.append(contentsOf: additionalData.map(URLQueryItem.init)) + url = components.url! + } UIApplication.shared.open(url, options: [:]) } }