aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-toot.el25
-rw-r--r--lisp/mastodon.el2
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)