From 606fbfc26a620f76bedea1d7bf033aea9690ead5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Nov 2022 14:09:57 +0100 Subject: 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. --- lisp/mastodon-tl.el | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-tl.el') 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)) -- cgit v1.2.3