From 7e7b6c5c67af47c37d2a856dd72ccc040c967482 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 29 Oct 2021 17:55:27 +0200 Subject: merge upload-media-attachments functionality into toot-send. this obviates the need for the user to upload files before posting their toot. - this commit makes http--post-media-attachment synchronous, so that toot-send has to wait for it. - in toot-send: if mastodon-toot--media-attachements is non-nil, the files it contains are uploaded synchronously, and their returned ids are added to toot-media-attachment-ids, which are parsed as args for the POST request to be attached to the toot. - then we send toot as usual. - clear-all-attachments also clears mastodon-toot--media-attachment-ids just in case. - we have no more need of media-attachments-filenames, as media-attachments is now a list and not a boolean value. --- lisp/mastodon-http.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-http.el') diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index b5437a3..d6158eb 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -256,7 +256,9 @@ Authorization header is included by default unless UNAUTHENTICED-P is non-nil." ;; TODO: test for curl first? (defun mastodon-http--post-media-attachment (url filename caption) "Make POST request to upload FILENAME with CAPTION to the server's media URL. -The upload is asynchronous. On succeeding, `mastodon-toot--media-attachment-ids' is set to the id(s) of the item uploaded, and `mastodon-toot--update-status-fields' is run." +The upload is asynchronous. On succeeding, +`mastodon-toot--media-attachment-ids' is set to the id(s) of the +item uploaded, and `mastodon-toot--update-status-fields' is run." (let* ((file (file-name-nondirectory filename)) (request-backend 'curl)) ;; (response @@ -269,14 +271,13 @@ The upload is asynchronous. On succeeding, `mastodon-toot--media-attachment-ids' :parser 'json-read :headers `(("Authorization" . ,(concat "Bearer " (mastodon-auth--access-token)))) - :sync nil + :sync t :success (cl-function (lambda (&key data &allow-other-keys) (when data (progn (push (cdr (assoc 'id data)) mastodon-toot--media-attachment-ids) ; add ID to list - (push file mastodon-toot--media-attachment-filenames) (message "%s file %s with id %S and caption '%s' uploaded!" (capitalize (cdr (assoc 'type data))) file -- cgit v1.2.3