diff options
author | mousebot <mousebot@riseup.net> | 2022-02-07 16:54:54 +0100 |
---|---|---|
committer | mousebot <mousebot@riseup.net> | 2022-02-07 16:58:12 +0100 |
commit | 4bd42aa4c52d709a512be94524fe1182eac9c4f6 (patch) | |
tree | 4b2ba033d489da28c2f74f215d328cc7edd29dc9 /lisp | |
parent | 7e21eeabc68102e4bae6c5729a69daf5b9e2aca4 (diff) |
implement follow suggestions.
this factors out display of accounts from mastodon-search--search-query into
mastodon-search--insert-users-propertized.
mastodon-tl--get-follow-suggestions is the fun to view suggestions.
seeing as this allows easy display of profile note under the account handle, i
also added this display to --search-query, but it cd be easily disabled by
calling --insert-users-propertized without its second arg.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-search.el | 40 | ||||
-rw-r--r-- | lisp/mastodon-tl.el | 20 |
2 files changed, 45 insertions, 15 deletions
diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 5fee328..6c85965 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -97,19 +97,7 @@ Returns a nested list containing user handle, display name, and URL." " USERS\n" " ------------\n\n") 'success)) - (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" - "\n")) - user-ids) + (mastodon-search--insert-users-propertized user-ids :note) ;; hashtag results: (insert (mastodon-tl--set-face (concat "\n ------------\n" @@ -135,11 +123,33 @@ 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. +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)) + (defun mastodon-search--get-user-info (account) - "Get user handle, display name and account URL from ACCOUNT." + "Get user handle, display name, account URL and profile note from ACCOUNT." (list (alist-get 'display_name account) (alist-get 'acct account) - (alist-get 'url account))) + (alist-get 'url account) + (alist-get 'note account))) (defun mastodon-search--get-hashtag-info (tag) "Get hashtag name and URL from TAG." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index d3ab56b..13c6729 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -60,6 +60,7 @@ ;; make notifications--get available via M-x and outside our keymap: (autoload 'mastodon-notifications--get "mastodon-notifications" "Display NOTIFICATIONS in buffer." t) ; interactive +(autoload 'mastodon-search--insert-users-propertized "mastodon-search") (defvar mastodon-instance-url) (defvar mastodon-toot-timestamp-format) (defvar shr-use-fonts) ;; declare it since Emacs24 didn't have this @@ -991,6 +992,25 @@ webapp" (alist-get 'descendants context))))) (message "No Thread!")))) +(defun mastodon-tl--get-follow-suggestions () +"Display a buffer of suggested accounts to follow." + (interactive) + (let* ((buffer (format "*mastodon-follow-suggestions*")) + (response + (mastodon-http--get-json + (mastodon-http--api "suggestions"))) + (users (mapcar 'mastodon-search--get-user-info response))) + (with-output-to-temp-buffer buffer + (let ((inhibit-read-only t)) + (switch-to-buffer buffer) + (mastodon-mode) + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " SUGGESTED ACCOUNTS\n" + " ------------\n\n") + 'success)) + (mastodon-search--insert-users-propertized users :note))))) + (defun mastodon-tl--follow-user (user-handle &optional notify) "Query for USER-HANDLE from current status and follow that user. If NOTIFY is \"true\", enable notifications when that user posts. |