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(-) 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