From 083b085ebce6753001c8fe6798f5f44f2c3971c1 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 8 May 2021 10:06:28 +0200 Subject: re-write follow-user fun with completing read --- lisp/mastodon-tl.el | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index d271243..14623e6 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -798,19 +798,27 @@ webapp" (lambda () (message "Toot deleted! There may be a delay before it disappears from your profile.")))))) -;; follow user at point: -;; try to make it work only for toot user id first, then try to allow mentions/boosts -(defun mastodon-tl--follow-user () - "Follow author OR BOOSTER! of toot at point synchronously." - (interactive) - (let* ((account - (cdr (assoc 'account (mastodon-profile--toot-json)))) ; acc data from toot - (user-id (mastodon-profile--account-field account 'id)) ; id from acc +(defun mastodon-tl--follow-user (user-handle) + "Query user for user id from current status and follow that user." + (interactive + (list + (let ((user-handles (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json)))) + (completing-read "User handle: " + user-handles + nil ; predicate + 'confirm)))) + (let* ((account (mastodon-profile--lookup-account-in-status + user-handle (mastodon-profile--toot-json))) + (user-id (mastodon-profile--account-field account 'id)) + (name (mastodon-profile--account-field account 'display_name)) (url (mastodon-http--api (format "accounts/%s/follow" user-id)))) - (let ((response (mastodon-http--post url nil nil))) - (mastodon-http--triage response - (lambda () - (message "User ID %s followed!" user-id)))))) ; TODO: use handle + (if account + (let ((response (mastodon-http--post url nil nil))) + (mastodon-http--triage response + (lambda () + (message "User %s (@%s) followed!" name user-handle)))) + (message "Cannot find a user with handle %S" user-handle)))) (defun mastodon-tl--more () "Append older toots to timeline." -- cgit v1.2.3