From c8a9683b61a207bf38fd76e337bf22a814b6cbf2 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 24 Nov 2022 17:57:51 +0100 Subject: draft remove-from-followers --- lisp/mastodon-profile.el | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index fa9642e..8cea4d7 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -822,5 +822,54 @@ 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) + (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 (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 "Remove follower %s? " handle) + (let ((response (mastodon-http--post url))) + (mastodon-http--triage (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." + (let* ((handles + (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json))) + (handle (completing-read "Handle to unfollow: " + handles)) + (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 -- cgit v1.2.3 From fc28851921af66ad56829fc06cd217c4b1335d26 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 25 Nov 2022 17:41:06 +0100 Subject: actually make remove-from-followers work --- lisp/mastodon-profile.el | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index d6b2b94..801ebd4 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -849,7 +849,7 @@ account ('toot-json) at point if you are on your own profile page (followers)." ;; FIXME: do some thing else? (get-text-property (point) 'toot-json))))) ;; TODO: read account from list of all followers' handles - (id (or (alist-get 'id account))) + (id (or id (alist-get 'id account))) (handle (if account (alist-get 'acct account) (let ((account @@ -857,17 +857,18 @@ account ('toot-json) at point if you are on your own profile page (followers)." (alist-get 'acct account)))) (url (mastodon-http--api (format "accounts/%s/remove_from_followers" id)))) - (when (y-or-n-p "Remove follower %s? " handle) + (when (y-or-n-p (format "Remove follower %s? " handle)) (let ((response (mastodon-http--post url))) - (mastodon-http--triage (lambda () + (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." - (let* ((handles - (mastodon-profile--extract-users-handles - (mastodon-profile--toot-json))) - (handle (completing-read "Handle to unfollow: " + (interactive) + (let* ((handles (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json))) + (handle (completing-read "Remove from followers: " handles)) (account (mastodon-profile--lookup-account-in-status handle (mastodon-profile--toot-json))) -- cgit v1.2.3 From 593ad71b2c331d6aeb24dcfb943d4cc435e36bf3 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 25 Nov 2022 17:45:53 +0100 Subject: don't require match for handle at point --- lisp/mastodon-profile.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 801ebd4..d9b45c8 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -830,6 +830,7 @@ These include the author, author of reblogged entries and any user mentioned." 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 @@ -869,7 +870,7 @@ account ('toot-json) at point if you are on your own profile page (followers)." (let* ((handles (mastodon-profile--extract-users-handles (mastodon-profile--toot-json))) (handle (completing-read "Remove from followers: " - handles)) + handles nil)) (account (mastodon-profile--lookup-account-in-status handle (mastodon-profile--toot-json))) (id (alist-get 'id account))) -- cgit v1.2.3 From b6dd92225bfef4bfdbc229791d1c863335d2f403 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 28 Nov 2022 14:25:54 +0100 Subject: simplify remove from followers --- lisp/mastodon-profile.el | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 36042e7..c2c58f6 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -845,25 +845,7 @@ These include the author, author of reblogged entries and any user mentioned." 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))))) + (let* ((account (unless id (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 -- cgit v1.2.3 From e8797f4769248ab79bab4e30548b4796eefd2520 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 28 Nov 2022 14:39:59 +0100 Subject: add remove-from-followers via list of 100 followers. --- lisp/mastodon-profile.el | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index c2c58f6..d0b7179 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -77,6 +77,7 @@ (autoload 'mastodon-tl--get-link-header-from-response "mastodon-tl") (autoload 'mastodon-tl--set-buffer-spec "mastodon-tl") (autoload 'mastodon-tl--symbol "mastodon-tl") +(autoload 'mastodon-auth--get-account-id "mastodon-auth") (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) @@ -575,14 +576,14 @@ NO-REBLOGS means do not display boosts in statuses. HEADERS means also fetch link headers for pagination." (let* ((id (mastodon-profile--account-field account 'id)) (args (when no-reblogs '(("exclude_reblogs" . "t")))) - (url (mastodon-http--api (format "accounts/%s/%s" id endpoint-type))) + (endpoint (format "accounts/%s/%s" id endpoint-type)) + (url (mastodon-http--api endpoint)) (acct (mastodon-profile--account-field account 'acct)) (buffer (concat "*mastodon-" acct "-" endpoint-type "*")) (response (if headers (mastodon-http--get-response url args) (mastodon-http--get-json url args))) (json (if headers (car response) response)) - (endpoint (format "accounts/%s/%s" id endpoint-type)) (link-header (when headers (mastodon-tl--get-link-header-from-response (cdr response)))) @@ -842,11 +843,9 @@ These include the author, author of reblogged entries and any user mentioned." (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)." +Optionally provide the ID of the account to remove." (interactive) (let* ((account (unless id (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) @@ -861,8 +860,8 @@ account ('toot-json) at point if you are on your own profile page (followers)." (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." +(defun mastodon-profile--remove-from-followers-at-point () + "Prompt for a user in the item at point and remove from followers." (interactive) (let* ((handles (mastodon-profile--extract-users-handles (mastodon-profile--toot-json))) @@ -873,5 +872,25 @@ account ('toot-json) at point if you are on your own profile page (followers)." (id (alist-get 'id account))) (mastodon-profile--remove-user-from-followers id))) +(defun mastodon-profile--remove-from-followers-list () + "Select a user from your followers and remove from followers. +Currently limited to 100 handles. If not found, try +`mastodon-search--search-query'." + (interactive) + (let* ((endpoint (format "accounts/%s/followers" + (mastodon-auth--get-account-id))) + (url (mastodon-http--api endpoint)) + (response (mastodon-http--get-json url + `(("limit" . "100")))) + (handles (mapcar (lambda (x) + (cons + (alist-get 'acct x) + (alist-get 'id x))) + response)) + (choice (completing-read "Remove from followers: " + handles)) + (id (alist-get choice handles nil nil 'equal))) + (mastodon-profile--remove-user-from-followers id))) + (provide 'mastodon-profile) ;;; mastodon-profile.el ends here -- cgit v1.2.3