diff options
author | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2022-11-29 11:42:43 +0100 |
---|---|---|
committer | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2022-11-29 11:42:43 +0100 |
commit | 2bbc9f7289e2e249d8b4c27a22446c20c5b21f1b (patch) | |
tree | 62b5d7e1e5832bb40e880d57ba7deee88203d60b | |
parent | 9bac6bf378137ee220cfa4ae7e43079ef3ce0295 (diff) |
work on scheduling toots, editing as new, display scheduled ts
-rw-r--r-- | lisp/mastodon-tl.el | 50 | ||||
-rw-r--r-- | lisp/mastodon-toot.el | 47 |
2 files changed, 74 insertions, 23 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 4662fc3..6a90949 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1854,21 +1854,9 @@ If ID, just return that toot." (url (mastodon-http--api endpoint))) (mastodon-http--get-json url))) -(defun mastodon-tl--reschedule-toot (&optional id) +(defun mastodon-tl--reschedule-toot () "Reschedule the scheduled toot at point." - (interactive) - (let* ((id (get-text-property (point) 'id)) - (time-value (org-read-date nil t nil "Schedule toot:")) - (iso8601-str (format-time-string "%Y-%m-%dT%H:%M:%S%z" time-value)) - (msg-str (format-time-string "%Y-%m-%d at %H:%M[%z]" time-value)) - (args `(("scheduled_at" . ,iso8601-str))) - (url (mastodon-http--api (format "scheduled_statuses/%s" id))) - (response (mastodon-http--put url args))) - (mastodon-http--triage response - (lambda () - (mastodon-tl--update) - (message - (format "Toot rescheduled for %s." msg-str)))))) + (mastodon-toot--schedule-toot :reschedule)) (defun mastodon-tl--view-scheduled-toots () "Show the user's scheduled toots in a new buffer." @@ -1905,7 +1893,7 @@ If ID, just return that toot." (insert (propertize (concat text " | " - scheduled) + (mastodon-toot--iso-to-human scheduled)) 'byline t ; so we nav here 'toot-id "0" ; so we nav here 'face 'font-lock-comment-face @@ -1914,6 +1902,12 @@ If ID, just return that toot." 'id id) "\n"))) +(defun mastodon-toot--iso-to-human (ts) + "Format an ISO8601 timestamp TS to be more human-readable." + (let* ((decoded (iso8601-parse ts)) + (encoded (encode-time decoded))) + (format-time-string "%d-%m-%y, %H:%M[%z]" encoded))) + (defun mastodon-tl--copy-scheduled-toot-text () "Copy the text of the scheduled toot at point." (interactive) @@ -1934,6 +1928,32 @@ If ID, just return that toot." (mastodon-tl--view-scheduled-toots) (message "Toot cancelled!"))))))) +(defun mastodon-tl--edit-scheduled-as-new () + "Edit scheduled status as new toot." + (interactive) + (let* ((toot (get-text-property (point) 'scheduled-json)) + (scheduled (alist-get 'scheduled_at toot)) + (params (alist-get 'params toot)) + (text (alist-get 'text params)) + (visibility (alist-get 'visibility params)) + (cw (alist-get 'spoiler_text params)) + (lang (alist-get 'language params)) + (poll (alist-get 'poll params)) + (reply-id (alist-get 'in_reply_to_id params)) + (media (alist-get 'media_attachments toot))) + (mastodon-toot--compose-buffer) + (goto-char (point-max)) + (insert text) + ;; adopt properties from scheduled toot: + (when reply-id + (setq mastodon-toot--reply-to-id reply-id)) + (setq mastodon-toot--visibility visibility) + (setq mastodon-toot--scheduled-for scheduled) + (when (not (equal "" lang)) + (setq mastodon-toot--language lang)) + (mastodon-toot--set-cw cw) + (mastodon-toot--update-status-fields))) + ;;; FILTERS (defun mastodon-tl--create-filter () diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a1fb014..29d3914 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -693,7 +693,7 @@ instance to edit a toot." (symbol-name t))) ("spoiler_text" . ,spoiler) ("language" . ,mastodon-toot--language) - ("scheduled_at" . ,mastodon-toot--scheduled-at))) + ("scheduled_at" . ,mastodon-toot--scheduled-for))) (args-media (when mastodon-toot--media-attachments (mastodon-http--build-array-params-alist "media_ids[]" @@ -1126,16 +1126,35 @@ Return its two letter ISO 639 1 code." mastodon-iso-639-1))) (setq mastodon-toot--language (alist-get choice mastodon-iso-639-1 nil nil 'equal)) - (message "Language set to %s" choice))) + (message "Language set to %s" choice) + (mastodon-toot--update-status-fields))) -(defun mastodon-toot--schedule-toot () - "Read a date (+ time) in the minibuffer and schedule the current toot." +(defun mastodon-toot--schedule-toot (&optional reschedule) + "Read a date (+ time) in the minibuffer and schedule the current toot. +With RESCHEDULE, reschedule the scheduled toot at point." (interactive) - (let* ((time-value (org-read-date nil t nil "Schedule toot:")) - (iso8601-string (format-time-string "%Y-%m-%dT%H:%M:%S%z" time-value)) + (let* ((id (when reschedule (get-text-property (point) 'id))) + (time-value (org-read-date nil t nil "Schedule toot:")) + (iso8601-str (format-time-string "%FT%T%z" time-value)) (msg-str (format-time-string "%d-%m-%y at %H:%M[%z]" time-value))) - (setq-local mastodon-toot--scheduled-at iso8601-string) - (message (format "Toot scheduled for %s." msg-str)))) + (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 () + (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." + (let* ((decoded (iso8601-parse ts)) + (encoded (encode-time decoded))) + (format-time-string "%d-%m-%y, %H:%M[%z]" encoded))) ;; we'll need to revisit this if the binds get ;; more diverse than two-chord bindings @@ -1230,6 +1249,9 @@ REPLY-TEXT is the text of the toot being replied to." (propertize "Language" 'toot-post-language t) " " + (propertize "Scheduled" + 'toot-post-scheduled t) + " " (propertize "CW" 'toot-post-cw-flag t) " " @@ -1285,6 +1307,8 @@ REPLY-JSON is the full JSON of the toot being replied to." (point-min))) (lang-region (mastodon-tl--find-property-range 'toot-post-language (point-min))) + (scheduled-region (mastodon-tl--find-property-range 'toot-post-scheduled + (point-min))) (toot-string (buffer-substring-no-properties (cdr header-region) (point-max)))) (add-text-properties (car count-region) (cdr count-region) @@ -1306,6 +1330,13 @@ REPLY-JSON is the full JSON of the toot being replied to." (format "Lang: %s ⋅" mastodon-toot--language) ""))) + (add-text-properties (car scheduled-region) (cdr scheduled-region) + (list 'display + (if mastodon-toot--scheduled-for + (format "Scheduled: %s ⋅" + (mastodon-toot--iso-to-human + mastodon-toot--scheduled-for)) + ""))) (add-text-properties (car nsfw-region) (cdr nsfw-region) (list 'display (if mastodon-toot--content-nsfw (if mastodon-toot--media-attachments |