aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-09-03 09:40:14 +0200
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-09-03 09:40:14 +0200
commit525898871f014120e1dc34ef9bb44787d3443ac6 (patch)
treeab5a6fe810d820b877e23cf8da529939161e328a /lisp
parente7436ad93df6f489eaba4d0a29685e3cf618bb59 (diff)
search--url-lookup
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-search.el20
1 files changed, 20 insertions, 0 deletions
diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el
index 49b5367..4d1a2d3 100644
--- a/lisp/mastodon-search.el
+++ b/lisp/mastodon-search.el
@@ -77,6 +77,26 @@ QUERY is the string to search."
(tags (alist-get 'hashtags response)))
(mapcar #'mastodon-search--get-hashtag-info tags)))
+(defun mastodon-search--url-lookup (&optional query-url)
+ "Do a WebFinger lookup for QUERY-URL.
+If a status or account is found, load it in `mastodon.el', if not, just browse the URL in the normal fashion."
+ (interactive)
+ (let* ((query (or query-url (url-get-url-at-point)))
+ (url (format "%s/api/v2/search" mastodon-instance-url))
+ (param (concat "resolve=t")) ; webfinger
+ (response (mastodon-http--get-search-json url query param)))
+ (if (equal response '((accounts . #1=[]) (statuses . #1#) (hashtags . #1#)))
+ ;; no results
+ ;; browse URL here
+ ()
+ (let ((statuses (assoc 'statuses response))
+ (status-1 (seq-first (cdr statuses)))
+ (status-1-id (alist-get 'id status-1))
+ (accounts (assoc 'accounts response)))
+ ;; TODO: test for a masto URL first?
+ (when status-1
+ (mastodon-tl--single-toot status-1-id))))))
+
;; trending tags