Browse Source

Add X-Callback-URL for search

pixelfed
Shadowfacts 9 months ago
parent
commit
e17e00583f
Signed by: Shadowfacts <me@shadowfacts.net> GPG Key ID: 94A5AB95422746E5

+ 17
- 0
Documentation/X-Callback-URL.md View File

@@ -69,6 +69,8 @@ Dates in responses are encoded as Unix timestamps.
69 69
   - [`dismissAllNotifications`](#dismissallnotifications)
70 70
 - [Instances](#instances)
71 71
   - [`getCurrentInstance`](#getcurrentinstance)
72
+- [Misc](#misc)
73
+  - [`search`](#search)
72 74
 
73 75
 ### Accounts
74 76
 
@@ -336,3 +338,18 @@ No parameters.
336 338
 | `description` (string)    | The instance description                                | No       |
337 339
 | `contactAccount` (string) | The instance-local ID of the instance's contact account | No       |
338 340
 
341
+
342
+### Misc
343
+
344
+#### `search`
345
+Performs a search in Tusker with the given query
346
+
347
+##### Request
348
+
349
+| Parameter (type) | Description              | Optional |
350
+| ---------------- | ------------------------ |--------- |
351
+| `query` (string) | The search query to use. | No       |
352
+
353
+##### Response
354
+
355
+No data if successful.

+ 1
- 1
Tusker/AppDelegate.swift View File

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

+ 2
- 0
Tusker/XCallbackURL/XCBActionType.swift View File

@@ -20,6 +20,8 @@ enum XCBActionType: String {
20 20
     case getAccount
21 21
     case getCurrentUser
22 22
     case followUser
23
+    // Search
24
+    case search
23 25
     
24 26
     var path: String {
25 27
         return "/\(rawValue)"

+ 17
- 0
Tusker/XCallbackURL/XCBActions.swift View File

@@ -314,4 +314,21 @@ struct XCBActions {
314 314
         
315 315
         getAccount(from: request, session: session, completion: follow)
316 316
     }
317
+    
318
+    // MARK: - Search
319
+    
320
+    static func search(_ request: XCBRequest, _ session: XCBSession, _ silent: Bool?) {
321
+        let query = request.arguments["query"]!
322
+        
323
+        if let tabBarController = UIApplication.shared.keyWindow?.rootViewController as? UITabBarController,
324
+            let navigationController = tabBarController.viewControllers?[3] as? UINavigationController,
325
+            let searchController = navigationController.viewControllers.first as? SearchTableViewController {
326
+            tabBarController.selectedIndex = 3
327
+            navigationController.popToRootViewController(animated: false)
328
+            searchController.searchController.searchBar.text = query
329
+            searchController.performSearch(query: query)
330
+        } else {
331
+            session.complete(with: .error)
332
+        }
333
+    }
317 334
 }

+ 3
- 1
Tusker/XCallbackURL/XCBManager.swift View File

@@ -21,7 +21,9 @@ class XCBManager {
21 21
         XCBRequestSpec(type: .showAccount, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: false, action: XCBActions.showAccount),
22 22
         XCBRequestSpec(type: .getAccount, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: false, action: XCBActions.getAccount),
23 23
         XCBRequestSpec(type: .getCurrentUser, arguments: [:], canRunSilently: false, action: XCBActions.getCurrentUser),
24
-        XCBRequestSpec(type: .followUser, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: true, action: XCBActions.followUser)
24
+        XCBRequestSpec(type: .followUser, arguments: ["accountID": true, "accountURL": true, "acct": true], canRunSilently: true, action: XCBActions.followUser),
25
+        // Search
26
+        XCBRequestSpec(type: .search, arguments: ["query": false], canRunSilently: false, action: XCBActions.search),
25 27
     ]
26 28
     
27 29
     static var currentSession: XCBSession?

Loading…
Cancel
Save