aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-03-18 22:17:45 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-03-19 13:21:37 +0100
commit5d62213b4f8f92cb974c24c4ab0fc373fe806115 (patch)
treebaf36c533fe7e81538c7428408266a6026401b78
parentd6470dd725c0da74345e1ed8bf40822730e0c004 (diff)
refactor tl--map-alist-to-alist
-rw-r--r--lisp/mastodon-profile.el11
-rw-r--r--lisp/mastodon-tl.el8
-rw-r--r--lisp/mastodon-views.el10
3 files changed, 12 insertions, 17 deletions
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index 684b11f..b77bdac 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -540,10 +540,7 @@ FIELDS means provide a fields vector fetched by other means."
(let ((fields (or fields
(mastodon-profile--account-field account 'fields))))
(when fields
- (mapcar (lambda (el)
- (cons (alist-get 'name el)
- (alist-get 'value el)))
- fields))))
+ (mastodon-tl-map-alist-to-alist 'name 'value fields))))
(defun mastodon-profile--fields-insert (fields)
"Format and insert field pairs (a.k.a profile metadata) in FIELDS."
@@ -891,11 +888,7 @@ Currently limited to 100 handles. If not found, try
(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))
+ (handles (mastodon-tl-map-alist-to-alist 'acct 'id response))
(choice (completing-read "Remove from followers: "
handles))
(id (alist-get choice handles nil nil 'equal)))
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 95af2f1..91619f1 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1505,6 +1505,14 @@ Key is a symbol, as with `alist-get'."
(alist-get key x))
alist))
+(defun mastodon-tl-map-alist-to-alist (key1 key2 alist)
+ "From ALIST, return an alist consisting of (val1 . val2) elements.
+Values are accessed by `alist-get', using KEY1 and KEY2."
+ (mapcar (lambda (x)
+ (cons (alist-get key1 x)
+ (alist-get key2 x)))
+ alist))
+
(defun mastodon-tl--symbol (name)
"Return the unicode symbol (as a string) corresponding to NAME.
If symbol is not displayable, an ASCII equivalent is returned. If
diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el
index f92a9aa..d3865bc 100644
--- a/lisp/mastodon-views.el
+++ b/lisp/mastodon-views.el
@@ -398,10 +398,7 @@ If ACCOUNT-ID and HANDLE are provided use them rather than prompting."
(mastodon-views--get-lists-names) nil t)))
(list-id (or id (mastodon-views--get-list-id list-name)))
(followings (mastodon-views--get-users-followings))
- (handles (mapcar (lambda (x)
- (cons (alist-get 'acct x)
- (alist-get 'id x)))
- followings))
+ (handles (mastodon-tl-map-alist-to-alist 'acct 'id followings))
(account (or handle (completing-read "Account to add: "
handles nil t)))
(account-id (or account-id (alist-get account handles nil nil 'equal)))
@@ -437,10 +434,7 @@ If ID is provided, use that list."
(mastodon-views--get-lists-names) nil t)))
(list-id (or id (mastodon-views--get-list-id list-name)))
(accounts (mastodon-views--accounts-in-list list-id))
- (handles (mapcar (lambda (x)
- (cons (alist-get 'acct x)
- (alist-get 'id x)))
- accounts))
+ (handles (mastodon-tl-map-alist-to-alist 'acct 'id accounts))
(account (completing-read "Account to remove: "
handles nil t))
(account-id (alist-get account handles nil nil 'equal))