diff options
author | mousebot <mousebot@riseup.net> | 2022-02-15 21:55:10 +0100 |
---|---|---|
committer | mousebot <mousebot@riseup.net> | 2022-02-17 09:50:03 +0100 |
commit | 1c0328ced821b152e3da911592a6acd12d8598dd (patch) | |
tree | 97750344e739748fddef44184ade8b4adfcceadb /lisp | |
parent | f545d8c1d65e3e2256f8b769bfdb87a5b6a1e3ea (diff) |
re-factor follow-user functions for various views
- revert profile--extract-users-handles
- rewrite search--insert-users-propertized to handle raw account JSON, and to
call search--get-user-info itself, so we can add full acct JSON to each user
displayed and use it for follow-user etc.
- and to choose how we want to follow users, we edit
tl--interactive-user-handles-get to work differently depending on context:
- poss contexts are "follow suggestions" view, search results, and profiles
displaying a user's followers/followed users.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-profile.el | 11 | ||||
-rw-r--r-- | lisp/mastodon-search.el | 48 | ||||
-rw-r--r-- | lisp/mastodon-tl.el | 15 |
3 files changed, 43 insertions, 31 deletions
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 8388d05..5504065 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -463,14 +463,9 @@ If the handle does not match a search return then retun NIL." These include the author, author of reblogged entries and any user mentioned." (when status - (let ((this-account - ;; follow suggestions view compat: - (if (or (equal (buffer-name) "*mastodon-follow-suggestions*") - (string-prefix-p "accounts" (mastodon-tl--get-endpoint))) - (mastodon-tl--property 'toot-json) - (alist-get 'account status))) - (mentions (alist-get 'mentions status)) - (reblog (alist-get 'reblog status))) + (let ((this-account (alist-get 'account status)) + (mentions (alist-get 'mentions status)) + (reblog (alist-get 'reblog status))) (seq-filter 'stringp (seq-uniq diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index d17b054..726b76e 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -89,16 +89,16 @@ Returns a nested list containing user handle, display name, and URL." status-ids-list))) (with-current-buffer (get-buffer-create buffer) (switch-to-buffer buffer) - (erase-buffer) (mastodon-mode) (let ((inhibit-read-only t)) + (erase-buffer) ;; user results: (insert (mastodon-tl--set-face (concat "\n ------------\n" " USERS\n" " ------------\n\n") 'success)) - (mastodon-search--insert-users-propertized user-ids :note) + (mastodon-search--insert-users-propertized accts :note) ;; hashtag results: (insert (mastodon-tl--set-face (concat "\n ------------\n" @@ -124,26 +124,34 @@ Returns a nested list containing user handle, display name, and URL." (mapc 'mastodon-tl--toot toots-list-json) (goto-char (point-min)))))) -(defun mastodon-search--insert-users-propertized (users &optional note) - "Insert USERS list into the buffer. +(defun mastodon-search--insert-users-propertized (json &optional note) + "Insert users list into the buffer. +JSON is the data from the server.. If NOTE is non-nil, include user's profile note. This is also called by `mastodon-tl--get-follow-suggestions'." - (mapc (lambda (el) - (insert (propertize (car el) 'face 'mastodon-display-name-face) - " : \n : " - (propertize (concat "@" (car (cdr el))) - 'face 'mastodon-handle-face - 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle - 'keymap mastodon-tl--link-keymap - 'mastodon-handle (concat "@" (car (cdr el))) - 'help-echo (concat "Browse user profile of @" (car (cdr el)))) - " : \n" - (if note - (mastodon-tl--render-text (cadddr el) nil) - "") - "\n")) - users)) + (mapc (lambda (acct) + (let ((user (mastodon-search--get-user-info acct))) + (insert + (propertize + (concat (propertize (car user) + 'face 'mastodon-display-name-face + 'byline t + 'toot-id "0") + " : \n : " + (propertize (concat "@" (cadr user)) + 'face 'mastodon-handle-face + 'mouse-face 'highlight + 'mastodon-tab-stop 'user-handle + 'keymap mastodon-tl--link-keymap + 'mastodon-handle (concat "@" (cadr user)) + 'help-echo (concat "Browse user profile of @" (cadr user))) + " : \n" + (if note + (mastodon-tl--render-text (cadddr user) nil) + "") + "\n") + 'user-json acct)))) + json)) (defun mastodon-search--get-user-info (account) "Get user handle, display name, account URL and profile note from ACCOUNT." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ec9c033..6bb5656 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1253,7 +1253,7 @@ RESPONSE is the JSON returned by the server." " SUGGESTED ACCOUNTS\n" " ------------\n\n") 'success)) - (mastodon-search--insert-users-propertized users :note) + (mastodon-search--insert-users-propertized response :note) (goto-char (point-min)))) (defun mastodon-tl--follow-user (user-handle &optional notify) @@ -1321,8 +1321,17 @@ Can be called to toggle NOTIFY on users already being followed." (defun mastodon-tl--interactive-user-handles-get (action) "Get the list of user-handles for ACTION from the current toot." - (let ((user-handles (mastodon-profile--extract-users-handles - (mastodon-profile--toot-json)))) + (let ((user-handles + ;; follow suggests / search compat: + (cond ((or (equal (buffer-name) "*mastodon-follow-suggestions*") + (string-prefix-p "*mastodon-search" (buffer-name))) + (list (alist-get 'acct (mastodon-tl--property 'user-json)))) + ;; profile view follows/followers compat: + ((string-prefix-p "accounts" (mastodon-tl--get-endpoint)) + (list (alist-get 'acct (mastodon-tl--property 'toot-json)))) + (t + (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json)))))) (completing-read (if (or (equal action "disable") (equal action "enable")) (format "%s notifications when user posts: " action) |