aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-05-08 08:09:18 +0200
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2023-05-08 08:09:18 +0200
commit471e90374d7be36fdeba9a7a7a97a7ca11159c2e (patch)
treef7ac8e003b4713eb51e6449a96d2ee216b0608a0
parent92e49d913475fffc8c269cd15940db8b1dac6c87 (diff)
let-alist tl--content
-rw-r--r--lisp/mastodon-tl.el106
1 files changed, 106 insertions, 0 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 93ea20c..1179cc3 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -1096,6 +1096,112 @@ HELP-ECHO, DISPLAY, and FACE are the text properties to add."
(concat help-echo "\nC-RET: play " type " with mpv"))))
+;;; INSERT TOOTS
+
+(defun mastodon-tl--content (toot)
+ "Retrieve text content from TOOT.
+Runs `mastodon-tl--render-text' and fetches poll or media."
+ (let-alist toot
+ (concat (mastodon-tl--render-text .content toot)
+ (when (or .reblog.poll .poll)
+ (mastodon-tl--get-poll toot))
+ (mastodon-tl--media toot))))
+
+(defun mastodon-tl--insert-status (toot body author-byline action-byline
+ &optional id base-toot detailed-p)
+ "Display the content and byline of timeline element TOOT.
+BODY will form the section of the toot above the byline.
+AUTHOR-BYLINE is an optional function for adding the author
+portion of the byline that takes one variable. By default it is
+`mastodon-tl--byline-author'.
+ACTION-BYLINE is also an optional function for adding an action,
+such as boosting favouriting and following to the byline. It also
+takes a single function. By default it is
+`mastodon-tl--byline-boosted'.
+ID is that of the status if it is a notification, which is
+attached as a `toot-id' property if provided. If the
+status is a favourite or boost notification, BASE-TOOT is the
+JSON of the toot responded to.
+DETAILED-P means display more detailed info. For now
+this just means displaying toot client."
+ (let ((start-pos (point)))
+ (insert
+ (propertize
+ (concat "\n"
+ body
+ " \n"
+ (mastodon-tl--byline toot author-byline action-byline detailed-p))
+ 'toot-id (or id ; notification's own id
+ (alist-get 'id toot)) ; toot id
+ 'base-toot-id (mastodon-tl--toot-id
+ ;; if status is a notif, get id from base-toot
+ ;; (-tl--toot-id toot) will not work here:
+ (or base-toot
+ ;; else normal toot with reblog check:
+ toot))
+ 'toot-json toot
+ 'base-toot base-toot)
+ "\n")
+ (when mastodon-tl--display-media-p
+ (mastodon-media--inline-images start-pos (point)))))
+
+;; from mastodon-alt.el:
+(defun mastodon-tl--toot-for-stats (&optional toot)
+ "Return the TOOT on which we want to extract stats.
+If no TOOT is given, the one at point is considered."
+ (let* ((original-toot (or toot (get-text-property (point) 'toot-json)))
+ (toot (or (alist-get 'status original-toot)
+ (when (alist-get 'type original-toot)
+ original-toot)
+ (alist-get 'reblog original-toot)
+ original-toot))
+ (type (alist-get 'type (or toot))))
+ (unless (member type '("follow" "follow_request"))
+ toot)))
+
+(defun mastodon-tl--toot-stats (toot)
+ "Return a right aligned string (using display align-to).
+String is filled with TOOT statistics (boosts, favs, replies).
+When the TOOT is a reblog (boost), statistics from reblogged
+toots are returned.
+To disable showing the stats, customize
+`mastodon-tl--show-stats'."
+ (when-let ((toot (mastodon-tl--toot-for-stats toot)))
+ (let* ((favourites-count (alist-get 'favourites_count toot))
+ (favourited (equal 't (alist-get 'favourited toot)))
+ (faves-prop (propertize (format "%s" favourites-count)
+ 'favourites-count favourites-count))
+ (boosts-count (alist-get 'reblogs_count toot))
+ (boosted (equal 't (alist-get 'reblogged toot)))
+ (boosts-prop (propertize (format "%s" boosts-count)
+ 'boosts-count boosts-count))
+ (replies-count (alist-get 'replies_count toot))
+ (favourites (format "%s %s" faves-prop ;favourites-count
+ (mastodon-tl--symbol 'favourite)))
+ (boosts (format "%s %s" boosts-prop ;boosts-count
+ (mastodon-tl--symbol 'boost)))
+ (replies (format "%s %s" replies-count (mastodon-tl--symbol 'reply)))
+ (status (concat
+ (propertize favourites
+ 'favourited-p favourited
+ 'favourites-field t
+ 'face font-lock-comment-face)
+ (propertize " | " 'face font-lock-comment-face)
+ (propertize boosts
+ 'boosted-p boosted
+ 'boosts-field t
+ 'face font-lock-comment-face)
+ (propertize " | " 'face font-lock-comment-face)
+ (propertize replies
+ 'replies-field t
+ 'replies-count replies-count
+ 'face font-lock-comment-face)))
+ (status (concat
+ (propertize " " 'display `(space :align-to (- right ,(+ (length status) 7))))
+ status)))
+ status)))
+
+
;; POLLS
(defun mastodon-tl--get-poll (toot)