aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-04-25 20:42:08 +0200
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-05-08 08:09:27 +0200
commitc579efdef65e1d6a6ad29e0a609202cd59a683e2 (patch)
treeab04005741dbbee96eb1a040be91f650326b2bd3
parent471e90374d7be36fdeba9a7a7a97a7ca11159c2e (diff)
let-alist tl--get-poll
-rw-r--r--lisp/mastodon-tl.el87
1 files changed, 40 insertions, 47 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 1179cc3..536ad62 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1206,53 +1206,46 @@ To disable showing the stats, customize
(defun mastodon-tl--get-poll (toot)
"If TOOT includes a poll, return it as a formatted string."
- (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))
- (voters-count (mastodon-tl--field 'voters_count poll))
- (vote-count (mastodon-tl--field 'votes_count poll))
- (options (mastodon-tl--field 'options poll))
- (option-titles (mastodon-tl--map-alist 'title options))
- (longest-option (car (sort option-titles
- (lambda (x y)
- (> (length x)
- (length y))))))
- (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")))))
- options
- "\n")
- "\n"
- (propertize
- (cond (voters-count ; sometimes it is nil
- (if (= voters-count 1)
- (format "%s person | " voters-count)
- (format "%s people | " voters-count)))
- (vote-count
- (format "%s votes | " vote-count))
- (t
- ""))
- 'face 'font-lock-comment-face)
- (let ((str (if expired-p
- "Poll expired."
- (mastodon-tl--format-poll-expiry expiry))))
- (propertize str 'face 'font-lock-comment-face))
- "\n")))
+ (let-alist toot
+ (let* ((option-titles (mastodon-tl--map-alist 'title .poll.options))
+ (longest-option (car (sort option-titles
+ (lambda (x y)
+ (> (length x)
+ (length y))))))
+ (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")))))
+ .poll.options
+ "\n")
+ "\n"
+ (propertize
+ (cond (.poll.voters_count ; sometimes it is nil
+ (if (= .poll.voters_count 1)
+ (format "%s person | " .poll.voters_count)
+ (format "%s people | " .poll.voters_count)))
+ (.poll.vote_count
+ (format "%s votes | " .poll.vote_count))
+ (t
+ ""))
+ 'face 'font-lock-comment-face)
+ (let ((str (if (eq .poll.expired :json-false)
+ (mastodon-tl--format-poll-expiry expiry)
+ "Poll expired.")))
+ (propertize str 'face 'font-lock-comment-face))
+ "\n"))))
(defun mastodon-tl--format-poll-expiry (timestamp)
"Convert poll expiry TIMESTAMP into a descriptive string."