diff options
author | mousebot <mousebot@riseup.net> | 2021-09-23 13:09:17 +0200 |
---|---|---|
committer | mousebot <mousebot@riseup.net> | 2021-09-23 13:09:17 +0200 |
commit | 4499e9471c4a7ba923ef950954a9e42f9a7ed6e9 (patch) | |
tree | f3ae3392e8fe39ca93663cf9443a5f2e79daba76 | |
parent | 21c6572d62d9129b48003129e60c97d0f64868d0 (diff) |
basic delete-and-redraft-toot, text status only for now.
-rw-r--r-- | lisp/mastodon-toot.el | 25 | ||||
-rw-r--r-- | lisp/mastodon.el | 2 |
2 files changed, 27 insertions, 0 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1c8a475..1f65cbf 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -234,6 +234,31 @@ Remove MARKER if REMOVE is non-nil, otherwise add it." (mastodon-tl--reload-timeline-or-profile) (message "Toot deleted!")))))))) +;; TODO: handle media/poll for redrafting toots +(defun mastodon-toot--delete-and-redraft-toot () + "Delete and redraft user's toot at point synchronously." + (interactive) + (let* ((toot (mastodon-tl--property 'toot-json)) + (id (mastodon-tl--as-string (mastodon-tl--toot-id toot))) + (url (mastodon-http--api (format "statuses/%s" id)))) + (if (or (cdr (assoc 'reblog toot)) + (not (equal (cdr (assoc 'acct + (cdr (assoc 'account toot)))) + (mastodon-auth--user-acct)))) + (message "You can only delete and redraft your own toots.") + (if (y-or-n-p (format "Delete and redraft this toot? ")) + (let* ((response (mastodon-http--delete url))) + (mastodon-http--triage + response + (lambda () + (with-current-buffer response + (let* ((json-response (mastodon-http--process-json)) + (content (cdr (assoc 'text json-response))) + (media (cdr (assoc 'media_attachments json-response)))) + (mastodon-toot--compose-buffer nil nil) + (goto-char (point-max)) + (insert content)))))))))) + (defun mastodon-toot--kill () "Kill `mastodon-toot-mode' buffer and window." (kill-buffer-and-window)) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 460fe29..acb9e12 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -80,6 +80,7 @@ (autoload 'mastodon-profile--update-user-profile-note "mastodon-profile") (autoload 'mastodon-auth--user-acct "mastodon-auth") (autoload 'mastodon-tl--poll-vote "mastodon-http") +(autoload 'mastodon-toot--delete-and-redraft-toot "mastodon-toot") (defgroup mastodon nil "Interface with Mastodon." @@ -143,6 +144,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "C-S-P") #'mastodon-profile--my-profile) (define-key map (kbd "S") #'mastodon-search--search-query) (define-key map (kbd "d") #'mastodon-toot--delete-toot) + (define-key map (kbd "D") #'mastodon-toot--delete-and-redraft-toot) (define-key map (kbd "C") #'mastodon-toot--copy-toot-url) (define-key map (kbd "i") #'mastodon-toot--pin-toot-toggle) (define-key map (kbd "V") #'mastodon-profile--view-favourites) |