From 21bb3bff54c766514b93d8022f149f4179e9d31e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 26 Nov 2022 18:20:01 +0100 Subject: nil the update-fun in buffer-spec for --thread views --- lisp/mastodon-tl.el | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 7d23b69..a5b5ed7 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1491,10 +1491,9 @@ ID is that of the toot to view." (with-output-to-temp-buffer buffer (switch-to-buffer buffer) (mastodon-mode) - (mastodon-tl--set-buffer-spec - buffer - (format "statuses/%s/context" id) - 'mastodon-tl--thread) + (mastodon-tl--set-buffer-spec buffer + (format "statuses/%s/context" id) + nil) (let ((inhibit-read-only t)) (mastodon-tl--timeline (alist-get 'ancestors context)) (goto-char (point-max)) -- cgit v1.2.3 From e23ef05fabe038396875c118101847d69e5de7f6 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 27 Nov 2022 10:35:07 +0100 Subject: add fun mastodon-tl--dm-user --- lisp/mastodon-tl.el | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index a5b5ed7..53ab57a 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2175,6 +2175,16 @@ LANGS is the accumulated array param alist if we re-run recursively." (message "Looks like you have no mutes to unmute!") (mastodon-tl--do-user-action-and-response user-handle "unmute" t))) +(defun mastodon-tl--dm-user (user-handle) + "Query for USER-HANDLE from current status and compose a message to that user." + (interactive + (list + (mastodon-tl--interactive-user-handles-get "message"))) + (mastodon-tl--do-if-toot + (mastodon-toot--compose-buffer (concat "@" user-handle)) + (setq mastodon-toot--visibility "direct") + (mastodon-toot--update-status-fields))) + (defun mastodon-tl--interactive-user-handles-get (action) "Get the list of user-handles for ACTION from the current toot." (mastodon-tl--do-if-toot -- cgit v1.2.3 From 3b3e97c0c142e41be1acb419b5793b8aa62b0920 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 27 Nov 2022 11:33:14 +0100 Subject: extract endpoint to let var in --thread --- lisp/mastodon-tl.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 53ab57a..49c26ea 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1469,7 +1469,8 @@ ID is that of the toot to view." (if (or (string= type "follow_request") (string= type "follow")) ; no can thread these (error "No thread") - (let* ((url (mastodon-http--api (format "statuses/%s/context" id))) + (let* ((endpoint (format "statuses/%s/context" id)) + (url (mastodon-http--api endpoint)) (buffer (format "*mastodon-thread-%s*" id)) (toot ;; refetch current toot in case we just faved/boosted: @@ -1492,7 +1493,7 @@ ID is that of the toot to view." (switch-to-buffer buffer) (mastodon-mode) (mastodon-tl--set-buffer-spec buffer - (format "statuses/%s/context" id) + endpoint nil) (let ((inhibit-read-only t)) (mastodon-tl--timeline (alist-get 'ancestors context)) -- cgit v1.2.3 From accc0c8b451580169300d28974c62650e5e30aac Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 27 Nov 2022 11:34:43 +0100 Subject: add tl--mute-thread --- lisp/mastodon-tl.el | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 49c26ea..fe865d0 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1508,6 +1508,46 @@ ID is that of the toot to view." ;; else just print the lone toot: (mastodon-tl--single-toot id))))))) + +(defun mastodon-tl--mute-thread () + "Mute the thread displayed in the current buffer." + (interactive) + (let ((endpoint (mastodon-tl--get-endpoint))) + (if (string-suffix-p "context" endpoint) ; thread view + (let* ((id + (save-match-data + (let ((str (string-match "statuses/\\(?2:[[:digit:]]+\\)/context" + endpoint))) + (match-string 2 endpoint)))) + (we-posted-p (mastodon-tl--user-in-thread-p id)) + (url (mastodon-http--api (format "statuses/%s/mute" id)))) + (if (not we-posted-p) + (message "You can only mute a thread you have posted in.") + (when (y-or-n-p "Mute this thread? ") + (let ((response (mastodon-http--post url))) + (mastodon-http--triage response + (lambda () + (message "Thread muted!")))))))))) + +(defun mastodon-tl--user-in-thread-p (id) + "Return non-nil if the logged-in user has posted to the current thread. +ID is that of the post the context is currently displayed for." + (let* ((context-json (mastodon-http--get-json + (mastodon-http--api (format "statuses/%s/context" id)) + nil :silent)) + (ancestors (alist-get 'ancestors context-json)) + (descendants (alist-get 'descendants context-json)) + (a-ids (mapcar (lambda (status) + (alist-get 'id + (alist-get 'account status))) + ancestors)) + (d-ids (mapcar (lambda (status) + (alist-get 'id + (alist-get 'account status))) + descendants))) + (or (member (mastodon-auth--get-account-id) a-ids) + (member (mastodon-auth--get-account-id) d-ids)))) + ;;; LISTS (defun mastodon-tl--get-users-lists () -- cgit v1.2.3 From fa82691cc42a4344015a4920ee0582a92897160b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 27 Nov 2022 11:44:34 +0100 Subject: unmute or mute a thread --- lisp/mastodon-tl.el | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index fe865d0..fbf1b7b 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1510,8 +1510,20 @@ ID is that of the toot to view." (defun mastodon-tl--mute-thread () - "Mute the thread displayed in the current buffer." + "Mute the thread displayed in the current buffer. +Note that you can only (un)mute threads you have posted in." (interactive) + (mastodon-tl--mute-or-unmute-thread)) + +(defun mastodon-tl--unmute-thread () + "Mute the thread displayed in the current buffer. +Note that you can only (un)mute threads you have posted in." + (interactive) + (mastodon-tl--mute-or-unmute-thread :unmute)) + +(defun mastodon-tl--mute-or-unmute-thread (&optional unmute) + "Mute a thread. +If UNMUTE, unmute it." (let ((endpoint (mastodon-tl--get-endpoint))) (if (string-suffix-p "context" endpoint) ; thread view (let* ((id @@ -1520,14 +1532,21 @@ ID is that of the toot to view." endpoint))) (match-string 2 endpoint)))) (we-posted-p (mastodon-tl--user-in-thread-p id)) - (url (mastodon-http--api (format "statuses/%s/mute" id)))) + (url (mastodon-http--api + (if unmute + (format "statuses/%s/unmute" id) + (format "statuses/%s/mute" id))))) (if (not we-posted-p) - (message "You can only mute a thread you have posted in.") - (when (y-or-n-p "Mute this thread? ") + (message "You can only (un)mute a thread you have posted in.") + (when (if unmute + (y-or-n-p "Unute this thread? ") + (y-or-n-p "Mute this thread? ")) (let ((response (mastodon-http--post url))) (mastodon-http--triage response (lambda () - (message "Thread muted!")))))))))) + (if unmute + (message "Thread unmuted!") + (message "Thread muted!"))))))))))) (defun mastodon-tl--user-in-thread-p (id) "Return non-nil if the logged-in user has posted to the current thread. -- cgit v1.2.3 From b9865a58cf7f73c5205390dbf4df32d723ba15af Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 27 Nov 2022 13:19:00 +0100 Subject: autoloads and docstrings --- lisp/mastodon-tl.el | 9 +++++++-- lisp/mastodon-toot.el | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index fbf1b7b..2503516 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -79,6 +79,11 @@ (autoload 'mastodon-http--build-params-string "mastodon-http") (autoload 'mastodon-notifications--filter-types-list "mastodon-notifications") (autoload 'mastodon-toot--get-toot-edits "mastodon-toot") +(autoload 'mastodon-toot--update-status-fields "mastodon-toot") +(autoload 'mastodon-toot--compose-buffer "mastodon-toot") + +(defvar mastodon-toot--visibility) +(defvar mastodon-active-user) (when (require 'mpv nil :no-error) (declare-function mpv-start "mpv")) @@ -1157,7 +1162,7 @@ this just means displaying toot client." (let* ((poll (mastodon-tl--field 'poll toot)) (expiry (mastodon-tl--field 'expires_at poll)) (expired-p (if (eq (mastodon-tl--field 'expired poll) :json-false) nil t)) - (multi (mastodon-tl--field 'multiple poll)) + ;; (multi (mastodon-tl--field 'multiple poll)) (voters-count (mastodon-tl--field 'voters_count poll)) (vote-count (mastodon-tl--field 'votes_count poll)) (options (mastodon-tl--field 'options poll)) @@ -1539,7 +1544,7 @@ If UNMUTE, unmute it." (if (not we-posted-p) (message "You can only (un)mute a thread you have posted in.") (when (if unmute - (y-or-n-p "Unute this thread? ") + (y-or-n-p "Unnute this thread? ") (y-or-n-p "Mute this thread? ")) (let ((response (mastodon-http--post url))) (mastodon-http--triage response diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 099ce10..ae7dae2 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -788,8 +788,8 @@ instance to edit a toot." (defun mastodon-toot--insert-toot-iter (it) "Insert iteration IT of toot." - (let ((content (alist-get 'content it)) - (account (alist-get 'account it))) + (let ((content (alist-get 'content it))) + ;; (account (alist-get 'account it)) ;; TODO: handle polls, media (mastodon-tl--render-text content))) @@ -827,7 +827,7 @@ eg. \"feduser@fed.social\" -> \"feduser@fed.social\"." ""))) (defun mastodon-toot--get-bounds (regex) - "Get bounds of tag or handle before point." + "Get bounds of tag or handle before point using REGEX." ;; needed because # and @ are not part of any existing thing at point (save-match-data (save-excursion -- cgit v1.2.3 From f1c5b02512287a07899f793d667ce6924cbe88e8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 27 Nov 2022 13:23:43 +0100 Subject: remove redundant str var --- lisp/mastodon-tl.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2503516..ff00252 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1533,9 +1533,9 @@ If UNMUTE, unmute it." (if (string-suffix-p "context" endpoint) ; thread view (let* ((id (save-match-data - (let ((str (string-match "statuses/\\(?2:[[:digit:]]+\\)/context" - endpoint))) - (match-string 2 endpoint)))) + (string-match "statuses/\\(?2:[[:digit:]]+\\)/context" + endpoint) + (match-string 2 endpoint))) (we-posted-p (mastodon-tl--user-in-thread-p id)) (url (mastodon-http--api (if unmute -- cgit v1.2.3 From 119d0de0ec1e916fc14a083368ac32e488d1263b Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 27 Nov 2022 17:08:33 +0100 Subject: update copyright/author attribution --- lisp/mastodon-discover.el | 2 ++ lisp/mastodon-http.el | 2 ++ lisp/mastodon-inspect.el | 2 ++ lisp/mastodon-media.el | 2 ++ lisp/mastodon-notifications.el | 2 ++ lisp/mastodon-profile.el | 2 ++ lisp/mastodon-tl.el | 1 + lisp/mastodon-toot.el | 1 + 8 files changed, 14 insertions(+) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index 08df46e..1b960e5 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -1,7 +1,9 @@ ;;; mastodon-discover.el --- Use Mastodon.el with discover.el -*- lexical-binding: t -*- ;; Copyright (C) 2019 Johnson Denen +;; Copyright (C) 2020-2022 Marty Hiatt ;; Author: Johnson Denen +;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 1.0.0 ;; Package-Requires: ((emacs "27.1")) diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index d677e57..9ef7aec 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -1,7 +1,9 @@ ;;; mastodon-http.el --- HTTP request/response functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen +;; Copyright (C) 2020-2022 Marty Hiatt ;; Author: Johnson Denen +;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 1.0.0 ;; Package-Requires: ((emacs "27.1") (request "0.3.0")) diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index cbf6a8e..112a753 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -1,7 +1,9 @@ ;;; mastodon-inspect.el --- Client for Mastodon -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen +;; Copyright (C) 2020-2022 Marty Hiatt ;; Author: Johnson Denen +;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 1.0.0 ;; Package-Requires: ((emacs "27.1")) diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index c783130..4e50dbc 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -1,7 +1,9 @@ ;;; mastodon-media.el --- Functions for inlining Mastodon media -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen +;; Copyright (C) 2020-2022 Marty Hiatt ;; Author: Johnson Denen +;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 1.0.0 ;; Package-Requires: ((emacs "27.1")) diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index f5ddea3..b7fe038 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -1,7 +1,9 @@ ;;; mastodon-notifications.el --- Notification functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen +;; Copyright (C) 2020-2022 Marty Hiatt ;; Author: Johnson Denen +;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 1.0.0 ;; Package-Requires: ((emacs "27.1")) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 1200972..babe308 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -1,7 +1,9 @@ ;;; mastodon-profile.el --- Functions for inspecting Mastodon profiles -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen +;; Copyright (C) 2020-2022 Marty Hiatt ;; Author: Johnson Denen +;; Marty Hiatt ;; Maintainer: Marty Hiatt ;; Version: 1.0.0 ;; Package-Requires: ((emacs "27.1")) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ff00252..76cca6c 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1,6 +1,7 @@ ;;; mastodon-tl.el --- HTTP request/response functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen +;; Copyright (C) 2020-2022 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 28733e1..121a590 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1,6 +1,7 @@ ;;; mastodon-toot.el --- Minor mode for sending Mastodon toots -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen +;; Copyright (C) 2020-2022 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt -- cgit v1.2.3 From c719316e92fa1c2a7986ac682ee54637082ede3f Mon Sep 17 00:00:00 2001 From: "Nicolas P. Rougier" Date: Sun, 27 Nov 2022 20:53:53 +0100 Subject: Modify relative time strings such as all string are <= 12 characters --- lisp/mastodon-tl.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 76cca6c..995360c 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -570,25 +570,25 @@ TIMESTAMP is assumed to be in the past." (relative-result (cond ((< seconds-difference 60) - (cons "less than a minute ago" + (cons "now" 60)) ((< seconds-difference (* 1.5 60)) - (cons "one minute ago" + (cons "1 minute ago" 90)) ;; at 90 secs ((< seconds-difference (* 60 59.5)) (funcall regular-response seconds-difference 60 "minute")) ((< seconds-difference (* 1.5 60 60)) - (cons "one hour ago" + (cons "1 hour ago" (* 60 90))) ;; at 90 minutes ((< seconds-difference (* 60 60 23.5)) (funcall regular-response seconds-difference (* 60 60) "hour")) ((< seconds-difference (* 1.5 60 60 24)) - (cons "one day ago" + (cons "1 day ago" (* 1.5 60 60 24))) ;; at a day and a half ((< seconds-difference (* 60 60 24 6.5)) (funcall regular-response seconds-difference (* 60 60 24) "day")) ((< seconds-difference (* 1.5 60 60 24 7)) - (cons "one week ago" + (cons "1 week ago" (* 1.5 60 60 24 7))) ;; a week and a half ((< seconds-difference (* 60 60 24 7 52)) (if (= 52 (floor (+ 0.5 (/ seconds-difference 60 60 24 7)))) @@ -596,7 +596,7 @@ TIMESTAMP is assumed to be in the past." (* 60 60 24 7 52)) (funcall regular-response seconds-difference (* 60 60 24 7) "week"))) ((< seconds-difference (* 1.5 60 60 24 365)) - (cons "one year ago" + (cons "1 year ago" (* 60 60 24 365 1.5))) ;; a year and a half (t (funcall regular-response seconds-difference (* 60 60 24 365.25) "year"))))) -- cgit v1.2.3 From c3212e28d9d82ea86210beaf58cac79f9386fb94 Mon Sep 17 00:00:00 2001 From: "Nicolas P. Rougier" Date: Mon, 28 Nov 2022 13:56:43 +0100 Subject: Better wording for now --- lisp/mastodon-tl.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 995360c..a8bccb9 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -570,7 +570,7 @@ TIMESTAMP is assumed to be in the past." (relative-result (cond ((< seconds-difference 60) - (cons "now" + (cons "just now" 60)) ((< seconds-difference (* 1.5 60)) (cons "1 minute ago" -- cgit v1.2.3 From f493eb003bfb03205b81073adca1448c72317242 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 28 Nov 2022 20:34:01 +0100 Subject: view, reschedule, cancel scheduled toots --- lisp/mastodon-tl.el | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index a8bccb9..4662fc3 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -257,6 +257,13 @@ types of mastodon links and not just shr.el-generated ones.") (keymap-canonicalize map)) "Keymap for when point is on list name.") +(defvar mastodon-tl--scheduled-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "r") 'mastodon-tl--reschedule-toot) + (define-key map (kbd "c") 'mastodon-tl--cancel-scheduled-toot) + (keymap-canonicalize map)) + "Keymap for when point is on a scheduled toot.") + (defvar mastodon-tl--byline-link-keymap (when (require 'mpv nil :no-error) (let ((map (make-sparse-keymap))) @@ -1836,6 +1843,97 @@ If ID is provided, use that list." (let* ((url (mastodon-http--api (format "lists/%s/accounts" list-id)))) (mastodon-http--get-json url))) +;;; SCHEDULED TOOTS + +(defun mastodon-tl--get-scheduled-toots (&optional id) + "Get the user's currently scheduled toots. +If ID, just return that toot." + (let* ((endpoint (if id + (format "scheduled_statuses/%s" id) + "scheduled_statuses")) + (url (mastodon-http--api endpoint))) + (mastodon-http--get-json url))) + +(defun mastodon-tl--reschedule-toot (&optional id) + "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)))))) + +(defun mastodon-tl--view-scheduled-toots () + "Show the user's scheduled toots in a new buffer." + (interactive) + (mastodon-tl--init-sync "scheduled-toots" + "scheduled_statuses" + 'mastodon-tl--insert-scheduled-toots)) + +(defun mastodon-tl--insert-scheduled-toots (json) + "Insert the user's scheduled toots." + (let ((scheduleds (mastodon-tl--get-scheduled-toots))) + (erase-buffer) + (insert (mastodon-tl--set-face + (concat "\n ------------\n" + " YOUR SCHEDULED TOOTS\n" + " ------------\n\n") + 'success) + (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) + (goto-char (point-min)) + (when json + (mastodon-tl--goto-next-toot)))) + +(defun mastodon-tl--insert-scheduled-toot (toot) + "Insert scheduled TOOT into the buffer." + (let* ((id (alist-get 'id toot)) + (scheduled (alist-get 'scheduled_at toot)) + (params (alist-get 'params toot)) + (text (alist-get 'text params))) + (insert + (propertize (concat text + " | " + scheduled) + 'byline t ; so we nav here + 'toot-id "0" ; so we nav here + 'face 'font-lock-comment-face + 'keymap mastodon-tl--scheduled-map + 'scheduled-json toot + 'id id) + "\n"))) + +(defun mastodon-tl--copy-scheduled-toot-text () + "Copy the text of the scheduled toot at point." + (interactive) + (let* ((toot (get-text-property (point) 'toot)) + (params (alist-get 'params toot)) + (text (alist-get 'text params))) + (kill-new text))) + +(defun mastodon-tl--cancel-scheduled-toot () + "Cancel the scheduled toot at point." + (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?") + (let ((response (mastodon-http--delete url))) + (mastodon-http--triage response + (lambda () + (mastodon-tl--view-scheduled-toots) + (message "Toot cancelled!"))))))) + ;;; FILTERS (defun mastodon-tl--create-filter () -- cgit v1.2.3 From 520b2f86006f2274146ccff4b78f9b765b2280d2 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 29 Nov 2022 10:19:10 +0100 Subject: tl.el section headings --- lisp/mastodon-tl.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index a8bccb9..913c7e7 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1446,6 +1446,8 @@ webapp" (reblog (alist-get 'reblog json))) (if reblog (alist-get 'id reblog) id))) +;;; THREADS + (defun mastodon-tl--single-toot (id) "View toot at point in separate buffer. ID is that of the toot to view." @@ -1961,7 +1963,7 @@ RESPONSE is the JSON returned by the server." (message "Looks like there's no toot or user at point?") ,@body)) -;;;; INSTANCES +;;; INSTANCES (defun mastodon-tl--view-own-instance (&optional brief) "View details of your own instance. -- 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-tl.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 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-tl.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-tl.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 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-tl.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 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-tl.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 ed41f1ce270a25e80b9e75d9da23cc6a7749b9a7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 29 Nov 2022 16:38:36 +0100 Subject: edit scheduled post keybindings --- lisp/mastodon-tl.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-tl.el') diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index f28c7c5..24887b6 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -264,6 +264,8 @@ types of mastodon links and not just shr.el-generated ones.") (let ((map (make-sparse-keymap))) (define-key map (kbd "r") 'mastodon-tl--reschedule-toot) (define-key map (kbd "c") 'mastodon-tl--cancel-scheduled-toot) + (define-key map (kbd "e") 'mastodon-tl--edit-scheduled-as-new) + (define-key map (kbd "") 'mastodon-tl--edit-scheduled-as-new) (keymap-canonicalize map)) "Keymap for when point is on a scheduled toot.") @@ -1879,7 +1881,7 @@ If ID, just return that toot." " ------------\n\n") 'success) (mastodon-tl--set-face - "[n/p - prev/next\n r - reschedule\n c - cancel]\n\n" + "[n/p - prev/next\n r - reschedule\n e/RET - edit toot\n c - cancel]\n\n" 'font-lock-comment-face)) (mapc (lambda (x) (mastodon-tl--insert-scheduled-toot x)) @@ -1916,6 +1918,7 @@ If ID, just return that toot." (defun mastodon-tl--cancel-scheduled-toot (&optional id no-confirm) "Cancel the scheduled toot at point. +ID is that of the scheduled toot to cancel. NO-CONFIRM means there is no ask or message, there is only do." (interactive) (let* ((id (or id (get-text-property (point) 'id))) -- cgit v1.2.3