Skip to content

Commit

Permalink
tl--url-lookup command, FIX mooseyboots#240
Browse files Browse the repository at this point in the history
  • Loading branch information
marty hiatt committed Sep 3, 2022
1 parent 5258988 commit 8842e77
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
21 changes: 0 additions & 21 deletions lisp/mastodon-search.el
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,6 @@ 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

(defun mastodon-search--trending-tags ()
Expand Down
25 changes: 25 additions & 0 deletions lisp/mastodon-tl.el
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,31 @@ START and END are the boundaries of the link in the toot."
'help-echo help-echo)
extra-properties))))

(defun mastodon-tl--url-lookup (&optional query-url)
"Do a WebFinger lookup for QUERY-URL, or the URL at point.
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#)))
(shr-browse-url query-url)
(cond ((not (equal '[]
(alist-get 'statuses response)))
(let* ((statuses (assoc 'statuses response))
(status (seq-first (cdr statuses)))
(status-id (alist-get 'id status)))
(mastodon-tl--thread status-id)))
((not (equal '[]
(alist-get 'accounts response)))
(let* ((accounts (assoc 'accounts response))
(account (seq-first (cdr accounts)))
(account-id (alist-get 'id account)))
(mastodon-profile--account-from-id account-id)))))))


(defun mastodon-tl--extract-userid-toot (toot acct)
"Extract a user id for an ACCT from mentions in a TOOT."
(let* ((mentions (append (alist-get 'mentions toot) nil))
Expand Down

0 comments on commit 8842e77

Please sign in to comment.