From 4bfe8b8696ae36e3331f6900101aed003185be90 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 29 Oct 2022 13:27:51 +0200 Subject: restore -toot--kill fun for use with draft toot functionality --- lisp/mastodon-toot.el | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a96bdbf..bcf9c83 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -465,12 +465,16 @@ REPLY-ID, TOOT-VISIBILITY, and TOOT-CW of deleted toot are preseved." (mastodon-toot-set-cw toot-cw) (mastodon-toot--update-status-fields)))) -(defun mastodon-toot--kill () - "Kill `mastodon-toot-mode' buffer and window." - (with-current-buffer (get-buffer "*new toot*") - ;; FIXME: prevent some weird bug when cancelling a non-empty toot: - (delete #'mastodon-toot--save-toot-text after-change-functions) - (kill-buffer-and-window))) +(defun mastodon-toot--kill (&optional cancel) + "Kill `mastodon-toot-mode' buffer and window. +CANCEL means the toot was not sent, so we save the toot text as a draft." + (unless (eq mastodon-toot-current-toot-text nil) + (when cancel + (cl-pushnew mastodon-toot-current-toot-text + mastodon-toot-draft-toots-list :test 'equal))) + ;; prevent some weird bug when cancelling a non-empty toot: + (delete #'mastodon-toot-save-toot-text after-change-functions) + (kill-buffer-and-window)) (defun mastodon-toot--cancel () "Kill new-toot buffer/window. Does not POST content to Mastodon. -- cgit v1.2.3 From d93d1f15b7b02e7120ca2544b0c40295e6f62a09 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 31 Oct 2022 11:08:30 +0100 Subject: toot-mode-hook: profile-fetch-server-account-settings --- lisp/mastodon-toot.el | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index bcf9c83..9d2d02d 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -76,6 +76,7 @@ (autoload 'mastodon-toot "mastodon") (autoload 'mastodon-profile--get-source-pref "mastodon-profile") (autoload 'mastodon-profile--update-preference "mastodon-profile") +(autoload 'mastodon-profile-fetch-server-account-settings "mastodon-profile") (autoload 'mastodon-tl--render-text "mastodon-tl") ;; for mastodon-toot--translate-toot-text @@ -1187,6 +1188,9 @@ a draft into the buffer." (when initial-text (insert initial-text)))) +;;;###autoload +(add-hook 'mastodon-toot-mode-hook #'mastodon-profile-fetch-server-account-settings) + (define-minor-mode mastodon-toot-mode "Minor mode to capture Mastodon toots." :group 'mastodon-toot -- cgit v1.2.3 From b2d79eabd34040c9e8cadffb44ebcde771c35b33 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Mon, 31 Oct 2022 11:42:40 +0100 Subject: toot--kill: fix delete after change funs fun name --- 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 9d2d02d..bcb4af1 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -474,7 +474,7 @@ CANCEL means the toot was not sent, so we save the toot text as a draft." (cl-pushnew mastodon-toot-current-toot-text mastodon-toot-draft-toots-list :test 'equal))) ;; prevent some weird bug when cancelling a non-empty toot: - (delete #'mastodon-toot-save-toot-text after-change-functions) + (delete #'mastodon-toot--save-toot-text after-change-functions) (kill-buffer-and-window)) (defun mastodon-toot--cancel () -- cgit v1.2.3 From f5257ee34b46c383f537ab106fd3ae6a394efdfd Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 3 Nov 2022 23:37:53 +0100 Subject: basic poll create funs --- lisp/mastodon-toot.el | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index bcb4af1..a17fabb 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -162,6 +162,9 @@ change the setting on the server, see (defvar-local mastodon-toot--media-attachment-ids nil "A list of any media attachment ids of the toot being composed.") +(defvar-local mastodon-toot-poll-options nil + "A list of poll options for the toot being composed.") + (defvar-local mastodon-toot--reply-to-id nil "Buffer-local variable to hold the id of the toot being replied to.") @@ -188,6 +191,7 @@ send.") (define-key map (kbd "C-c C-e") #'mastodon-toot--insert-emoji)) (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) map) "Keymap for `mastodon-toot'.") @@ -615,7 +619,17 @@ If media items have been attached and uploaded with (mapcar (lambda (id) (cons "media_ids[]" id)) mastodon-toot--media-attachment-ids))) - (args (append args-media args-no-media))) + (args-poll (when mastodon-toot-poll-options + (append + (mastodon-toot--make-poll-params + mastodon-toot-poll-options) + `(("poll[expires_in]" . ,mastodon-toot-poll-expiry))))) + ;; media || polls: + (args (if mastodon-toot--media-attachments + (append args-media args-no-media) + (if mastodon-toot-poll-options + (append args-no-media args-poll) + args-no-media)))) (cond ((and mastodon-toot--media-attachments ;; make sure we have media args ;; and the same num of ids as attachments @@ -920,6 +934,27 @@ which is used to attach it to a toot when posting." mastodon-toot--media-attachments)) (list "None"))) +(defun mastodon-toot--make-poll-params (options) + "Returns an parameter query alist from poll OPTIONS." + (let ((key "poll[options][]")) + (cl-loop for o in options + collect `(,key . ,o)))) + +(defun mastodon-toot--create-poll () + "Prompt for new poll options and return as a list." + (interactive) + (let ((length (read-number "Number of poll options [2-4]: " 2))) + (setq mastodon-toot-poll-options + (cl-loop for x from 1 to length + collect (read-string (format "Poll option [%s/%s]: " x length)))) + (mastodon-toot--get-poll-expiry))) + +(defun mastodon-toot--get-poll-expiry () + "Prompt for a poll expiry time." + ;; API requires this in seconds + (setq mastodon-toot-poll-expiry + (read-string "poll ends in [seconds, min 5 mins]: "))) + ;; 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 af6cbd56602a4a1f56fd8bd9e6b8ac0d750bb0f5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 4 Nov 2022 12:33:12 +0100 Subject: basic poll creation, with all options polls docstrings etc cleanup --- lisp/mastodon-toot.el | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index a17fabb..44386f7 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -162,7 +162,7 @@ change the setting on the server, see (defvar-local mastodon-toot--media-attachment-ids nil "A list of any media attachment ids of the toot being composed.") -(defvar-local mastodon-toot-poll-options nil +(defvar-local mastodon-toot-poll nil "A list of poll options for the toot being composed.") (defvar-local mastodon-toot--reply-to-id nil @@ -599,6 +599,15 @@ to `emojify-user-emojis', and the emoji data is updated." (setq mastodon-toot--visibility visibility) (message "Visibility set to %s" visibility)) +(defun mastodon-toot--build-poll-params () + "Return an alist of parameters for POSTing a poll status." + (append + (mastodon-toot--make-poll-params + (plist-get mastodon-toot-poll :options)) + `(("poll[expires_in]" . ,(plist-get mastodon-toot-poll :expiry))) + `(("poll[multiple]" . ,(symbol-name (plist-get mastodon-toot-poll :multi)))) + `(("poll[hide_totals]" . ,(symbol-name (plist-get mastodon-toot-poll :hide)))))) + (defun mastodon-toot--send () "POST contents of new-toot buffer to Mastodon instance and kill buffer. If media items have been attached and uploaded with @@ -619,15 +628,12 @@ If media items have been attached and uploaded with (mapcar (lambda (id) (cons "media_ids[]" id)) mastodon-toot--media-attachment-ids))) - (args-poll (when mastodon-toot-poll-options - (append - (mastodon-toot--make-poll-params - mastodon-toot-poll-options) - `(("poll[expires_in]" . ,mastodon-toot-poll-expiry))))) + (args-poll (when mastodon-toot-poll + (mastodon-toot--build-poll-params))) ;; media || polls: (args (if mastodon-toot--media-attachments (append args-media args-no-media) - (if mastodon-toot-poll-options + (if mastodon-toot-poll (append args-no-media args-poll) args-no-media)))) (cond ((and mastodon-toot--media-attachments @@ -935,7 +941,7 @@ which is used to attach it to a toot when posting." (list "None"))) (defun mastodon-toot--make-poll-params (options) - "Returns an parameter query alist from poll OPTIONS." + "Return an parameter query alist from poll OPTIONS." (let ((key "poll[options][]")) (cl-loop for o in options collect `(,key . ,o)))) @@ -943,17 +949,26 @@ which is used to attach it to a toot when posting." (defun mastodon-toot--create-poll () "Prompt for new poll options and return as a list." (interactive) - (let ((length (read-number "Number of poll options [2-4]: " 2))) - (setq mastodon-toot-poll-options - (cl-loop for x from 1 to length - collect (read-string (format "Poll option [%s/%s]: " x length)))) - (mastodon-toot--get-poll-expiry))) + ;; re length, API docs show a poll 9 options. + (let* ((length (read-number "Number of poll options [2-9]: " 2)) + (multiple-p (y-or-n-p "Multiple choice poll? ")) + (options (mastodon-toot--read-poll-options length)) + (hide-totals (y-or-n-p "Hide votes until poll ends? ")) + (expiry (mastodon-toot--get-poll-expiry))) + (setq mastodon-toot-poll + `(:options ,options :length ,length :multi ,multiple-p :hide ,hide-totals :expiry ,expiry)) + (message "poll created!"))) + +(defun mastodon-toot--read-poll-options (length) + "Read a list of options for poll of LENGTH options." + (cl-loop for x from 1 to length + collect (read-string (format "Poll option [%s/%s]: " x length)))) (defun mastodon-toot--get-poll-expiry () "Prompt for a poll expiry time." ;; API requires this in seconds - (setq mastodon-toot-poll-expiry - (read-string "poll ends in [seconds, min 5 mins]: "))) + ;; TODO: offer sane poll expiry options + (read-string "poll ends in [seconds, min 5 mins]: ")) ;; we'll need to revisit this if the binds get ;; more diverse than two-chord bindings -- cgit v1.2.3 From 70c40eb1f903481fc7c2ff1fcbddf73411240412 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 5 Nov 2022 11:42:43 +0100 Subject: rename --make-poll-params to --make-poll-options-params --- 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 44386f7..29f9524 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -602,7 +602,7 @@ to `emojify-user-emojis', and the emoji data is updated." (defun mastodon-toot--build-poll-params () "Return an alist of parameters for POSTing a poll status." (append - (mastodon-toot--make-poll-params + (mastodon-toot--make-poll-options-params (plist-get mastodon-toot-poll :options)) `(("poll[expires_in]" . ,(plist-get mastodon-toot-poll :expiry))) `(("poll[multiple]" . ,(symbol-name (plist-get mastodon-toot-poll :multi)))) @@ -940,7 +940,7 @@ which is used to attach it to a toot when posting." mastodon-toot--media-attachments)) (list "None"))) -(defun mastodon-toot--make-poll-params (options) +(defun mastodon-toot--make-poll-options-params (options) "Return an parameter query alist from poll OPTIONS." (let ((key "poll[options][]")) (cl-loop for o in options -- cgit v1.2.3 From 2e89ac925f1198b5896061ec1d0442a9edbd8dcf Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 5 Nov 2022 11:43:10 +0100 Subject: poll - add collection of expiry times --- lisp/mastodon-toot.el | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 29f9524..bd24f6f 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -950,8 +950,8 @@ which is used to attach it to a toot when posting." "Prompt for new poll options and return as a list." (interactive) ;; re length, API docs show a poll 9 options. - (let* ((length (read-number "Number of poll options [2-9]: " 2)) - (multiple-p (y-or-n-p "Multiple choice poll? ")) + (let* ((length (read-number "Number of options [2-4]: " 2)) + (multiple-p (y-or-n-p "Multiple choice? ")) (options (mastodon-toot--read-poll-options length)) (hide-totals (y-or-n-p "Hide votes until poll ends? ")) (expiry (mastodon-toot--get-poll-expiry))) @@ -967,8 +967,25 @@ which is used to attach it to a toot when posting." (defun mastodon-toot--get-poll-expiry () "Prompt for a poll expiry time." ;; API requires this in seconds - ;; TODO: offer sane poll expiry options - (read-string "poll ends in [seconds, min 5 mins]: ")) + (let* ((options (mastodon-toot--poll-expiry-options-alist)) + (response (completing-read "poll ends in [or enter seconds]: " + options nil 'confirm))) + (or (alist-get response options nil nil #'equal) + (if (< (string-to-number response) 600) + "600" ;; min 5 mins + response)))) + +(defun mastodon-toot--poll-expiry-options-alist () + "Return an alist of seconds options." + `(("5 minutes" . ,(number-to-string (* 60 5))) + ("30 minutes" . ,(number-to-string (* 60 30))) + ("1 hour" . ,(number-to-string (* 60 60))) + ("6 hours" . ,(number-to-string (* 60 60 6))) + ("1 day" . ,(number-to-string (* 60 60 24))) + ("3 days" . ,(number-to-string (* 60 60 24 3))) + ("7 days" . ,(number-to-string (* 60 60 24 7))) + ("14 days" . ,(number-to-string (* 60 60 24 14))) + ("30 days" . ,(number-to-string (* 60 60 24 30))))) ;; we'll need to revisit this if the binds get ;; more diverse than two-chord bindings -- cgit v1.2.3