aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-http.el19
-rw-r--r--lisp/mastodon-toot.el21
-rw-r--r--lisp/mastodon.el2
3 files changed, 42 insertions, 0 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index 35af12c..50b560f 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -108,6 +108,25 @@ If response code is not 2XX, switches to the response buffer created by `url-ret
(funcall success)
(switch-to-buffer (current-buffer))))
+(defun mastodon-http--post (url args headers)
+ "POST synchronously to URL with ARGS and HEADERS.
+
+Authorization header is included by default."
+ (let ((url-request-method "POST")
+ (url-request-data
+ (when args
+ (mapconcat (lambda (arg)
+ (concat (url-hexify-string (car arg))
+ "="
+ (url-hexify-string (cdr arg))))
+ args
+ "&")))
+ (url-request-extra-headers
+ `(("Authorization" . ,(concat "Bearer " (mastodon--access-token)))
+ ,headers)))
+ (with-temp-buffer
+ (url-retrieve-synchronously url))))
+
(defun mastodon-http--get (url)
"Make GET request to URL.
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 481a187..ff20434 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -61,6 +61,27 @@ STATUS is passed by `url-retrieve'."
(interactive)
(kill-buffer-and-window))
+(defun mastodon-toot--property (prop)
+ "Get property PROP for toot at point."
+ (or (get-text-property (point) prop)
+ (progn
+ (mastodon-tl--goto-next-toot)
+ (get-text-property (point) prop))))
+
+;; TODO extract success callback
+(defun mastodon-toot--boost ()
+ "Boost toot at point."
+ (interactive)
+ (let* ((id (mastodon-toot--property 'toot-id))
+ (url (mastodon--api-for (concat "statuses/"
+ (number-to-string id)
+ "/reblog"))))
+ (let ((response (mastodon-http--post url nil nil)))
+ (with-current-buffer response
+ (if (string-prefix-p "2" (mastodon--response-code))
+ (message "Boosted!")
+ (switch-to-buffer response))))))
+
(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 b74a64d..6c13299 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -94,6 +94,7 @@
"Major mode for Mastodon, the federated microblogging network."
:group 'mastodon
(let ((map mastodon-mode-map))
+ (define-key map (kbd "b") #'mastodon-toot--boost)
(define-key map (kbd "F") #'mastodon-tl--get-federated-timeline)
(define-key map (kbd "H") #'mastodon-tl--get-home-timeline)
(define-key map (kbd "j") #'mastodon-tl--goto-next-toot)
@@ -115,6 +116,7 @@
(description "Mastodon feed viewer")
(actions
("Toots"
+ ("b" "Boost" mastodon-toot--boost)
("j" "Next" mastodon-tl--goto-next-toot)
("k" "Prev" mastodon-tl--goto-prev-toot)
("n" "Send" mastodon-toot)