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:30:43 +0200
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-05-08 18:30:43 +0200
commit03ee7ccc93a9285c6c50eec319c7844c60d3cda9 (patch)
tree56e4ef57a5ad95396fb1ae1d6061d7902b37a54e /lisp/mastodon-tl.el
parentedf718826a220a0754a53546d7efd35ff7264b29 (diff)
Revert "let-alist tl--get-poll"
This reverts commit c579efdef65e1d6a6ad29e0a609202cd59a683e2.
Diffstat (limited to 'lisp/mastodon-tl.el')
-rw-r--r--lisp/mastodon-tl.el87
1 files changed, 47 insertions, 40 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index edae3b8..d4d27c6 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1199,46 +1199,53 @@ To disable showing the stats, customize
(defun mastodon-tl--get-poll (toot)
"If TOOT includes a poll, return it as a formatted string."
- (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 .poll.expires_at)
- "Poll expired.")))
- (propertize str 'face 'font-lock-comment-face))
- "\n"))))
+ (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")))
(defun mastodon-tl--format-poll-expiry (timestamp)
"Convert poll expiry TIMESTAMP into a descriptive string."