From e17e00583f2cc04441893976b576ec57cb1bf370 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 15 Sep 2019 18:12:49 -0400 Subject: [PATCH] Add X-Callback-URL for search --- Documentation/X-Callback-URL.md | 17 +++++++++++++++++ Tusker/AppDelegate.swift | 2 +- Tusker/XCallbackURL/XCBActionType.swift | 2 ++ Tusker/XCallbackURL/XCBActions.swift | 17 +++++++++++++++++ Tusker/XCallbackURL/XCBManager.swift | 4 +++- 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Documentation/X-Callback-URL.md b/Documentation/X-Callback-URL.md index 409eca36..6146b77f 100644 --- a/Documentation/X-Callback-URL.md +++ b/Documentation/X-Callback-URL.md @@ -69,6 +69,8 @@ Dates in responses are encoded as Unix timestamps. - [`dismissAllNotifications`](#dismissallnotifications) - [Instances](#instances) - [`getCurrentInstance`](#getcurrentinstance) +- [Misc](#misc) + - [`search`](#search) ### Accounts @@ -336,3 +338,18 @@ No parameters. | `description` (string) | The instance description | No | | `contactAccount` (string) | The instance-local ID of the instance's contact account | No | + +### Misc + +#### `search` +Performs a search in Tusker with the given query + +##### Request + +| Parameter (type) | Description | Optional | +| ---------------- | ------------------------ |--------- | +| `query` (string) | The search query to use. | No | + +##### Response + +No data if successful. \ No newline at end of file diff --git a/Tusker/AppDelegate.swift b/Tusker/AppDelegate.swift index f243587b..b381219d 100644 --- a/Tusker/AppDelegate.swift +++ b/Tusker/AppDelegate.swift @@ -43,7 +43,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { searchController.loadViewIfNeeded() let query = components.url!.absoluteString - searchController.searchController.searchBar.searchTextField.text = query + searchController.searchController.searchBar.text = query searchController.performSearch(query: query) return true diff --git a/Tusker/XCallbackURL/XCBActionType.swift b/Tusker/XCallbackURL/XCBActionType.swift index d3eeb4cf..7d6a1042 100644 --- a/Tusker/XCallbackURL/XCBActionType.swift +++ b/Tusker/XCallbackURL/XCBActionType.swift @@ -20,6 +20,8 @@ enum XCBActionType: String { case getAccount case getCurrentUser case followUser + // Search + case search var path: String { return "/\(rawValue)" diff --git a/Tusker/XCallbackURL/XCBActions.swift b/Tusker/XCallbackURL/XCBActions.swift index b9d77d91..2430a3c7 100644 --- a/Tusker/XCallbackURL/XCBActions.swift +++ b/Tusker/XCallbackURL/XCBActions.swift @@ -314,4 +314,21 @@ struct XCBActions { getAccount(from: request, session: session, completion: follow) } + + // MARK: - Search + + static func search(_ request: XCBRequest, _ session: XCBSession, _ silent: Bool?) { + let query = request.arguments["query"]! + + if let tabBarController = UIApplication.shared.keyWindow?.rootViewController as? UITabBarController, + let navigationController = tabBarController.viewControllers?[3] as? UINavigationController, + let searchController = navigationController.viewControllers.first as? SearchTableViewController { + tabBarController.selectedIndex = 3 + navigationController.popToRootViewController(animated: false) + searchController.searchController.searchBar.text = query + searchController.performSearch(query: query) + } else { + session.complete(with: .error) + } + } } diff --git a/Tusker/XCallbackURL/XCBManager.swift b/Tusker/XCallbackURL/XCBManager.swift index c172b6e7..964cc0bf 100644 --- a/Tusker/XCallbackURL/XCBManager.swift +++ b/Tusker/XCallbackURL/XCBManager.swift @@ -21,7 +21,9 @@ class XCBManager { XCBRequestSpec(type: .showAccount, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: false, action: XCBActions.showAccount), XCBRequestSpec(type: .getAccount, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: false, action: XCBActions.getAccount), XCBRequestSpec(type: .getCurrentUser, arguments: [:], canRunSilently: false, action: XCBActions.getCurrentUser), - XCBRequestSpec(type: .followUser, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: true, action: XCBActions.followUser) + XCBRequestSpec(type: .followUser, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: true, action: XCBActions.followUser), + // Search + XCBRequestSpec(type: .search, arguments: ["query": false], canRunSilently: false, action: XCBActions.search), ] static var currentSession: XCBSession?