diff options
author | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2022-11-11 14:09:57 +0100 |
---|---|---|
committer | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2022-11-11 14:46:24 +0100 |
commit | 606fbfc26a620f76bedea1d7bf033aea9690ead5 (patch) | |
tree | ba5c11ff5ea1370aaa4fc8eeea0a7a8497da44c4 /lisp/mastodon-tl.el | |
parent | e0179b9ae26bcb7481959634b9ef91891c2a72eb (diff) |
Fetch user handles from mentions in JSON where possible.
Fixes an issue where handles with subomain-hiding aliases would have broken
links because they are fetched from the URL, which includes the subdomain.
we sill use url extracting as a fallback, but it's probably not needed/useless.
Diffstat (limited to 'lisp/mastodon-tl.el')
-rw-r--r-- | lisp/mastodon-tl.el | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b0baa70..9413a18 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -659,8 +659,15 @@ START and END are the boundaries of the link in the toot." mastodon-instance-url)) (maybe-hashtag (mastodon-tl--extract-hashtag-from-url url toot-instance-url)) - (maybe-userhandle (mastodon-tl--extract-userhandle-from-url - url (buffer-substring-no-properties start end)))) + (maybe-userhandle + (if (not (listp toot)) ; fails for profile buffers + (or (mastodon-tl--userhandle-from-mentions toot + (buffer-substring-no-properties start end)) + ;; FIXME: if prev always works, cut this: + (mastodon-tl--extract-userhandle-from-url + url (buffer-substring-no-properties start end))) + (mastodon-tl--extract-userhandle-from-url + url (buffer-substring-no-properties start end))))) (cond (;; Hashtags: maybe-hashtag (setq mastodon-tab-stop-type 'hashtag @@ -696,6 +703,23 @@ START and END are the boundaries of the link in the toot." 'help-echo help-echo) extra-properties)))) +;; TODO: refactor --userhandle-from-mentions and --extract-userid-toot +(defun mastodon-tl--userhandle-from-mentions (toot link) + "Extract a user handle from mentions in json TOOT. +LINK is the '@handle' to search for." + ;; TODO: ensure this doesn't error and returns nil if it doesn't work + ;; so that the 'or' that it is called in uses the following fallback + (let* ((mentions (append (alist-get 'mentions toot) nil)) ; alist + (mention (pop mentions)) + (name (substring-no-properties link 1)) ; cull @ + handle) + (while mention + (when (string= (alist-get 'username mention) + name) + (setq handle (alist-get 'acct mention))) + (setq mention (pop mentions))) + handle)) + (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)) |