aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-profile.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/mastodon-profile.el')
-rw-r--r--lisp/mastodon-profile.el51
1 files changed, 51 insertions, 0 deletions
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index babe308..36042e7 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -840,5 +840,56 @@ These include the author, author of reblogged entries and any user mentioned."
(t
(mastodon-profile--search-account-by-handle handle)))))
+(defun mastodon-profile--remove-user-from-followers (&optional id)
+ "Remove a user from your followers.
+User may be the current profile page if not your own, or the
+account ('toot-json) at point if you are on your own profile page (followers)."
+ (interactive)
+ ;; FIXME: this means you can't choose another account if on a profile page
+ (let* ((account (unless id
+ (cond ((and ;; we are on a profile page
+ mastodon-profile--account
+ ;; that is not our own:
+ (not (string= (mastodon-auth--user-acct)
+ (alist-get 'acct mastodon-profile--account))))
+ mastodon-profile--account)
+ ;; we are on our own profile page:
+ ((and (string= (mastodon-auth--user-acct)
+ (alist-get 'acct mastodon-profile--account))
+ ;; viewing our followers:
+ (string= endpoint-type "followers"))
+ ;; try for a follower at point:
+ ;; (mastodon-tl--field 'toot-json)
+ (get-text-property (point) 'toot-json))
+ (t
+ ;; FIXME: do some thing else?
+ (get-text-property (point) 'toot-json)))))
+ ;; TODO: read account from list of all followers' handles
+ (id (or id (alist-get 'id account)))
+ (handle (if account
+ (alist-get 'acct account)
+ (let ((account
+ (mastodon-profile--account-from-id id)))
+ (alist-get 'acct account))))
+ (url (mastodon-http--api
+ (format "accounts/%s/remove_from_followers" id))))
+ (when (y-or-n-p (format "Remove follower %s? " handle))
+ (let ((response (mastodon-http--post url)))
+ (mastodon-http--triage response
+ (lambda ()
+ (message "Follower %s removed!" handle)))))))
+
+(defun mastodon-profile--remove-from-followers-toot-at-point ()
+ "Prompt for a user in the toot at point and remove from followers."
+ (interactive)
+ (let* ((handles (mastodon-profile--extract-users-handles
+ (mastodon-profile--toot-json)))
+ (handle (completing-read "Remove from followers: "
+ handles nil))
+ (account (mastodon-profile--lookup-account-in-status
+ handle (mastodon-profile--toot-json)))
+ (id (alist-get 'id account)))
+ (mastodon-profile--remove-user-from-followers id)))
+
(provide 'mastodon-profile)
;;; mastodon-profile.el ends here