aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus@riseup.net>2024-08-01 13:04:07 +0200
committermarty hiatt <martianhiatus@riseup.net>2024-08-01 13:04:07 +0200
commit8d6983667d51f6aec7a024bb0e2f3dd3fdddb7f4 (patch)
treede5cf57830807467d34b6d82c291f5141e15c7d5
parentd0a5bae33167402f6abc8707642945a738b2fe19 (diff)
refactor toot--toggle-bookmark
-rw-r--r--lisp/mastodon-toot.el59
1 files changed, 26 insertions, 33 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 9b8117a..0324c32 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -481,39 +481,32 @@ SUBTRACT means we are un-favouriting or unboosting, so we decrement."
"Bookmark or unbookmark toot at point."
(interactive)
(mastodon-toot--with-toot-item
- (let ((n-type (mastodon-tl--property 'notification-type :no-move)))
- (if (or (equal n-type "follow")
- (equal n-type "follow_request"))
- (user-error (format "Can't bookmark %s notifications." n-type))
- (let* ((bookmarked-p (mastodon-tl--property
- 'bookmarked-p
- (if (mastodon-tl--property 'byline :no-move)
- ;; no move if not in byline, the idea being
- ;; if in body, we do move forward to byline
- ;; to toggle correctly. alternatively we
- ;; could bookmarked-p whole posts.
- :no-move)))
- (byline-region (when id
- (mastodon-tl--find-property-range 'byline (point))))
- (action (if bookmarked-p "unbookmark" "bookmark"))
- (bookmark-str (mastodon-tl--symbol 'bookmark))
- (message (if bookmarked-p
- "Bookmark removed!"
- "Toot bookmarked!"))
- (remove (when bookmarked-p t))
- (item-json (mastodon-tl--property 'item-json)))
- (if (not byline-region)
- (user-error "Nothing to %s here?!?" action)
- (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 item-json)
- (message "%s #%s" message id)))))))))
+ (let* ((n-type (mastodon-tl--property 'notification-type :no-move))
+ (byline-region (mastodon-tl--find-property-range 'byline (point)))
+ (bookmarked-p (when byline-region
+ (get-text-property (car byline-region) 'bookmarked-p)))
+ (action (if bookmarked-p "unbookmark" "bookmark")))
+ (cond ((or (equal n-type "follow")
+ (equal n-type "follow_request"))
+ (user-error "Can't bookmark %s notifications" n-type))
+ ((not byline-region)
+ (user-error "Nothing to %s here?!?" action))
+ (t
+ (let* ((bookmark-str (mastodon-tl--symbol 'bookmark))
+ (message (if bookmarked-p
+ "Bookmark removed!"
+ "Toot bookmarked!"))
+ (item-json (mastodon-tl--property 'item-json)))
+ (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 bookmarked-p item-json)
+ (message "%s #%s" message id))))))))))
(defun mastodon-toot--list-toot-boosters ()
"List the boosters of toot at point."