aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-profile.el
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-03-18 21:33:45 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-03-19 13:21:37 +0100
commite0ee8cbfa8e0e883f800ea09dbcff844f988fffb (patch)
tree68fdd0b817c388198a54759f544aacb2ae5908e3 /lisp/mastodon-profile.el
parent135443c63d26d0b77be5370e693aff8643d5078b (diff)
factor grab-profile-json, and handle familiar followers. FIX #404
Diffstat (limited to 'lisp/mastodon-profile.el')
-rw-r--r--lisp/mastodon-profile.el42
1 files changed, 37 insertions, 5 deletions
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index e6f5853..3661615 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -938,15 +938,19 @@ NOTE-OLD is the text of any existing note."
(let ((inhibit-read-only t))
(princ note))))
+(defun mastodon-profile--grab-profile-json ()
+ "Return the profile-json property if we are in a profile buffer."
+ (when (mastodon-tl--profile-buffer-p)
+ (save-excursion
+ (goto-char (point-min))
+ (or (mastodon-tl--property 'profile-json)
+ (error "No profile data found")))))
+
(defun mastodon-profile--add-or-view-private-note (action-fun &optional message view)
"Add or view a private note for an account.
ACTION-FUN does the adding or viewing, MESSAGE is a prompt for
`mastodon-tl--interactive-user-handles-get', VIEW is a flag."
- (let* ((profile-json (when (mastodon-tl--profile-buffer-p)
- (save-excursion
- (goto-char (point-min))
- (or (mastodon-tl--property 'profile-json)
- (error "No profile data found")))))
+ (let* ((profile-json (mastodon-profile--grab-profile-json))
(handle (if (mastodon-tl--profile-buffer-p)
(alist-get 'acct profile-json)
(mastodon-tl--interactive-user-handles-get message)))
@@ -962,5 +966,33 @@ ACTION-FUN does the adding or viewing, MESSAGE is a prompt for
(funcall action-fun note))
(funcall action-fun id handle note))))
+(defun mastodon-profile--show-familiar-followers ()
+ "Show a list of familiar followers.
+Familiar followers are accounts that you follow, and that follow
+the given account."
+ (interactive)
+ (let* ((profile-json (mastodon-profile--grab-profile-json))
+ (handle
+ (if (mastodon-tl--profile-buffer-p)
+ (alist-get 'acct profile-json)
+ (mastodon-tl--interactive-user-handles-get "show familiar followers of")))
+ (account (if (mastodon-tl--profile-buffer-p)
+ profile-json
+ (mastodon-profile--search-account-by-handle handle)))
+ (id (alist-get 'id account)))
+ (mastodon-profile--get-familiar-followers id)))
+
+(defun mastodon-profile--get-familiar-followers (id)
+ "Return JSON data of familiar followers for account ID."
+ ;; the server can handle multiple IDs, but for now we just handle one.
+ (let* ((params `(("id" . ,id)))
+ (url (mastodon-http--api "accounts/familiar_followers"))
+ (json (mastodon-http--get-json url params))
+ (accounts (alist-get 'accounts (car json))) ; first id result
+ (handles (mastodon-tl--map-get-accts accounts))
+ (choice (completing-read "Show profile of user: "
+ handles)))
+ (mastodon-profile--show-user choice)))
+
(provide 'mastodon-profile)
;;; mastodon-profile.el ends here