diff options
-rw-r--r-- | lisp/mastodon-toot.el | 21 | ||||
-rw-r--r-- | lisp/mastodon.el | 5 |
2 files changed, 22 insertions, 4 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index eac1193..78d0f22 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -35,6 +35,8 @@ :prefix "mastodon-toot-" :group 'mastodon) +(defvar mastodon-toot--reply-to-id nil) + (defun mastodon-toot--send-triage (status) "Callback function to triage toot POST. @@ -45,13 +47,16 @@ STATUS is passed by `url-retrieve'." (defun mastodon-toot-send () "Kill new-toot buffer/window and POST contents to the Mastodon instance." (interactive) - (let ((toot (buffer-string)) - (endpoint (mastodon--api-for "statuses"))) + (let* ((toot (buffer-string)) + (endpoint (mastodon--api-for "statuses")) + (args `(("status" . ,toot) + ("in_reply_to_id" . ,mastodon-toot--reply-to-id)))) (progn (kill-buffer-and-window) + (setq mastodon-toot--reply-to-id nil) (mastodon--http-post endpoint 'mastodon-toot--send-triage - `(("status" . ,toot)) + args `(("Authorization" . ,(concat "Bearer " (mastodon--access-token)))))))) @@ -59,6 +64,7 @@ STATUS is passed by `url-retrieve'." (defun mastodon-toot-cancel () "Kill new-toot buffer/window. Does not POST content to Mastodon." (interactive) + (setq mastodon-toot--reply-to-id nil) (kill-buffer-and-window)) (defun mastodon-toot--action-success (marker) @@ -102,6 +108,15 @@ Execute CALLBACK function if response was OK." (let ((callback (lambda () (mastodon-toot--action-success "F")))) (mastodon-toot--action "favourite" callback))) +(defun mastodon-toot--reply () + "Reply to toot at `point'." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (id (number-to-string (mastodon-tl--field 'id toot))) + (account (mastodon-tl--field 'account toot)) + (user (cdr (assoc 'username account)))) + (mastodon-toot user id))) + (defvar mastodon-toot-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "C-c C-c") #'mastodon-toot-send) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 42bfb67..478c6dd 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -75,12 +75,15 @@ (mastodon-tl--get "home")) ;;;###autoload -(defun mastodon-toot () +(defun mastodon-toot (&optional user reply-to-id) "Update a Mastodon instance with new toot. Content is captured in a new buffer." (interactive) (require 'mastodon-toot) (progn (switch-to-buffer-other-window (get-buffer-create "*new toot*")) + (when user + (insert (format "@%s " user)) + (setq mastodon-toot--reply-to-id reply-to-id)) (mastodon-toot-mode t))) ;;;###autoload |