aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-tl.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/mastodon-tl.el')
-rw-r--r--lisp/mastodon-tl.el195
1 files changed, 122 insertions, 73 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el
index 0e61e29..3ebfa4e 100644
--- a/lisp/mastodon-tl.el
+++ b/lisp/mastodon-tl.el
@@ -598,51 +598,77 @@ Do so if type of status at poins is not follow_request/follow."
(string= type "follow")) ; no counts for these
(message "%s" echo)))))
-(defun mastodon-tl--byline-author (toot &optional avatar domain)
+;; FIXME: now that this can also be used for non byline rendering, let's remove
+;; the toot arg, and deal with attachments higher up (on real author
+;; byline only)
+;; removing toot arg makes it easier to render notifs that have no status
+;; (foll_reqs)
+(defun mastodon-tl--byline-username (toot &optional account)
+ "Format a byline username from account in TOOT."
+ (let-alist (or account (alist-get 'account toot))
+ (propertize (if (not (string-empty-p .display_name))
+ .display_name
+ .username)
+ 'face 'mastodon-display-name-face
+ ;; enable playing of videos when point is on byline:
+ 'attachments (mastodon-tl--get-attachments-for-byline toot)
+ 'keymap mastodon-tl--byline-link-keymap
+ ;; echo faves count when point on post author name:
+ ;; which is where --goto-next-toot puts point.
+ 'help-echo
+ ;; but don't add it to "following"/"follows" on
+ ;; profile views: we don't have a tl--buffer-spec
+ ;; yet:
+ (unless (or (string-suffix-p "-followers*" (buffer-name))
+ (string-suffix-p "-following*" (buffer-name)))
+ (mastodon-tl--format-byline-help-echo toot)))))
+
+(defun mastodon-tl--byline-handle (toot &optional domain account)
+ "Format a byline handle from account in TOOT.
+DOMAIN is optionally added to the handle."
+ (let-alist (or account (alist-get 'account toot))
+ (propertize (concat "@" .acct
+ (when domain
+ (concat "@"
+ (url-host
+ (url-generic-parse-url .url)))))
+ 'face 'mastodon-handle-face
+ 'mouse-face 'highlight
+ 'mastodon-tab-stop 'user-handle
+ 'account account
+ 'shr-url .url
+ 'keymap mastodon-tl--link-keymap
+ 'mastodon-handle (concat "@" .acct)
+ 'help-echo (concat "Browse user profile of @" .acct))))
+
+(defun mastodon-tl--byline-uname-+-handle (data &optional domain account)
+ ""
+ (concat (mastodon-tl--byline-username data account)
+ " (" (mastodon-tl--byline-handle data domain account) ")"))
+
+(defun mastodon-tl--byline-author (toot &optional avatar domain base)
"Propertize author of TOOT.
+If TOOT contains a reblog, return author of reblogged item.
With arg AVATAR, include the account's avatar image.
-When DOMAIN, force inclusion of user's domain in their handle."
- (let-alist toot
+When DOMAIN, force inclusion of user's domain in their handle.
+BASE means to use data from the base item (reblog slot) if possible.
+If BASE is nil, we are a boosted byline, so show less info."
+ (let* ((data (if base
+ (mastodon-tl--toot-or-base toot)
+ toot)))
(concat
- ;; avatar insertion moved up to `mastodon-tl--byline' by default to be
- ;; outside 'byline propt.
+ ;; avatar insertion moved up to `mastodon-tl--byline' by default to
+ ;; be outside 'byline propt.
(when (and avatar ; used by `mastodon-profile--format-user'
mastodon-tl--show-avatars
mastodon-tl--display-media-p
(mastodon-tl--image-trans-check))
- (mastodon-media--get-avatar-rendering .account.avatar))
- ;; username:
- (propertize (if (not (string-empty-p .account.display_name))
- .account.display_name
- .account.username)
- 'face 'mastodon-display-name-face
- ;; enable playing of videos when point is on byline:
- 'attachments (mastodon-tl--get-attachments-for-byline toot)
- 'keymap mastodon-tl--byline-link-keymap
- ;; echo faves count when point on post author name:
- ;; which is where --goto-next-toot puts point.
- 'help-echo
- ;; but don't add it to "following"/"follows" on profile views:
- ;; we don't have a tl--buffer-spec yet:
- (unless (or (string-suffix-p "-followers*" (buffer-name))
- (string-suffix-p "-following*" (buffer-name)))
- (mastodon-tl--format-byline-help-echo toot)))
- ;; handle:
- " ("
- (propertize (concat "@" .account.acct
- (when domain
- (concat "@"
- (url-host
- (url-generic-parse-url .account.url)))))
- 'face 'mastodon-handle-face
- 'mouse-face 'highlight
- 'mastodon-tab-stop 'user-handle
- 'account .account
- 'shr-url .account.url
- 'keymap mastodon-tl--link-keymap
- 'mastodon-handle (concat "@" .account.acct)
- 'help-echo (concat "Browse user profile of @" .account.acct))
- ")")))
+ (mastodon-media--get-avatar-rendering
+ (alist-get 'avatar
+ (alist-get 'account data))))
+ (if (not base)
+ (mastodon-tl--byline-handle data domain)
+ (mastodon-tl--byline-uname-+-handle data domain)))))
(defun mastodon-tl--format-byline-help-echo (toot)
"Format a help-echo for byline of TOOT.
@@ -690,13 +716,28 @@ The result is added as an attachments property to author-byline."
:type .type)))
media)))
-(defun mastodon-tl--byline-boosted (toot)
- "Add byline for boosted data from TOOT."
+(defun mastodon-tl--byline-booster (toot)
+ "Add author byline for booster from TOOT.
+Only return something if TOOT contains a reblog."
(let ((reblog (alist-get 'reblog toot)))
- (when reblog
- (concat
- "\n " (propertize "Boosted" 'face 'mastodon-boosted-face)
- " " (mastodon-tl--byline-author reblog)))))
+ (if reblog
+ (concat
+ " " (mastodon-tl--byline-author toot))
+ "")))
+
+(defun mastodon-tl--byline-booster-str (toot)
+ "Format boosted string for action byline.
+Only return string if TOOT contains a reblog."
+ (let ((reblog (alist-get 'reblog toot)))
+ (if reblog
+ (concat
+ " " (propertize "boosted" 'face 'mastodon-boosted-face) "\n")
+ "")))
+
+(defun mastodon-tl--byline-boost (toot)
+ "Format a boost action-byline element for TOOT."
+ (concat (mastodon-tl--byline-booster toot)
+ (mastodon-tl--byline-booster-str toot)))
(defun mastodon-tl--format-faved-or-boosted-byline (letter)
"Format the byline marker for a boosted or favourited status.
@@ -719,8 +760,8 @@ LETTER is a string, F for favourited, B for boosted, or K for bookmarked."
(image-type-available-p 'imagemagick)
(image-transforms-p)))
-(defun mastodon-tl--byline (toot author-byline action-byline
- &optional detailed-p domain base-toot)
+(defun mastodon-tl--byline (toot author-byline &optional detailed-p
+ domain base-toot group)
"Generate byline for TOOT.
AUTHOR-BYLINE is a function for adding the author portion of
the byline that takes one variable.
@@ -732,23 +773,25 @@ this just means displaying toot client.
When DOMAIN, force inclusion of user's domain in their handle.
BASE-TOOT is JSON for the base toot, if any."
(let* ((created-time
- ;; bosts and faves in notifs view
- ;; (makes timestamps be for the original toot not the boost/fave):
- (or (mastodon-tl--field 'created_at
- (mastodon-tl--field 'status toot))
- ;; all other toots, inc. boosts/faves in timelines:
- ;; (mastodon-tl--field auto fetches from reblogs if needed):
- (mastodon-tl--field 'created_at toot)))
+ (if group
+ (mastodon-tl--field 'latest_page_notification_at group)
+ ;; bosts and faves in notifs view
+ ;; (makes timestamps be for the original toot not the boost/fave):
+ (or (mastodon-tl--field 'created_at
+ (mastodon-tl--field 'status toot))
+ ;; all other toots, inc. boosts/faves in timelines:
+ ;; (mastodon-tl--field auto fetches from reblogs if needed):
+ (mastodon-tl--field 'created_at toot))))
(parsed-time (date-to-time created-time))
(faved (eq t (mastodon-tl--field 'favourited toot)))
(boosted (eq t (mastodon-tl--field 'reblogged toot)))
(bookmarked (eq t (mastodon-tl--field 'bookmarked toot)))
(visibility (mastodon-tl--field 'visibility toot))
- (account (alist-get 'account toot))
- (avatar-url (alist-get 'avatar account))
(type (alist-get 'type toot))
(base-toot-maybe (or base-toot ;; show edits for notifs
(mastodon-tl--toot-or-base toot))) ;; for boosts
+ (account (alist-get 'account base-toot-maybe))
+ (avatar-url (alist-get 'avatar account))
(edited-time (alist-get 'edited_at base-toot-maybe))
(edited-parsed (when edited-time (date-to-time edited-time))))
(concat
@@ -768,17 +811,16 @@ BASE-TOOT is JSON for the base toot, if any."
(when bookmarked
(mastodon-tl--format-faved-or-boosted-byline
(mastodon-tl--symbol 'bookmark))))
- ;; we remove avatars from the byline also, so that they also do not mess
- ;; with `mastodon-tl--goto-next-item':
+ ;; we remove avatars from the byline also, so that they also do not
+ ;; mess with `mastodon-tl--goto-next-item':
(when (and mastodon-tl--show-avatars
mastodon-tl--display-media-p
(mastodon-tl--image-trans-check))
(mastodon-media--get-avatar-rendering avatar-url))
(propertize
(concat
- ;; we propertize help-echo format faves for author name
- ;; in `mastodon-tl--byline-author'
- (funcall author-byline toot nil domain)
+ ;; NB: action-byline (boost) is now added in insert-status, so no
+ ;; longer part of the byline.
;; visibility:
(cond ((string= visibility "direct")
(propertize (concat " " (mastodon-tl--symbol 'direct))
@@ -786,8 +828,8 @@ BASE-TOOT is JSON for the base toot, if any."
((string= visibility "private")
(propertize (concat " " (mastodon-tl--symbol 'private))
'help-echo visibility)))
- ;;action byline:
- (funcall action-byline toot)
+ ;; (base) author byline:
+ (funcall author-byline toot nil domain :base)
" "
;; timestamp:
(let ((ts (format-time-string
@@ -1164,7 +1206,7 @@ content should be hidden."
(save-excursion
(goto-char (point-min))
(while (not (string= "No more items" ; improve this hack test!
- (mastodon-tl--goto-next-item :no-refresh)))
+ (mastodon-tl--goto-next-item :no-refresh)))
(let* ((json (mastodon-tl--property 'item-json :no-move))
(cw (alist-get 'spoiler_text json)))
(when (not (string= "" cw))
@@ -1574,7 +1616,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media."
(defun mastodon-tl--insert-status
(toot body author-byline action-byline &optional id base-toot
- detailed-p thread domain unfolded no-byline)
+ detailed-p thread domain unfolded no-byline group accounts)
"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
@@ -1594,11 +1636,14 @@ THREAD means the status will be displayed in a thread view.
When DOMAIN, force inclusion of user's domain in their handle.
UNFOLDED is a boolean meaning whether to unfold or fold item if foldable.
NO-BYLINE means just insert toot body, used for folding."
- (let* ((reply-to-id (alist-get 'in_reply_to_id toot))
+ (let* ((reply-to-id
+ (if group
+ (alist-get 'status_id group)
+ (alist-get 'in_reply_to_id toot)))
(after-reply-status-p
(when (and thread reply-to-id)
(mastodon-tl--after-reply-status reply-to-id)))
- (type (alist-get 'type toot))
+ (type (alist-get 'type (or group toot)))
(toot-foldable
(and mastodon-tl--fold-toots-at-length
(length> body mastodon-tl--fold-toots-at-length))))
@@ -1625,9 +1670,11 @@ NO-BYLINE means just insert toot body, used for folding."
'toot-body t) ;; includes newlines etc. for folding
;; byline:
"\n"
- (unless no-byline
- (mastodon-tl--byline toot author-byline action-byline
- detailed-p domain base-toot)))
+ (if no-byline
+ ""
+ (concat (funcall action-byline toot)
+ (mastodon-tl--byline toot author-byline detailed-p
+ domain base-toot group))))
'item-type 'toot
'item-id (or id ; notification's own id
(alist-get 'id toot)) ; toot id
@@ -1639,9 +1686,11 @@ NO-BYLINE means just insert toot body, used for folding."
'item-json toot
'base-toot base-toot
'cursor-face 'mastodon-cursor-highlight-face
- 'notification-type type
'toot-foldable toot-foldable
- 'toot-folded (and toot-foldable (not unfolded)))
+ 'toot-folded (and toot-foldable (not unfolded))
+ 'notification-type type
+ 'notification-group group
+ 'notification-accounts accounts)
(if no-byline "" "\n"))))
(defun mastodon-tl--is-reply (toot)
@@ -1712,7 +1761,7 @@ NO-BYLINE means just insert toot body, used for folding."
(mastodon-tl--insert-status
toot
(mastodon-tl--clean-tabs-and-nl spoiler-or-content)
- 'mastodon-tl--byline-author 'mastodon-tl--byline-boosted
+ #'mastodon-tl--byline-author #'mastodon-tl--byline-boost
nil nil detailed-p thread domain unfolded no-byline))))
(defun mastodon-tl--timeline (toots &optional thread domain)
@@ -2806,7 +2855,7 @@ Aims to respect any pagination in effect."
((eq type 'mentions)
(mastodon-notifications--get-mentions))
((eq type 'notifications)
- (mastodon-notifications-get nil nil :force max-id))
+ (mastodon-notifications-get nil nil max-id))
((eq type 'profile-statuses-no-boosts)
;; TODO: max-id arg needed here also
(mastodon-profile--open-statuses-no-reblogs))