aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-toot.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/mastodon-toot.el')
-rw-r--r--lisp/mastodon-toot.el32
1 files changed, 26 insertions, 6 deletions
diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el
index 99c202e..e203cda 100644
--- a/lisp/mastodon-toot.el
+++ b/lisp/mastodon-toot.el
@@ -78,6 +78,7 @@
(autoload 'mastodon-profile--update-preference "mastodon-profile")
(autoload 'mastodon-profile-fetch-server-account-settings "mastodon-profile")
(autoload 'mastodon-tl--render-text "mastodon-tl")
+(autoload 'mastodon-profile-fetch-server-account-settings-maybe "mastodon-profile")
;; for mastodon-toot--translate-toot-text
(autoload 'mastodon-tl--content "mastodon-tl")
@@ -208,12 +209,12 @@ send.")
nil t)))
(mastodon-profile--update-preference "privacy" vis :source)))
-(defun mastodon-toot--get-max-toot-chars (&optional _no-toot)
+(defun mastodon-toot--get-max-toot-chars (&optional no-toot)
"Fetch max_toot_chars from `mastodon-instance-url' asynchronously.
NO-TOOT means we are not calling from a toot buffer."
(mastodon-http--get-json-async
(mastodon-http--api "instance")
- 'mastodon-toot--get-max-toot-chars-callback 'no-toot))
+ 'mastodon-toot--get-max-toot-chars-callback no-toot))
(defun mastodon-toot--get-max-toot-chars-callback (json-response
&optional no-toot)
@@ -509,11 +510,12 @@ Pushes `mastodon-toot-current-toot-text' to
(message "Draft saved!")))
(defun mastodon-toot-empty-p (&optional text-only)
- "Return t if no text or attachments have been added to the compose buffer.
+ "Return t if no text, attachments, or polls have been added to the compose buffer.
TEXT-ONLY means don't check for attachments."
(and (if text-only
t
- (not mastodon-toot--media-attachments))
+ (not mastodon-toot--media-attachments)
+ (not mastodon-toot-poll))
(string-empty-p (mastodon-tl--clean-tabs-and-nl
(mastodon-toot--remove-docs)))))
@@ -961,11 +963,29 @@ which is used to attach it to a toot when posting."
(cl-loop for o in options
collect `(,key . ,o))))
+(defun mastodon-toot--fetch-max-poll-options ()
+ "Return the maximum number of poll options from the user's instance. "
+ (let* ((instance (mastodon-http--get-json (mastodon-http--api "instance"))))
+ (alist-get 'max_options
+ (alist-get 'polls
+ (alist-get 'configuration instance)
+ instance))))
+
+(defun mastodon-toot--read-poll-options-count (max)
+ "Read the user's choice of the number of options the poll should have.
+MAX is the maximum number set by their instance."
+ (let ((number (read-number
+ (format "Number of options [2-%s]: " max) 2)))
+ (if (> number max)
+ (error "You need to choose a number between 2 and %s" max)
+ number)))
+
(defun mastodon-toot--create-poll ()
"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 options [2-4]: " 2))
+ (let* ((max-options (mastodon-toot--fetch-max-poll-options))
+ (length (mastodon-toot--read-poll-options-count max-options))
(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? "))
@@ -1303,7 +1323,7 @@ a draft into the buffer."
(insert initial-text))))
;;;###autoload
-(add-hook 'mastodon-toot-mode-hook #'mastodon-profile-fetch-server-account-settings)
+(add-hook 'mastodon-toot-mode-hook #'mastodon-profile-fetch-server-account-settings-maybe)
(define-minor-mode mastodon-toot-mode
"Minor mode to capture Mastodon toots."