diff options
| -rw-r--r-- | lisp/mastodon-http.el | 7 | ||||
| -rw-r--r-- | lisp/mastodon-toot.el | 37 | 
2 files changed, 24 insertions, 20 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 50b560f..92c876f 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -108,6 +108,13 @@ 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--triage (response success) +  (let ((status (with-current-buffer response +                  (mastodon--response-code)))) +    (if (string-prefix-p "2" status) +        (funcall success) +      (switch-to-buffer response)))) +  (defun mastodon-http--post (url args headers)    "POST synchronously to URL with ARGS and HEADERS. diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 93980f0..13e23b7 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -44,24 +44,7 @@ STATUS is passed by `url-retrieve'."    (mastodon--http-response-triage status                                    (lambda () (switch-to-buffer (current-buffer))))) ;; FIXME -(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")) -         (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 -                           args -                           `(("Authorization" . ,(concat -                                                  "Bearer " -                                                  (mastodon--access-token)))))))) - -(defun mastodon-toot-cancel () +(defun mastodon-toot--cancel ()    "Kill new-toot buffer/window. Does not POST content to Mastodon."    (interactive)    (setq mastodon-toot--reply-to-id nil) @@ -94,6 +77,20 @@ Execute CALLBACK function if response was OK."      (let ((response (mastodon-http--post url nil nil)))        (mastodon-toot--action-triage response callback)))) +(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")) +         (args `(("status" . ,toot) +                 ("in_reply_to_id" . ,mastodon-toot--reply-to-id)))) +    (progn +      (kill-buffer-and-window) +      (setq mastodon-toot--reply-to-id nil) +      (let ((response (mastodon-http--post endpoint args nil))) +        (mastodon-http--triage response +                               (lambda () (message "Toot toot!"))))))) +  (defun mastodon-toot--boost ()    "Boost toot at `point'."    (interactive) @@ -121,8 +118,8 @@ Execute CALLBACK function if response was OK."  (defvar mastodon-toot-mode-map    (let ((map (make-sparse-keymap))) -    (define-key map (kbd "C-c C-c") #'mastodon-toot-send) -    (define-key map (kbd "C-c C-k") #'mastodon-toot-cancel) +    (define-key map (kbd "C-c C-c") #'mastodon-toot--send) +    (define-key map (kbd "C-c C-k") #'mastodon-toot--cancel)        map)    "Keymap for `mastodon-toot-mode'.")  | 
