aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-19 11:53:23 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-19 11:53:23 +0100
commit82e0ee3f7526f455485acd833c816362722a501a (patch)
treeb77db5d48b9bf38ae819f729be1b8960e6282a1b /lisp
parentf49ef7a5647fadc64e3f8af3abce7c95454fe04b (diff)
lists refactor response triage
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-tl.el45
1 files changed, 23 insertions, 22 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 4ef6b47..f7c8b7f 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1497,12 +1497,9 @@ Prompt for name and replies policy."
`(("title" . ,title)
("replies_policy" . ,replies-policy))
nil)))
- (mastodon-http--triage response
- (lambda ()
- (when (equal (buffer-name (current-buffer))
- "*mastodon-lists*")
- (mastodon-tl--view-lists))
- (message "list %s created!" title)))))
+ (mastodon-tl--list-action-triage
+ response
+ (message "list %s created!" title))))
(defun mastodon-tl--delete-list-at-point ()
"Delete list at point."
@@ -1523,12 +1520,9 @@ If ID is provided, delete that list."
(url (mastodon-http--api (format "lists/%s" id))))
(when (y-or-n-p (format "Delete list %s?" name))
(let ((response (mastodon-http--delete url)))
- (mastodon-http--triage response
- (lambda ()
- (when (equal (buffer-name (current-buffer))
- "*mastodon-lists*")
- (mastodon-tl--view-lists))
- (message "list %s deleted!" name)))))))
+ (mastodon-tl--list-action-triage
+ response
+ (message "list %s deleted!" name))))))
(defun mastodon-tl--view-lists ()
"Show the user's lists in a new buffer."
@@ -1593,7 +1587,8 @@ a: add account to this list, r: remove account from this list"
"Prompt for a list and for an account, add account to list.
If ID is provided, use that list."
(interactive)
- (let* ((list-name (unless id
+ (let* ((list-name (if id
+ (word-at-point :no-properties)
(completing-read "Add account to list: "
(mastodon-tl--get-lists-names) nil t)))
(list-id (or id (mastodon-tl--get-list-id list-name)))
@@ -1609,12 +1604,9 @@ If ID is provided, use that list."
(response (mastodon-http--post url
`(("account_ids[]" . ,account-id))
nil)))
- (mastodon-http--triage response
- (lambda ()
- (when (equal (buffer-name (current-buffer))
- "*mastodon-lists*")
- (mastodon-tl--view-lists))
- (message "%s added to list %s!" account list-name)))))
+ (mastodon-tl--list-action-triage
+ response
+ (message "%s added to list %s!" account list-name))))
(defun mastodon-tl--remove-account-from-list-at-point ()
"Prompt for account and remove from list at point."
@@ -1646,9 +1638,18 @@ If ID is provided, use that list."
(query-str (mastodon-http--build-query-string args))
(url (concat base-url "?" query-str))
(response (mastodon-http--delete url)))
- (mastodon-http--triage response
- (lambda ()
- (message "%s removed from list %s!" account list-name)))))
+ (mastodon-tl--list-action-triage
+ response
+ (message "%s removed from list %s!" account list-name))))
+
+(defun mastodon-tl--list-action-triage (response message)
+ "Call `mastodon-http--triage' on RESPONSE and display MESSAGE."
+ (mastodon-http--triage response
+ (lambda ()
+ (when (equal (buffer-name (current-buffer))
+ "*mastodon-lists*")
+ (mastodon-tl--view-lists))
+ message)))
(defun mastodon-tl--accounts-in-list (list-id)
"Return the JSON of the accounts in list with LIST-ID."