aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-05 12:43:12 +0100
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-11-05 15:50:25 +0100
commit8da3601be521952f0435b2692fe9d55f40bdb218 (patch)
treee98c3682758111a76a2466ad2243d8a7e9977732
parent2e89ac925f1198b5896061ec1d0442a9edbd8dcf (diff)
pretty expiry display and voter count
-rw-r--r--lisp/mastodon-tl.el24
1 files changed, 18 insertions, 6 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 3399791..2db5700 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -949,6 +949,7 @@ this just means displaying toot client."
(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))
+ (vote-count (mastodon-tl--field 'voters_count poll))
(options (mastodon-tl--field 'options poll))
(option-titles (mapcar (lambda (x)
(alist-get 'title x))
@@ -976,14 +977,25 @@ this just means displaying toot client."
"0")))))
options
"\n")
- (unless expired-p
- (propertize (format "Expires: %s" expiry)
- 'face 'font-lock-comment-face))
- (when expired-p
- (propertize "Poll expired."
- 'face 'font-lock-comment-face))
+ "\n"
+ (propertize (format "%s people | " vote-count)
+ 'face 'font-lock-comment-face)
+ (let ((str (if expired-p
+ "Poll expired."
+ (matodon-tl--format-poll-expiry expiry))))
+ (propertize str 'face 'font-lock-comment-face))
"\n")))
+(defun matodon-tl--format-poll-expiry (timestamp)
+ "Convert poll expiry TIMESTAMP into a descriptive string."
+ (let ((parsed (iso8601-parse timestamp)))
+ (cond ((> (decoded-time-day parsed) 0)
+ (format "%s days left" (decoded-time-day parsed)))
+ ((> (decoded-time-hour parsed) 0)
+ (format "%s hours left" (decoded-time-hour parsed)))
+ ((> (decoded-time-minute parsed) 0)
+ (format "%s minutes left" (decoded-time-minute parsed))))))
+
(defun mastodon-tl--poll-vote (option)
"If there is a poll at point, prompt user for OPTION to vote on it."
(interactive