aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-03 23:37:53 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-05 15:50:25 +0100
commitf5257ee34b46c383f537ab106fd3ae6a394efdfd (patch)
treec59db94b053e5951d3eb7135550335c54aeb6610 /lisp
parent6d11e60a7a0b661e0241dcd8372de53edbfbf27f (diff)
basic poll create funs
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-toot.el37
1 files changed, 36 insertions, 1 deletions
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 ()