aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnson Denen <johnson.denen@gmail.com>2017-04-25 13:03:08 -0400
committerJohnson Denen <johnson.denen@gmail.com>2017-04-28 19:57:23 -0400
commitc99b717c3ca818e3f8ecc0b0b508fcc31c54cc5a (patch)
tree2bece7fed247d75c95970b64096213d385c50032
parentae42703f4beb840e7988c7714c0f5624b2dc0556 (diff)
Use toggle function approach for favourite/unfavourite
TODOs: * Will require a boost/unboost toggle impl * Must pass favourite/boosted state to the toggle functions from mastodon-tl
-rw-r--r--lisp/mastodon-toot.el53
1 files changed, 22 insertions, 31 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 79c5a2d..2da6cec 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -38,24 +38,19 @@
(defvar mastodon-toot--reply-to-id nil)
(defvar mastodon-toot--content-warning nil)
-(defun mastodon-toot--action-success (marker)
- "Insert MARKER with 'success face in byline."
- (let ((inhibit-read-only t))
- (move-beginning-of-line '())
- (mastodon-tl--goto-next-toot)
- (insert (format "(%s) "
- (propertize marker 'face 'success)))))
+(defun mastodon-toot--action-success (marker &optional rm)
+ "Insert MARKER with 'success face in byline.
-(defun mastodon-toot--action-success-undo (marker)
- "Remove MARKER from byline."
+Remove MARKER if RM is non-nil."
(let ((inhibit-read-only t)
- (start (progn (move-beginning-of-line '())
- (point)))
- (end (progn (move-end-of-line '())
- (point))))
- (replace-regexp (format "(%s) " marker) "" '() start end)
+ (bol (progn (move-beginning-of-line '()) (point)))
+ (eol (progn (move-end-of-line '()) (point))))
+ (when rm (replace-regexp (format "(%s) " marker) "" '() bol eol))
(move-beginning-of-line '())
- (mastodon-tl--goto-next-toot)))
+ (mastodon-tl--goto-next-toot)
+ (unless rm
+ (insert (format "(%s) "
+ (propertize marker 'face 'success))))))
(defun mastodon-toot--action (action callback)
"Take ACTION on toot at point, then execute CALLBACK."
@@ -67,6 +62,18 @@
(let ((response (mastodon-http--post url nil nil)))
(mastodon-http--triage response callback))))
+(defun mastodon-toot--toggle-favourite (faved)
+ "Favourite/unfavourite toot based on current state.
+
+If FAVED is nil, favourite the toot.
+If FAVED is non-nil, unfavourite the toot."
+ (interactive)
+ (let ((action (if faved "unfavourite" "favourite"))
+ (remove (when faved t))
+ (id (mastodon-tl--property 'toot-id)))
+ (mastodon-toot--action action (lambda () (mastodon-toot--action-success "F" remove)))
+ (message (format "%sd #%s" action id))))
+
(defun mastodon-toot--kill ()
"Kill `mastodon-toot-mode' buffer and window.
@@ -107,22 +114,6 @@ Set `mastodon-toot--content-warning' to nil."
(mastodon-toot--action "reblog" callback)
(message (format "Boosted #%s" id))))
-(defun mastodon-toot--favourite ()
- "Favourite toot at `point'."
- (interactive)
- (let ((callback (lambda () (mastodon-toot--action-success "F")))
- (id (mastodon-tl--property 'toot-id)))
- (mastodon-toot--action "favourite" callback)
- (message (format "Favourited #%s" id))))
-
-(defun mastodon-toot--unfavourite ()
- "Unfavourite toot at `point'."
- (interactive)
- (let ((callback (lambda () (mastodon-toot--action-success-undo "F")))
- (id (mastodon-tl--property 'toot-id)))
- (mastodon-toot--action "unfavourite" callback)
- (message (format "unfavourited #%s" id))))
-
(defun mastodon-toot--reply ()
"Reply to toot at `point'."
(interactive)