diff options
Diffstat (limited to 'lisp/mastodon-toot.el')
-rw-r--r-- | lisp/mastodon-toot.el | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 56b9417..b89b01e 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -216,8 +216,6 @@ Makes a POST request to the server." (let ((response (mastodon-http--post url nil nil))) (mastodon-http--triage response callback)))) - - (defun mastodon-toot--toggle-boost-or-favourite (type) "Toggle boost or favourite of toot at `point'. TYPE is a symbol, either 'favourite or 'boost." @@ -273,6 +271,43 @@ TYPE is a symbol, either 'favourite or 'boost." (interactive) (mastodon-toot--toggle-boost-or-favourite 'favourite)) +;; TODO maybe refactor into boost/fave fun +(defun mastodon-toot--bookmark-toot-toggle () + "Bookmark or unbookmark toot at point." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (id (mastodon-tl--property 'base-toot-id)) + ;; (mastodon-tl--as-string (mastodon-tl--toot-id toot))) + (bookmarked-p (mastodon-tl--property 'bookmarked-p)) + (prompt (if bookmarked-p + (format "Toot already bookmarked. Remove? ") + (format "Bookmark this toot? "))) + (byline-region + (when id + (mastodon-tl--find-property-range 'byline (point)))) + (action (if bookmarked-p "unbookmark" "bookmark")) + (bookmark-str (if (fontp (char-displayable-p #10r128278)) + "🔖" + "K")) + (message (if bookmarked-p + "Bookmark removed!" + "Toot bookmarked!")) + (remove (when bookmarked-p t))) + (if byline-region + (when (y-or-n-p prompt) + (mastodon-toot--action + action + (lambda () + (let ((inhibit-read-only t)) + (add-text-properties (car byline-region) + (cdr byline-region) + (list 'bookmarked-p (not bookmarked-p)))) + (mastodon-toot--action-success + bookmark-str + byline-region remove) + (message (format "%s #%s" message id))))) + (message (format "Nothing to %s here?!?" action))))) + (defun mastodon-toot--copy-toot-url () "Copy URL of toot at point." (interactive) @@ -388,27 +423,6 @@ REPLY-ID, TOOT-VISIBILITY, and TOOT-CW of deleted toot are preseved." (mastodon-toot-set-cw toot-cw) (mastodon-toot--update-status-fields)))) -(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))) - (bookmarked (alist-get '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." (kill-buffer-and-window)) |