aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-toot.el
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-08-20 16:27:18 +0200
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-08-20 16:27:18 +0200
commit448b9e5a757b4ebf617a8ff1f04b9643f086672e (patch)
tree3bb5587c33223a1175d9d5c605186d11c03872a7 /lisp/mastodon-toot.el
parent43baced1733b318a4fbe0a2ddba02c252f109c41 (diff)
parent705adb3ae86ee2c09074e9938673fc9083b9ab9d (diff)
Merge branch 'develop'
Diffstat (limited to 'lisp/mastodon-toot.el')
-rw-r--r--lisp/mastodon-toot.el60
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))