Add X-Callback-URL for search

This commit is contained in:
Shadowfacts 2019-09-15 18:12:49 -04:00
parent 078f9e076d
commit e17e00583f
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
5 changed files with 40 additions and 2 deletions

View File

@ -69,6 +69,8 @@ Dates in responses are encoded as Unix timestamps.
- [`dismissAllNotifications`](#dismissallnotifications) - [`dismissAllNotifications`](#dismissallnotifications)
- [Instances](#instances) - [Instances](#instances)
- [`getCurrentInstance`](#getcurrentinstance) - [`getCurrentInstance`](#getcurrentinstance)
- [Misc](#misc)
- [`search`](#search)
### Accounts ### Accounts
@ -336,3 +338,18 @@ No parameters.
| `description` (string) | The instance description | No | | `description` (string) | The instance description | No |
| `contactAccount` (string) | The instance-local ID of the instance's contact account | 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.

View File

@ -43,7 +43,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
searchController.loadViewIfNeeded() searchController.loadViewIfNeeded()
let query = components.url!.absoluteString let query = components.url!.absoluteString
searchController.searchController.searchBar.searchTextField.text = query searchController.searchController.searchBar.text = query
searchController.performSearch(query: query) searchController.performSearch(query: query)
return true return true

View File

@ -20,6 +20,8 @@ enum XCBActionType: String {
case getAccount case getAccount
case getCurrentUser case getCurrentUser
case followUser case followUser
// Search
case search
var path: String { var path: String {
return "/\(rawValue)" return "/\(rawValue)"

View File

@ -314,4 +314,21 @@ struct XCBActions {
getAccount(from: request, session: session, completion: follow) 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)
}
}
} }

View File

@ -21,7 +21,9 @@ class XCBManager {
XCBRequestSpec(type: .showAccount, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: false, action: XCBActions.showAccount), 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: .getAccount, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: false, action: XCBActions.getAccount),
XCBRequestSpec(type: .getCurrentUser, arguments: [:], canRunSilently: false, action: XCBActions.getCurrentUser), 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? static var currentSession: XCBSession?