From f43dd731e9d6b882cf687c44ef1b5631309bd3b9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 3 Sep 2022 12:42:31 +0200 Subject: move url-lookup to mastodon.el --- lisp/mastodon-tl.el | 31 +------------------------------ lisp/mastodon.el | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 30 deletions(-) (limited to 'lisp') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 113bd11..4b0bd9f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -143,7 +143,7 @@ etc.") (define-key map [remap shr-previous-link] 'mastodon-tl--previous-tab-item) ;; keep new my-profile binding; shr 'O' doesn't work here anyway (define-key map (kbd "O") 'mastodon-profile--my-profile) - (define-key map [remap shr-browse-url] 'mastodon-tl--url-lookup) + (define-key map [remap shr-browse-url] 'mastodon-url-lookup) (keymap-canonicalize map)) "The keymap to be set for shr.el generated links that are not images. @@ -689,35 +689,6 @@ START and END are the boundaries of the link in the toot." 'help-echo help-echo) extra-properties)))) -;; URL lookup: should be available even if `mastodon.el' not loaded: - -;;;###autoload -(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) - (message "Performing lookup...") - (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 :silent))) - (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)) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 96faf56..5c2bc34 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -264,6 +264,34 @@ If REPLY-JSON is the json of the toot being replied to." (interactive) (mastodon-toot--compose-buffer user reply-to-id reply-json)) +;; URL lookup: should be available even if `mastodon.el' not loaded: + +;;;###autoload +(defun mastodon-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) + (message "Performing lookup...") + (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 :silent))) + (if (equal response '((accounts . #1=[]) (statuses . #1#) (hashtags . #1#))) + (shr-browse-url query-url) + (cond ((not (seq-empty-p + (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 (seq-empty-p + (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))))))) + ;;;###autoload (add-hook 'mastodon-mode-hook (lambda () (when (require 'emojify nil :noerror) -- cgit v1.2.3