aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-03-18 21:57:42 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-03-19 13:21:37 +0100
commitd6470dd725c0da74345e1ed8bf40822730e0c004 (patch)
tree0e8bb82e30d1abca9a167dd292c0b6bc55c645e0
parente0ee8cbfa8e0e883f800ea09dbcff844f988fffb (diff)
map-get-accts > map-alist, handle no results for fam folls
use tl--map-alist in views.el
-rw-r--r--lisp/mastodon-profile.el16
-rw-r--r--lisp/mastodon-tl.el29
-rw-r--r--lisp/mastodon-toot.el6
-rw-r--r--lisp/mastodon-views.el8
4 files changed, 23 insertions, 36 deletions
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index 3661615..684b11f 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -70,7 +70,7 @@
(autoload 'mastodon-tl--init "mastodon-tl.el")
(autoload 'mastodon-tl--init-sync "mastodon-tl")
(autoload 'mastodon-tl--interactive-user-handles-get "mastodon-tl")
-(autoload 'mastodon-tl--map-get-accts "mastodon-views")
+(autoload 'mastodon-tl--map-alist "mastodon-tl")
(autoload 'mastodon-tl--profile-buffer-p "mastodon tl")
(autoload 'mastodon-tl--property "mastodon-tl.el")
(autoload 'mastodon-tl--render-text "mastodon-tl.el")
@@ -827,9 +827,7 @@ These include the author, author of reblogged entries and any user mentioned."
'list
(list (alist-get 'acct this-account))
(mastodon-profile--extract-users-handles reblog)
- (mapcar (lambda (mention)
- (alist-get 'acct mention))
- mentions)))))))
+ (mastodon-tl--map-alist 'acct mentions)))))))
(defun mastodon-profile--lookup-account-in-status (handle status)
"Return account for HANDLE using hints in STATUS if possible."
@@ -989,10 +987,12 @@ the given account."
(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)))
+ (handles (mastodon-tl--map-alist 'acct accounts)))
+ (if (null handles)
+ (message "Looks like there are no familiar followers for this account")
+ (let ((choice (completing-read "Show profile of user: "
+ handles)))
+ (mastodon-profile--show-user choice)))))
(provide 'mastodon-profile)
;;; mastodon-profile.el ends here
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 6e80db3..95af2f1 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -489,9 +489,7 @@ image media from the byline."
(defun mastodon-tl--get-media-types (toot)
"Return a list of the media attachment types of the TOOT at point."
(let* ((attachments (mastodon-tl--field 'media_attachments toot)))
- (mapcar (lambda (x)
- (alist-get 'type x))
- attachments)))
+ (mastodon-tl--map-alist 'type attachments)))
(defun mastodon-tl--get-attachments-for-byline (toot)
"Return a list of attachment URLs and types for TOOT.
@@ -1124,9 +1122,7 @@ this just means displaying toot client."
(voters-count (mastodon-tl--field 'voters_count poll))
(vote-count (mastodon-tl--field 'votes_count poll))
(options (mastodon-tl--field 'options poll))
- (option-titles (mapcar (lambda (x)
- (alist-get 'title x))
- options))
+ (option-titles (mastodon-tl--map-alist 'title options))
(longest-option (car (sort option-titles
(lambda (x y)
(> (length x)
@@ -1194,9 +1190,7 @@ this just means displaying toot client."
(poll (or (alist-get 'poll reblog)
(mastodon-tl--field 'poll toot)))
(options (mastodon-tl--field 'options poll))
- (options-titles (mapcar (lambda (x)
- (alist-get 'title x))
- options))
+ (options-titles (mastodon-tl--map-alist 'title options))
(options-number-seq (number-sequence 1 (length options)))
(options-numbers (mapcar #'number-to-string options-number-seq))
(options-alist (cl-mapcar 'cons options-numbers options-titles))
@@ -1504,11 +1498,11 @@ timeline."
;;; UTILITIES
-;; consider having this return an id / acct alist
-(defun mastodon-tl--map-get-accts (alist)
- "Return a list of handles from ALIST."
+(defun mastodon-tl--map-alist (key alist)
+ "Return a list of values extracted from ALIST with KEY.
+Key is a symbol, as with `alist-get'."
(mapcar (lambda (x)
- (alist-get 'acct x))
+ (alist-get key x))
alist))
(defun mastodon-tl--symbol (name)
@@ -1973,9 +1967,8 @@ If TAG provided, follow it."
If TAG is provided, unfollow it."
(interactive)
(let* ((followed-tags-json (unless tag (mastodon-tl--followed-tags)))
- (tags (unless tag (mapcar (lambda (x)
- (alist-get 'name x))
- followed-tags-json)))
+ (tags (unless tag
+ (mastodon-tl--map-alist 'name followed-tags-json)))
(tag (or tag (completing-read "Unfollow tag: "
tags)))
(url (mastodon-http--api (format "tags/%s/unfollow" tag)))
@@ -1988,9 +1981,7 @@ If TAG is provided, unfollow it."
"List followed tags. View timeline of tag user choses."
(interactive)
(let* ((followed-tags-json (mastodon-tl--followed-tags))
- (tags (mapcar (lambda (x)
- (alist-get 'name x))
- followed-tags-json))
+ (tags (mastodon-tl--map-alist 'name followed-tags-json))
(tag (completing-read "Tag: " tags)))
(mastodon-tl--get-tag-timeline tag)))
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 1d91f84..df9a22c 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -75,7 +75,7 @@
(autoload 'mastodon-tl--find-property-range "mastodon-tl")
(autoload 'mastodon-tl--find-property-range "mastodon-tl")
(autoload 'mastodon-tl--goto-next-toot "mastodon-tl")
-(autoload 'mastodon-tl--map-get-accts "mastodon-views")
+(autoload 'mastodon-tl--map-alist "mastodon-tl")
(autoload 'mastodon-tl--property "mastodon-tl")
(autoload 'mastodon-tl--reload-timeline-or-profile "mastodon-tl")
(autoload 'mastodon-tl--render-text "mastodon-tl")
@@ -451,7 +451,7 @@ With FAVOURITE, list favouriters, else list boosters."
(if (eq (caar json) 'error)
(error "%s (Status does not exist or is private)"
(alist-get 'error json))
- (let ((handles (mastodon-tl--map-get-accts json))
+ (let ((handles (mastodon-tl--map-alist 'acct json))
(type-string (if favourite "Favouriters" "Boosters")))
(if (not handles)
(error "Looks like this toot has no %s" type-string)
@@ -921,7 +921,7 @@ Federated user: `username@host.co`."
(alist-get 'mentions (alist-get 'reblog status))
(alist-get 'mentions status))))
;; reverse does not work on vectors in 24.5
- (mastodon-tl--map-get-accts (reverse mentions))))
+ (mastodon-tl--map-alist 'acct (reverse mentions))))
(defun mastodon-toot--get-bounds (regex)
"Get bounds of tag or handle before point using REGEX."
diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el
index e38455b..f92a9aa 100644
--- a/lisp/mastodon-views.el
+++ b/lisp/mastodon-views.el
@@ -219,9 +219,7 @@ provides the JSON data."
(defun mastodon-views--print-list-set (lists)
"Print each account plus a separator for each list in LISTS."
(let ((lists-names
- (mapcar (lambda (x)
- (alist-get 'title x))
- lists)))
+ (mastodon-tl--map-alist 'title lists)))
(mapc (lambda (x)
(mastodon-views--print-list-accounts x)
(insert (propertize " ------------\n\n"
@@ -266,9 +264,7 @@ a: add account to this list, r: remove account from this list"
(defun mastodon-views--get-lists-names ()
"Return a list of the user's lists' names."
(let ((lists (mastodon-views--get-users-lists)))
- (mapcar (lambda (x)
- (alist-get 'title x))
- lists)))
+ (mastodon-tl--map-alist 'title lists)))
(defun mastodon-views--get-list-by-name (name)
"Return the list data for list with NAME."