aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-tl.el
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-05-08 18:56:49 +0200
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-05-08 18:56:49 +0200
commitf1f45761bed72a41f915d78b94962cfe752ea155 (patch)
tree2e586ef0c7075aaef6a6dc4d23d32ffcede568b5 /lisp/mastodon-tl.el
parentf74946157071b103e5f9c9b038f112d3bf8565e5 (diff)
refactor mastodon-tl--format-poll-option
Diffstat (limited to 'lisp/mastodon-tl.el')
-rw-r--r--lisp/mastodon-tl.el31
1 files changed, 16 insertions, 15 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 7fffb77..5599609 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1197,6 +1197,20 @@ To disable showing the stats, customize
;; POLLS
+(defun mastodon-tl--format-poll-option (option-counter longest-option)
+ "Format a poll option. OPTION-COUNTER is just a counter.
+LONGEST-OPTION is the option whose length determines the formatting."
+ (format "%s: %s%s%s\n"
+ (setq option-counter (1+ option-counter))
+ (propertize (alist-get 'title option)
+ 'face 'success)
+ (make-string (1+ (- (length longest-option)
+ (length (alist-get 'title option))))
+ ?\ )
+ ;; TODO: disambiguate no votes from hidden votes
+ (format "[%s votes]" (or (alist-get 'votes_count option)
+ "0"))))
+
(defun mastodon-tl--get-poll (toot)
"If TOOT includes a poll, return it as a formatted string."
(let-alist (mastodon-tl--field 'poll toot) ; toot or reblog
@@ -1208,25 +1222,12 @@ To disable showing the stats, customize
(option-counter 0))
(concat "\nPoll: \n\n"
(mapconcat (lambda (option)
- (progn
- (format "%s: %s%s%s\n"
- (setq option-counter (1+ option-counter))
- (propertize (alist-get 'title option)
- 'face 'success)
- (make-string
- (1+
- (- (length longest-option)
- (length (alist-get 'title
- option))))
- ?\ )
- ;; TODO: disambiguate no votes from hidden votes
- (format "[%s votes]" (or (alist-get 'votes_count option)
- "0")))))
+ (mastodon-tl--format-poll-option option-counter longest-option))
.options
"\n")
"\n"
(propertize
- (cond (.voters_count ; sometimes it is nil
+ (cond (.voters_count ; sometimes it is nil
(if (= .voters_count 1)
(format "%s person | " .voters_count)
(format "%s people | " .voters_count)))