Browse Source

Add X-Callback-URL for search

pixelfed
Shadowfacts 2 years ago
parent
commit
e17e00583f
Signed by: shadowfacts GPG Key ID: 94A5AB95422746E5
  1. 17
      Documentation/X-Callback-URL.md
  2. 2
      Tusker/AppDelegate.swift
  3. 2
      Tusker/XCallbackURL/XCBActionType.swift
  4. 17
      Tusker/XCallbackURL/XCBActions.swift
  5. 4
      Tusker/XCallbackURL/XCBManager.swift

17
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.

2
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

2
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)"

17
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)
}
}
}

4
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?

Loading…
Cancel
Save