From 143dc33f576fe9a6a4bff38d6f732efa2aede654 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 22 Oct 2021 23:17:25 +0200 Subject: bookmark-toot keybinding --- lisp/mastodon.el | 1 + 1 file changed, 1 insertion(+) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 387e9eb..57f5721 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -158,6 +158,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept-notifs) (define-key map (kbd "j") #'mastodon-notifications--follow-request-reject-notifs) (define-key map (kbd "v") #'mastodon-tl--poll-vote) + (define-key map (kbd "k") #'mastodon-toot--bookmark-toot) (define-key map (kbd "K") #'mastodon-profile--view-bookmarks) map) -- cgit v1.2.3 From f892c5b28b829943619a0e810903c426308aa174 Mon Sep 17 00:00:00 2001 From: mousebot Date: Sat, 23 Oct 2021 11:31:52 +0200 Subject: rewrite bookmark-toot as toggle --- lisp/mastodon-toot.el | 37 +++++++++++++++++-------------------- lisp/mastodon.el | 3 ++- 2 files changed, 19 insertions(+), 21 deletions(-) (limited to 'lisp/mastodon.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index cfc5182..983515e 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -323,29 +323,26 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (setq mastodon-toot--content-warning-from-reply-or-redraft toot-cw)) (mastodon-toot--update-status-fields)))))))))) -(defun mastodon-toot--bookmark-toot () - "Bookmark toot at point synchronously." +(defun mastodon-toot--bookmark-toot-toggle () + "Bookmark or unbookmark toot at point synchronously." (interactive) (let* ((toot (mastodon-tl--property 'toot-json)) (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) - (url (mastodon-http--api (format "statuses/%s/bookmark" id)))) - (if (y-or-n-p (format "Bookmark this toot? ")) - (let ((response (mastodon-http--post url nil nil))) - (mastodon-http--triage response - (lambda () - (message "Toot bookmarked!"))))))) - -(defun mastodon-toot--unbookmark-toot () - "Bookmark toot at point synchronously." - (interactive) - (let* ((toot (mastodon-tl--property 'toot-json)) - (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) - (url (mastodon-http--api (format "statuses/%s/unbookmark" id)))) - (if (y-or-n-p (format "Remove this toot from your bookmarks? ")) - (let ((response (mastodon-http--post url nil nil))) - (mastodon-http--triage response - (lambda () - (message "Toot unbookmarked!"))))))) + (bookmarked (cdr (assoc 'bookmarked toot))) + (url (mastodon-http--api (if (equal bookmarked t) + (format "statuses/%s/unbookmark" id) + (format "statuses/%s/bookmark" id)))) + (prompt (if (equal bookmarked t) + (format "Toot already bookmarked. Remove? ") + (format "Bookmark this toot? "))) + (message (if (equal bookmarked t) + "Bookmark removed!" + "Toot bookmarked!"))) + (when (y-or-n-p prompt) + (let ((response (mastodon-http--post url nil nil))) + (mastodon-http--triage response + (lambda () + (message message))))))) (defun mastodon-toot--kill () "Kill `mastodon-toot-mode' buffer and window." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 57f5721..7f4b773 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -82,6 +82,7 @@ (autoload 'mastodon-tl--poll-vote "mastodon-http") (autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot") (autoload 'mastodon-profile--view-bookmarks "mastodon-profile") +(autoload 'mastodon-toot--bookmark-toot-toggle "mastodon-toot") (defgroup mastodon nil "Interface with Mastodon." @@ -158,7 +159,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept-notifs) (define-key map (kbd "j") #'mastodon-notifications--follow-request-reject-notifs) (define-key map (kbd "v") #'mastodon-tl--poll-vote) - (define-key map (kbd "k") #'mastodon-toot--bookmark-toot) + (define-key map (kbd "k") #'mastodon-toot--bookmark-toot-toggle) (define-key map (kbd "K") #'mastodon-profile--view-bookmarks) map) -- cgit v1.2.3