aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohnson Denen <johnson.denen@gmail.com>2017-04-18 14:58:59 -0400
committerJohnson Denen <johnson.denen@gmail.com>2017-04-18 15:03:01 -0400
commit9d9da60576b3925cf7a0d91be14221f013090276 (patch)
treea0b992280fe642343ec38ccba75e9dceea1519a0
parentb2f927617e0e6394cfe55bb603668ee689480103 (diff)
Add reply functionality
-rw-r--r--lisp/mastodon-toot.el21
-rw-r--r--lisp/mastodon.el5
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