diff options
author | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2023-10-13 16:00:16 +0200 |
---|---|---|
committer | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2023-10-13 16:00:16 +0200 |
commit | e0b2f1a5eb1dab3b99f974b030bdbb866bd48dae (patch) | |
tree | 36aed30830ffdfafe0d0b1c1127a26bc136478e0 | |
parent | 3e0badc4af1b128e139d833f29cdc5ee643973cf (diff) |
mastodon-http--api-search fun (search uses api v2)
-rw-r--r-- | lisp/mastodon-http.el | 4 | ||||
-rw-r--r-- | lisp/mastodon-search.el | 9 | ||||
-rw-r--r-- | lisp/mastodon-tl.el | 4 |
3 files changed, 10 insertions, 7 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 8741972..33f6012 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -53,6 +53,10 @@ (concat mastodon-instance-url "/api/" mastodon-http--api-version "/" endpoint)) +(defun mastodon-http--api-search () + "Return Mastodon API url for the /search endpoind (v2)." + (format "%s/api/v2/search" mastodon-instance-url)) + (defun mastodon-http--response () "Capture response buffer content as string." (with-current-buffer (current-buffer) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 436041d..602df8d 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -76,7 +76,7 @@ Returns a nested list containing user handle, display name, and URL." (defun mastodon-search--search-tags-query (query) "Return an alist containing tag strings plus their URLs. QUERY is the string to search." - (let* ((url (format "%s/api/v2/search" mastodon-instance-url)) + (let* ((url (mastodon-http--api-search)) (params `(("q" . ,query) ("type" . "hashtags"))) (response (mastodon-http--get-json url params :silent)) (tags (alist-get 'hashtags response))) @@ -152,10 +152,9 @@ TYPE is a member of `mastodon-search-types'. FOLLOWING means limit to accounts followed, for \"accounts\" type only. A single prefix arg also sets FOLLOWING to true. ACCOUNT-ID means limit search to that account, for \"statuses\" type only." - ;; TODO: handle account search, buffer name etc. ;; TODO: handle no results (interactive "sSearch mastodon for: ") - (let* ((url (format "%s/api/v2/search" mastodon-instance-url)) + (let* ((url (mastodon-http--api-search)) (following (when (or following (equal current-prefix-arg '(4))) "true")) @@ -180,8 +179,6 @@ ACCOUNT-ID means limit search to that account, for \"statuses\" type only." (alist-get 'statuses response))) (tags-list (when tags (mapcar #'mastodon-search--get-hashtag-info tags)))) - ;; (toots-list-json (when statuses ; v slow, but do we have a choice? - ;; (mastodon-search--get-full-statuses-data statuses)))) (with-mastodon-buffer buffer #'mastodon-mode nil (mastodon-search-mode) (mastodon-tl--set-buffer-spec buffer "api/v2/search" nil @@ -197,7 +194,7 @@ ACCOUNT-ID means limit search to that account, for \"statuses\" type only." ;; status results: (when statuses (mastodon-search--format-heading "STATUSES") - (mapc #'mastodon-tl--toot statuses)) ;toots-list-json)) + (mapc #'mastodon-tl--toot statuses)) (goto-char (point-min)) (message (substitute-command-keys diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 25ffcd7..d32b806 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2249,7 +2249,9 @@ PARAMS is used to send any parameters needed to correctly update the current view." (let* ((args `(("max_id" . ,(mastodon-tl--as-string id)))) (args (if params (push (car args) params) args)) - (url (mastodon-http--api endpoint))) + (url (if (string-suffix-p "search" endpoint) + (mastodon-http--api-search) + (mastodon-http--api endpoint)))) (apply #'mastodon-http--get-json-async url args callback cbargs))) (defun mastodon-tl--updated-json (endpoint id &optional params) |