From e17e2ecd417864c725fe5f182a25cf3024251263 Mon Sep 17 00:00:00 2001 From: Christian Tietze Date: Sat, 26 Nov 2022 11:07:24 +0000 Subject: add mastodon-toot--scheduled-at buffer-local variable to optionally schedule posts --- lisp/mastodon-toot.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index c99f088..eefceda 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -163,6 +163,10 @@ This is determined by the account setting on the server. To change the setting on the server, see `mastodon-toot--set-default-visibility'.") +(defvar-local mastodon-toot--scheduled-at nil + "An ISO 8601 timestamp that declares when the post should be published. +Should be at least 5 minutes into the future.") + (defvar-local mastodon-toot--media-attachments nil "A list of the media attachments of the toot being composed.") @@ -686,7 +690,8 @@ instance to edit a toot." ("sensitive" . ,(when mastodon-toot--content-nsfw (symbol-name t))) ("spoiler_text" . ,spoiler) - ("language" . ,mastodon-toot--language))) + ("language" . ,mastodon-toot--language) + ("scheduled_at" . ,mastodon-toot--scheduled-at))) (args-media (when mastodon-toot--media-attachments (mastodon-http--build-array-params-alist "media_ids[]" -- cgit v1.2.3 From d8e93a8089b45bda92d9e408f4f713242f9fad50 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 28 Nov 2022 19:33:17 +0100 Subject: add schedule toot function + binding --- lisp/mastodon-toot.el | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 42cce36..4a10131 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -164,10 +164,6 @@ This is determined by the account setting on the server. To change the setting on the server, see `mastodon-toot--set-default-visibility'.") -(defvar-local mastodon-toot--scheduled-at nil - "An ISO 8601 timestamp that declares when the post should be published. -Should be at least 5 minutes into the future.") - (defvar-local mastodon-toot--media-attachments nil "A list of the media attachments of the toot being composed.") @@ -180,6 +176,10 @@ Should be at least 5 minutes into the future.") (defvar-local mastodon-toot--language nil "The language of the toot being composed, in ISO 639 (two-letter).") +(defvar-local mastodon-toot--scheduled-for nil + "An ISO 8601 timestamp that specifying when the post should be published. +Should be at least 5 minutes into the future.") + (defvar-local mastodon-toot--reply-to-id nil "Buffer-local variable to hold the id of the toot being replied to.") @@ -233,6 +233,7 @@ send.") (define-key map (kbd "C-c !") #'mastodon-toot--clear-all-attachments) (define-key map (kbd "C-c C-p") #'mastodon-toot--create-poll) (define-key map (kbd "C-c C-l") #'mastodon-toot--set-toot-lang) + (define-key map (kbd "C-c C-s") #'mastodon-toot--schedule-toot) map) "Keymap for `mastodon-toot'.") @@ -1127,6 +1128,15 @@ Return its two letter ISO 639 1 code." (alist-get choice mastodon-iso-639-1 nil nil 'equal)) (message "Language set to %s" choice))) +(defun mastodon-toot--schedule-toot () + "Read a date (+ time) in the minibuffer and schedule the current toot." + (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)) + (msg-str (format-time-string "%Y-%m-%d at %H:%M[%z]" time-value))) + (setq-local mastodon-toot--scheduled-at iso8601-string) + (message (format "Toot scheduled for %s." msg-str)))) + ;; we'll need to revisit this if the binds get ;; more diverse than two-chord bindings (defun mastodon-toot--get-mode-kbinds () -- cgit v1.2.3 From 7d676ccd4a4076c65d7b53dbdd9c7846083ffcd9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 29 Nov 2022 10:29:21 +0100 Subject: tweak scheduled toot message string date format --- lisp/mastodon-toot.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 4a10131..1ddaca8 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1133,7 +1133,7 @@ Return its two letter ISO 639 1 code." (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)) - (msg-str (format-time-string "%Y-%m-%d at %H:%M[%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)))) -- cgit v1.2.3 From 9bac6bf378137ee220cfa4ae7e43079ef3ce0295 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 29 Nov 2022 11:40:43 +0100 Subject: abbreviate toot compose properties (visibility, char count etc) --- lisp/mastodon-toot.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 1ddaca8..a1fb014 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1289,12 +1289,12 @@ REPLY-JSON is the full JSON of the toot being replied to." (point-max)))) (add-text-properties (car count-region) (cdr count-region) (list 'display - (format "%s/%s characters" + (format "%s/%s chars" (mastodon-toot--count-toot-chars toot-string) (number-to-string mastodon-toot--max-toot-chars)))) (add-text-properties (car visibility-region) (cdr visibility-region) (list 'display - (format "Visibility: %s" + (format "%s" (if (equal mastodon-toot--visibility "private") @@ -1303,7 +1303,7 @@ REPLY-JSON is the full JSON of the toot being replied to." (add-text-properties (car lang-region) (cdr lang-region) (list 'display (if mastodon-toot--language - (format "Language: %s" + (format "Lang: %s ⋅" mastodon-toot--language) ""))) (add-text-properties (car nsfw-region) (cdr nsfw-region) -- cgit v1.2.3 From 2bbc9f7289e2e249d8b4c27a22446c20c5b21f1b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 29 Nov 2022 11:42:43 +0100 Subject: work on scheduling toots, editing as new, display scheduled ts --- lisp/mastodon-tl.el | 50 +++++++++++++++++++++++++++++++++++--------------- lisp/mastodon-toot.el | 47 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 74 insertions(+), 23 deletions(-) (limited to 'lisp/mastodon-toot.el') 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 -- cgit v1.2.3 From 0fda96c715a059b0d149d41ed416525a737f3789 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 29 Nov 2022 11:43:03 +0100 Subject: set-toot-lang > -language --- lisp/mastodon-toot.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 29d3914..0bed0f9 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -232,7 +232,7 @@ send.") (define-key map (kbd "C-c C-a") #'mastodon-toot--attach-media) (define-key map (kbd "C-c !") #'mastodon-toot--clear-all-attachments) (define-key map (kbd "C-c C-p") #'mastodon-toot--create-poll) - (define-key map (kbd "C-c C-l") #'mastodon-toot--set-toot-lang) + (define-key map (kbd "C-c C-l") #'mastodon-toot--set-toot-language) (define-key map (kbd "C-c C-s") #'mastodon-toot--schedule-toot) map) "Keymap for `mastodon-toot'.") @@ -1118,7 +1118,7 @@ LENGTH is the maximum character length allowed for a poll option." ("14 days" . ,(number-to-string (* 60 60 24 14))) ("30 days" . ,(number-to-string (* 60 60 24 30))))) -(defun mastodon-toot--set-toot-lang () +(defun mastodon-toot--set-toot-language () "Prompt for a language and set `mastodon-toot--language'. Return its two letter ISO 639 1 code." (interactive) -- cgit v1.2.3 From 65102c25d97212387a9699efd6253117366f5181 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 29 Nov 2022 12:06:46 +0100 Subject: refactor set toot properties, autoloads, docstrings, fixes --- lisp/mastodon-tl.el | 41 +++++++++++++++++------------------------ lisp/mastodon-toot.el | 35 ++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 33 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 6a90949..70e882e 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -82,6 +82,9 @@ (autoload 'mastodon-toot--get-toot-edits "mastodon-toot") (autoload 'mastodon-toot--update-status-fields "mastodon-toot") (autoload 'mastodon-toot--compose-buffer "mastodon-toot") +(autoload 'mastodon-toot--set-toot-properties "mastodon-toot") +(autoload 'mastodon-toot--schedule-toot "mastodon-toot") +(autoload 'mastodon-toot--iso-to-human "mastodon-toot") (defvar mastodon-toot--visibility) (defvar mastodon-active-user) @@ -1866,7 +1869,7 @@ If ID, just return that toot." 'mastodon-tl--insert-scheduled-toots)) (defun mastodon-tl--insert-scheduled-toots (json) - "Insert the user's scheduled toots." + "Insert the user's scheduled toots, from JSON." (let ((scheduleds (mastodon-tl--get-scheduled-toots))) (erase-buffer) (insert (mastodon-tl--set-face @@ -1877,9 +1880,9 @@ If ID, just return that toot." (mastodon-tl--set-face "[n/p - prev/next\n r - reschedule\n c - cancel]\n\n" 'font-lock-comment-face)) - (mapcar (lambda (x) - (mastodon-tl--insert-scheduled-toot x)) - scheduleds) + (mapc (lambda (x) + (mastodon-tl--insert-scheduled-toot x)) + scheduleds) (goto-char (point-min)) (when json (mastodon-tl--goto-next-toot)))) @@ -1902,12 +1905,6 @@ 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) @@ -1916,12 +1913,14 @@ If ID, just return that toot." (text (alist-get 'text params))) (kill-new text))) -(defun mastodon-tl--cancel-scheduled-toot () - "Cancel the scheduled toot at point." +(defun mastodon-tl--cancel-scheduled-toot (no-confirm) + "Cancel the scheduled toot at point. +NO-CONFIRM means don't ask, just do." (interactive) (let* ((id (get-text-property (point) 'id)) (url (mastodon-http--api (format "scheduled_statuses/%s" id)))) - (when (y-or-n-p "Cancel scheduled toot?") + (when (or no-confirm + (y-or-n-p "Cancel scheduled toot?")) (let ((response (mastodon-http--delete url))) (mastodon-http--triage response (lambda () @@ -1938,21 +1937,15 @@ If ID, just return that toot." (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))) + ;; (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))) + (mastodon-toot--set-toot-properties reply-id visibility cw + scheduled lang))) ;;; FILTERS diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 0bed0f9..d775727 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -80,6 +80,10 @@ (autoload 'mastodon-tl--get-endpoint "mastodon-tl") (autoload 'mastodon-http--put "mastodon-http") (autoload 'mastodon-tl--symbol "mastodon-tl") +(autoload 'mastodon-tl--view-scheduled-toots "mastodon-tl") + +(autoload 'org-read-date "org") +(autoload 'iso8601-parse "iso8601") ;; for mastodon-toot--translate-toot-text (autoload 'mastodon-tl--content "mastodon-tl") @@ -519,11 +523,23 @@ REPLY-ID, TOOT-VISIBILITY, and TOOT-CW of deleted toot are preseved." (goto-char (point-max)) (insert content) ;; adopt reply-to-id, visibility and CW from deleted toot: - (when reply-id - (setq mastodon-toot--reply-to-id reply-id)) - (setq mastodon-toot--visibility toot-visibility) - (mastodon-toot--set-cw toot-cw) - (mastodon-toot--update-status-fields)))) + (mastodon-toot--set-toot-properties + reply-id toot-visibility toot-cw + ;; TODO set new lang/scheduled props here + nil nil)))) + +(defun mastodon-toot--set-toot-properties (reply-id visibility cw + scheduled lang) + "Set the toot properties for the current redrafted or edited toot. +REPLY-ID, VISIBILITY, CW, SCHEDULED, and LANG are the properties to set." + (when reply-id + (setq mastodon-toot--reply-to-id reply-id)) + (setq mastodon-toot--visibility visibility) + (setq mastodon-toot--scheduled-for scheduled) + (when (not (string-empty-p lang)) + (setq mastodon-toot--language lang)) + (mastodon-toot--set-cw cw) + (mastodon-toot--update-status-fields)) (defun mastodon-toot--kill (&optional cancel) "Kill `mastodon-toot-mode' buffer and window. @@ -728,7 +744,8 @@ instance to edit a toot." (lambda () (mastodon-toot--kill) (message "Toot toot!") - (mastodon-toot--restore-previous-window-config prev-window-config)))))))) + (mastodon-toot--restore-previous-window-config + prev-window-config)))))))) ;; EDITING TOOTS: @@ -1141,9 +1158,9 @@ With RESCHEDULE, reschedule the scheduled toot at point." (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))) + (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) -- cgit v1.2.3 From 7fd6a014a7b7301c03a13e5561d92f9f7e6ca208 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 29 Nov 2022 15:47:22 +0100 Subject: add var scheduled-id, so we can cancel it if we reschedule --- lisp/mastodon-tl.el | 3 ++- lisp/mastodon-toot.el | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 70e882e..8ce2333 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1931,6 +1931,7 @@ NO-CONFIRM means don't ask, just do." "Edit scheduled status as new toot." (interactive) (let* ((toot (get-text-property (point) 'scheduled-json)) + (id (alist-get 'id toot)) (scheduled (alist-get 'scheduled_at toot)) (params (alist-get 'params toot)) (text (alist-get 'text params)) @@ -1945,7 +1946,7 @@ NO-CONFIRM means don't ask, just do." (insert text) ;; adopt properties from scheduled toot: (mastodon-toot--set-toot-properties reply-id visibility cw - scheduled lang))) + lang scheduled id))) ;;; FILTERS diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index d775727..2c5c523 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -184,6 +184,9 @@ change the setting on the server, see "An ISO 8601 timestamp that specifying when the post should be published. Should be at least 5 minutes into the future.") +(defvar-local mastodon-toot--scheduled-id nil + "The id of the scheduled post that we are now editing.") + (defvar-local mastodon-toot--reply-to-id nil "Buffer-local variable to hold the id of the toot being replied to.") @@ -526,16 +529,18 @@ REPLY-ID, TOOT-VISIBILITY, and TOOT-CW of deleted toot are preseved." (mastodon-toot--set-toot-properties reply-id toot-visibility toot-cw ;; TODO set new lang/scheduled props here - nil nil)))) + nil)))) -(defun mastodon-toot--set-toot-properties (reply-id visibility cw - scheduled lang) +(defun mastodon-toot--set-toot-properties (reply-id visibility cw lang + &optional scheduled + scheduled-id) "Set the toot properties for the current redrafted or edited toot. REPLY-ID, VISIBILITY, CW, SCHEDULED, and LANG are the properties to set." (when reply-id (setq mastodon-toot--reply-to-id reply-id)) (setq mastodon-toot--visibility visibility) (setq mastodon-toot--scheduled-for scheduled) + (setq mastodon-toot--scheduled-id scheduled-id) (when (not (string-empty-p lang)) (setq mastodon-toot--language lang)) (mastodon-toot--set-cw cw) -- cgit v1.2.3 From 679e15e955e0d7f4d204ea71aaeadaf26bfa690c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 29 Nov 2022 15:47:41 +0100 Subject: edit toot: use set-toot-properties --- lisp/mastodon-toot.el | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 2c5c523..86c192b 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -766,16 +766,15 @@ instance to edit a toot." (content (alist-get 'text source)) (source-cw (alist-get 'spoiler_text source)) (toot-visibility (alist-get 'visibility toot)) + (toot-language (alist-get 'language toot)) (reply-id (alist-get 'in_reply_to_id toot))) (when (y-or-n-p "Edit this toot? ") (mastodon-toot--compose-buffer) (goto-char (point-max)) (insert content) - ;; adopt reply-to-id, visibility and CW: - (when reply-id - (setq mastodon-toot--reply-to-id reply-id)) - (setq mastodon-toot--visibility toot-visibility) - (mastodon-toot--set-cw source-cw) + ;; adopt reply-to-id, visibility, CW, and language: + (mastodon-toot--set-toot-properties reply-id toot-visibility + source-cw toot-language) (mastodon-toot--update-status-fields) (setq mastodon-toot--edit-toot-id id)))))) -- cgit v1.2.3 From 3ded5be6dcf964f35eec22a7efaaf74973d4d385 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 29 Nov 2022 16:00:30 +0100 Subject: cancel original scheduled toot if edited/rescheduled --- lisp/mastodon-tl.el | 9 +++++---- lisp/mastodon-toot.el | 13 +++++++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 8ce2333..6971673 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1913,11 +1913,11 @@ If ID, just return that toot." (text (alist-get 'text params))) (kill-new text))) -(defun mastodon-tl--cancel-scheduled-toot (no-confirm) +(defun mastodon-tl--cancel-scheduled-toot (&optional id no-confirm) "Cancel the scheduled toot at point. -NO-CONFIRM means don't ask, just do." +NO-CONFIRM means there is no ask or message, there is only do." (interactive) - (let* ((id (get-text-property (point) 'id)) + (let* ((id (or id (get-text-property (point) 'id))) (url (mastodon-http--api (format "scheduled_statuses/%s" id)))) (when (or no-confirm (y-or-n-p "Cancel scheduled toot?")) @@ -1925,7 +1925,8 @@ NO-CONFIRM means don't ask, just do." (mastodon-http--triage response (lambda () (mastodon-tl--view-scheduled-toots) - (message "Toot cancelled!"))))))) + (unless no-confirm + (message "Toot cancelled!")))))))) (defun mastodon-tl--edit-scheduled-as-new () "Edit scheduled status as new toot." diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 86c192b..c058296 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -727,7 +727,9 @@ instance to edit a toot." (if mastodon-toot-poll (append args-no-media args-poll) args-no-media))) - (prev-window-config mastodon-toot-previous-window-config)) + (prev-window-config mastodon-toot-previous-window-config) + (scheduled mastodon-toot--scheduled-for) + (scheduled-id mastodon-toot--scheduled-id)) (cond ((and mastodon-toot--media-attachments ;; make sure we have media args ;; and the same num of ids as attachments @@ -748,7 +750,13 @@ instance to edit a toot." (mastodon-http--triage response (lambda () (mastodon-toot--kill) - (message "Toot toot!") + (if scheduled + (message "Toot scheduled!") + (message "Toot toot!")) + ;; cancel scheduled toot if we were editing it: + (when scheduled-id + (mastodon-tl--cancel-scheduled-toot + scheduled-id :no-confirm)) (mastodon-toot--restore-previous-window-config prev-window-config)))))))) @@ -1155,6 +1163,7 @@ Return its two letter ISO 639 1 code." With RESCHEDULE, reschedule the scheduled toot at point." (interactive) (let* ((id (when reschedule (get-text-property (point) 'id))) + ;; TODO if reschedule, set org-read-date to scheduled time (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))) -- cgit v1.2.3 From 24fec2f262123264c2b84d4f9c902b477b731bbb Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 29 Nov 2022 16:16:47 +0100 Subject: display value of --scheduled-for in org-read-date if set --- lisp/mastodon-toot.el | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index c058296..17b57ed 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -81,7 +81,7 @@ (autoload 'mastodon-http--put "mastodon-http") (autoload 'mastodon-tl--symbol "mastodon-tl") (autoload 'mastodon-tl--view-scheduled-toots "mastodon-tl") - +(autoload 'mastodon-tl--cancel-scheduled-toot "mastodon-toot") (autoload 'org-read-date "org") (autoload 'iso8601-parse "iso8601") @@ -1164,7 +1164,10 @@ With RESCHEDULE, reschedule the scheduled toot at point." (interactive) (let* ((id (when reschedule (get-text-property (point) 'id))) ;; TODO if reschedule, set org-read-date to scheduled time - (time-value (org-read-date nil t nil "Schedule toot:")) + (time-value + (org-read-date t t nil "Schedule toot:" + ;; default to scheduled timestamp if already set: + (mastodon-toot--iso-to-org 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) @@ -1172,10 +1175,12 @@ With RESCHEDULE, reschedule the scheduled toot at point." (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)))) + (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)))))))) @@ -1186,6 +1191,11 @@ With RESCHEDULE, reschedule the scheduled toot at point." (encoded (encode-time decoded))) (format-time-string "%d-%m-%y, %H:%M[%z]" encoded))) +(defun mastodon-toot--iso-to-org (ts) + "Convert ISO8601 timestamp TS to something `org-read-date' can handle." + (let* ((decoded (iso8601-parse ts))) + (encode-time decoded))) + ;; we'll need to revisit this if the binds get ;; more diverse than two-chord bindings (defun mastodon-toot--get-mode-kbinds () -- cgit v1.2.3 From 9f5ebd694be8033b3ea79b6e6f56ec777bbdfb80 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 29 Nov 2022 16:25:08 +0100 Subject: make rescheduling without editing work, also with org-read-date --- lisp/mastodon-tl.el | 1 + lisp/mastodon-toot.el | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 6971673..f28c7c5 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1859,6 +1859,7 @@ If ID, just return that toot." (defun mastodon-tl--reschedule-toot () "Reschedule the scheduled toot at point." + (interactive) (mastodon-toot--schedule-toot :reschedule)) (defun mastodon-tl--view-scheduled-toots () diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 17b57ed..87b1b77 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1160,14 +1160,20 @@ Return its two letter ISO 639 1 code." (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." +With RESCHEDULE, reschedule the scheduled toot at point without editing." (interactive) (let* ((id (when reschedule (get-text-property (point) 'id))) - ;; TODO if reschedule, set org-read-date to scheduled time + (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 mastodon-toot--scheduled-for))) + (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) @@ -1193,8 +1199,8 @@ With RESCHEDULE, reschedule the scheduled toot at point." (defun mastodon-toot--iso-to-org (ts) "Convert ISO8601 timestamp TS to something `org-read-date' can handle." - (let* ((decoded (iso8601-parse ts))) - (encode-time decoded))) + (when ts (let* ((decoded (iso8601-parse ts))) + (encode-time decoded)))) ;; we'll need to revisit this if the binds get ;; more diverse than two-chord bindings -- cgit v1.2.3 From a0df42d70b8e7285234c4a8bb3d65154c7a31c70 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 30 Nov 2022 10:56:25 +0100 Subject: schedule-toot - comment to acknowledge ct --- lisp/mastodon-toot.el | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 87b1b77..7efe682 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1161,6 +1161,8 @@ Return its two letter ISO 639 1 code." (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 without editing." + ;; original idea by christian tietze, thanks! + ;; https://codeberg.org/martianh/mastodon.el/issues/285 (interactive) (let* ((id (when reschedule (get-text-property (point) 'id))) (ts (when reschedule -- cgit v1.2.3 From 308a9824fa5391fd4228949faedffd05b46579da Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 1 Dec 2022 09:44:32 +0100 Subject: completion - bound the --get-bounds backward regex search this prevents matching when we have type words after a handle/tag (forward-whitespace -1) places point before the previous space. placing it after doesn't work, it breaks some completion cases. --- lisp/mastodon-toot.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 7efe682..9402241 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -869,7 +869,11 @@ eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." (save-excursion ;; match full handle inc. domain, or tag including # ;; (see the regexes for subexp 2) - (when (re-search-backward regex nil :no-error) + (when (re-search-backward regex + (save-excursion + (forward-whitespace -1) + (point)) + :no-error) (cons (match-beginning 2) (match-end 2)))))) -- cgit v1.2.3 From 7a70e091f64729b03ad55079b5a3a86afd178d0c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 1 Dec 2022 10:16:21 +0100 Subject: factor fetch candidates fun, try to improve completion performance --- lisp/mastodon-toot.el | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 9402241..8d8bfc2 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -877,6 +877,24 @@ eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." (cons (match-beginning 2) (match-end 2)))))) +(defun mastodon-toot--fetch-completion-candidates (start end &optional tags) + "Search for a completion prefix from buffer positions START to END. +Return a list of candidates. +If TAGS, we search for tags, else we search for handles." + ;; FIXME: can we save the first two-letter search then only filter the + ;; resulting list? + ;; (or mastodon-toot-completions + ;; would work if we could null that var upon completion success + (setq mastodon-toot-completions + (if tags + (let ((tags-list (mastodon-search--search-tags-query + (buffer-substring-no-properties start end)))) + (cl-loop for tag in tags-list + collect (cons (concat "#" (car tag)) + (cdr tag)))) + (mastodon-search--search-accounts-query + (buffer-substring-no-properties start end))))) + (defun mastodon-toot--mentions-capf () "Build a mentions completion backend for `completion-at-point-functions'." (let* ((bounds @@ -889,11 +907,7 @@ eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." ;; only search when necessary: (completion-table-dynamic (lambda (_) - ;; TODO: do we really need to set a local var here - ;; just for the annotation-function? - (setq mastodon-toot-completions - (mastodon-search--search-accounts-query - (buffer-substring-no-properties start end))))) + (mastodon-toot--fetch-completion-candidates start end))) :exclusive 'no :annotation-function (lambda (candidate) @@ -912,13 +926,7 @@ eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." ;; only search when necessary: (completion-table-dynamic (lambda (_) - (setq mastodon-toot-completions - (let ((tags (mastodon-search--search-tags-query - (buffer-substring-no-properties start end)))) - (mapcar (lambda (x) - (list (concat "#" (car x)) - (cdr x))) - tags))))) + (mastodon-toot--fetch-completion-candidates start end :tags))) :exclusive 'no :annotation-function (lambda (candidate) @@ -933,7 +941,7 @@ eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." "Given a tag string CANDIDATE, return an annotation, the tag's URL." ;; FIXME check the list returned here? should be cadr ;;or make it an alist and use cdr - (caadr (assoc candidate mastodon-toot-completions))) + (cadr (assoc candidate mastodon-toot-completions))) (defun mastodon-toot--reply () "Reply to toot at `point'. -- cgit v1.2.3 From 8db62b46a141dc862cee6e90afc935964a55b9d4 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 2 Dec 2022 11:58:35 +0100 Subject: update comment re completion fetching --- lisp/mastodon-toot.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 8d8bfc2..a394b00 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -881,10 +881,8 @@ eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." "Search for a completion prefix from buffer positions START to END. Return a list of candidates. If TAGS, we search for tags, else we search for handles." - ;; FIXME: can we save the first two-letter search then only filter the - ;; resulting list? - ;; (or mastodon-toot-completions - ;; would work if we could null that var upon completion success + ;; we can't save the first two-letter search then only filter the + ;; resulting list, as max results returned is 40. (setq mastodon-toot-completions (if tags (let ((tags-list (mastodon-search--search-tags-query -- cgit v1.2.3 From fabe373dedeae535726434527870e65496044e58 Mon Sep 17 00:00:00 2001 From: Sacha Chua Date: Thu, 8 Dec 2022 09:13:16 -0500 Subject: Use mastodon-toot--count-toot-chars when validating toot length * lisp/mastodon-toot.el (mastodon-toot--send): Use mastodon-toot--count-toot-chars instead of length. --- lisp/mastodon-toot.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a394b00..c87b3bb 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -738,7 +738,7 @@ instance to edit a toot." (length mastodon-toot--media-attachment-ids))))) (message "Something is wrong with your uploads. Wait for them to complete or try again.")) ((and mastodon-toot--max-toot-chars - (> (length toot) mastodon-toot--max-toot-chars)) + (> (mastodon-toot--count-toot-chars toot) mastodon-toot--max-toot-chars)) (message "Looks like your toot is longer than that maximum allowed length.")) ((mastodon-toot--empty-p) (message "Empty toot. Cowardly refusing to post this.")) -- cgit v1.2.3