diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-toot.el | 53 |
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) |