branch: elpa/mastodon
commit ab799c54fb9d2e2e8a79313fa4fc9203634adeb3
Author: marty hiatt <[email protected]>
Commit: marty hiatt <[email protected]>
composing: optionally delete attachments when clearing them. FIX #774.
---
lisp/mastodon-toot.el | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 1f3ee71502..1023272198 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -1331,11 +1331,28 @@ Return its two letter ISO 639 1 code."
;;; ATTACHMENTS
+(defun mastodon-toot--delete-attachments ()
+ "Delete each attachment on the server.
+Makes a DELETE request for each item in
+`mastodon-toot--media-attachment-ids'."
+ (while mastodon-toot--media-attachment-ids
+ (let* ((id (pop mastodon-toot--media-attachment-ids))
+ (url (mastodon-http--api
+ (format "media/%s"
+ id)))
+ (resp (mastodon-http--delete url)))
+ (mastodon-http--triage resp
+ (lambda (_resp)
+ (message "File %s deleted!" id))))))
+
(defun mastodon-toot-clear-all-attachments ()
- "Remove all attachments from a toot draft."
+ "Remove all attachments from a toot draft.
+If user so chooses, also delete the files on the server."
(interactive)
(setq mastodon-toot--media-attachments nil)
- (setq mastodon-toot--media-attachment-ids nil)
+ (if (not (y-or-n-p "Also delete attachments on the server?"))
+ (setq mastodon-toot--media-attachment-ids nil)
+ (mastodon-toot--delete-attachments))
(mastodon-toot--refresh-attachments-display)
(mastodon-toot--update-status-fields))