diff options
author | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2022-08-20 15:42:50 +0200 |
---|---|---|
committer | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2022-08-20 15:42:50 +0200 |
commit | 88895d0c8307f27c643171cc7095c876856fe300 (patch) | |
tree | 638182d1499fbcc4c743d9148fb284cdcadbca57 /lisp | |
parent | 07953cabfc08fe43552016185525d1b34cd05769 (diff) |
FIX bookmark toggle, updating display in byline
just boilerplate copying fave/boost funs for now, better than nothing.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-tl.el | 8 | ||||
-rw-r--r-- | lisp/mastodon-toot.el | 59 |
2 files changed, 40 insertions, 27 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index d5a893d..aab0509 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -533,6 +533,9 @@ By default it is `mastodon-tl--byline-boosted'" (faved (equal 't (mastodon-tl--field 'favourited toot))) (boosted (equal 't (mastodon-tl--field 'reblogged toot))) (bookmarked (equal 't (mastodon-tl--field 'bookmarked toot))) + (bookmark-str (if (fontp (char-displayable-p #10r128278)) + "🔖" + "K")) (visibility (mastodon-tl--field 'visibility toot))) (concat ;; Boosted/favourited markers are not technically part of the byline, so @@ -547,10 +550,7 @@ By default it is `mastodon-tl--byline-boosted'" (when faved (mastodon-tl--format-faved-or-boosted-byline "F")) (when bookmarked - (mastodon-tl--format-faved-or-boosted-byline - (if (fontp (char-displayable-p #10r128278)) - "🔖" - "K")))) + (mastodon-tl--format-faved-or-boosted-byline bookmark-str))) (propertize (concat ;; we propertize help-echo format faves for author name diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 38179be..821dd43 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,42 @@ 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--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 +422,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)) |