aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-03-18 13:57:01 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-03-18 15:28:55 +0100
commit945bedc26c358dc20d34a4546ac6fc9f0641e2ee (patch)
tree066b89fc0effea4299273e3a3a2d5d6afb896bf0 /lisp
parent0a46393218ce10f828f467882433e2a45ff06ff0 (diff)
check for compose buffer in schedule toot
check for toot compose or scheduled view before scheduling a toot
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-toot.el64
1 files changed, 34 insertions, 30 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index b9e97b6..08b3467 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -1232,36 +1232,40 @@ With RESCHEDULE, reschedule the scheduled toot at point without editing."
;; original idea by christian tietze, thanks!
;; https://codeberg.org/martianh/mastodon.el/issues/285
(interactive)
- (if (mastodon-tl--buffer-type-eq 'edit-toot)
- (message "You can't schedule toots you're editing.")
- (let* ((id (when reschedule (get-text-property (point) 'id)))
- (ts (when reschedule
- (alist-get 'scheduled_at
- (get-text-property (point) 'scheduled-json))))
- (time-value
- (org-read-date t t nil "Schedule toot:"
- ;; default to scheduled timestamp if already set:
- (mastodon-toot--iso-to-org
- ;; we are rescheduling without editing:
- (or ts
- ;; we are maybe editing the scheduled toot:
- mastodon-toot--scheduled-for))))
- (iso8601-str (format-time-string "%FT%T%z" time-value))
- (msg-str (format-time-string "%d-%m-%y at %H:%M[%z]" time-value)))
- (if (not reschedule)
- (progn
- (setq-local mastodon-toot--scheduled-for iso8601-str)
- (message (format "Toot scheduled for %s." msg-str)))
- (let* ((args (when reschedule `(("scheduled_at" . ,iso8601-str))))
- (url (when reschedule (mastodon-http--api
- (format "scheduled_statuses/%s" id))))
- (response (mastodon-http--put url args)))
- (mastodon-http--triage response
- (lambda ()
- ;; reschedule means we are in scheduled toots view:
- (mastodon-tl--view-scheduled-toots)
- (message
- (format "Toot rescheduled for %s." msg-str)))))))))
+ (cond ((mastodon-tl--buffer-type-eq 'edit-toot)
+ (message "You can't schedule toots you're editing."))
+ ((not (or (mastodon-tl--buffer-type-eq 'new-toot)
+ (mastodon-tl--buffer-type-eq 'scheduled-statuses)))
+ (message "You can only schedule toots from the compose toot buffer or the scheduled toots view."))
+ (t
+ (let* ((id (when reschedule (get-text-property (point) 'id)))
+ (ts (when reschedule
+ (alist-get 'scheduled_at
+ (get-text-property (point) 'scheduled-json))))
+ (time-value
+ (org-read-date t t nil "Schedule toot:"
+ ;; default to scheduled timestamp if already set:
+ (mastodon-toot--iso-to-org
+ ;; we are rescheduling without editing:
+ (or ts
+ ;; we are maybe editing the scheduled toot:
+ mastodon-toot--scheduled-for))))
+ (iso8601-str (format-time-string "%FT%T%z" time-value))
+ (msg-str (format-time-string "%d-%m-%y at %H:%M[%z]" time-value)))
+ (if (not reschedule)
+ (progn
+ (setq-local mastodon-toot--scheduled-for iso8601-str)
+ (message (format "Toot scheduled for %s." msg-str)))
+ (let* ((args (when reschedule `(("scheduled_at" . ,iso8601-str))))
+ (url (when reschedule (mastodon-http--api
+ (format "scheduled_statuses/%s" id))))
+ (response (mastodon-http--put url args)))
+ (mastodon-http--triage response
+ (lambda ()
+ ;; reschedule means we are in scheduled toots view:
+ (mastodon-tl--view-scheduled-toots)
+ (message
+ (format "Toot rescheduled for %s." msg-str))))))))))
(defun mastodon-toot--iso-to-human (ts)
"Format an ISO8601 timestamp TS to be more human-readable."