diff options
author | marty hiatt <martianhiatus@disroot.org> | 2024-11-01 16:07:08 +0100 |
---|---|---|
committer | marty hiatt <martianhiatus@disroot.org> | 2024-11-01 16:07:08 +0100 |
commit | 3ec8a8386b63e00042482bd52be74d48dc160f8a (patch) | |
tree | 2bc5c5311ef5214469eba95577f79bd61ca318c1 /lisp/mastodon-tl.el | |
parent | add6bfceafeb115d4665706ca76f3c1e5105d531 (diff) | |
parent | 1bf73f2528e35c28d41d48548ea65ab00bd8f689 (diff) |
Merge branch 'non-group-notifs' into develop
Diffstat (limited to 'lisp/mastodon-tl.el')
-rw-r--r-- | lisp/mastodon-tl.el | 140 |
1 files changed, 72 insertions, 68 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2db7f34..b5dfa2b 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -97,7 +97,8 @@ (defvar mastodon-toot--visibility) (defvar mastodon-toot-mode) (defvar mastodon-active-user) -(defvar mastodon-notifications--images-in-notifs) +(defvar mastodon-images-in-notifs) +(defvar mastodon-group-notifications) (when (require 'mpv nil :no-error) (declare-function mpv-start "mpv")) @@ -610,32 +611,31 @@ Do so if type of status at poins is not follow_request/follow." (string= type "follow")) ; no counts for these (message "%s" echo))))) -;; 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) +(defun mastodon-tl--byline-username (toot) "Format a byline username from account in TOOT. -ACCOUNT is optionally acccount data to use." - (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 string face) +TOOT may be account data, or toot data, in which case acount data +is extracted from it." + (let ((data (or (alist-get 'account toot) + toot))) ;; grouped nofifs use account data directly + (let-alist data + (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 data)))))) + +(defun mastodon-tl--byline-handle (toot &optional domain string face) "Format a byline handle from account in TOOT. DOMAIN is optionally added to the handle. ACCOUNT is optionally acccount data to use. @@ -643,7 +643,8 @@ STRING is optionally the string to propertize. FACE is optionally the face to use. The last two args allow for display a username as a clickable handle." - (let-alist (or account (alist-get 'account toot)) + (let-alist (or (alist-get 'account toot) + toot) ;; grouped notifs (propertize (or string (concat "@" .acct (when domain @@ -653,19 +654,18 @@ handle." 'face (or 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) +(defun mastodon-tl--byline-uname-+-handle (data &optional domain) "Concatenate a byline username and handle. DATA is the (toot) data to use. DOMAIN is optionally a domain for the handle. ACCOUNT is optionally acccount data to use." - (concat (mastodon-tl--byline-username data account) - " (" (mastodon-tl--byline-handle data domain account) ")")) + (concat (mastodon-tl--byline-username data) + " (" (mastodon-tl--byline-handle data domain) ")")) (defun mastodon-tl--display-or-uname (account) "Return display name or username from ACCOUNT data." @@ -673,7 +673,7 @@ ACCOUNT is optionally acccount data to use." (alist-get 'display_name account) (alist-get 'username account))) -(defun mastodon-tl--byline-author (toot &optional avatar domain base 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. @@ -684,7 +684,7 @@ ACCOUNT is optionally acccount data to use." (let* ((data (if base (mastodon-tl--toot-or-base toot) toot)) - (account (or account (alist-get 'account data))) + (account (alist-get 'account data)) (uname (mastodon-tl--display-or-uname account))) (concat ;; avatar insertion moved up to `mastodon-tl--byline' by default to @@ -701,11 +701,11 @@ ACCOUNT is optionally acccount data to use." " " ;; username as button: (mastodon-tl--byline-handle - data domain account + data domain ;; display uname not handle (for boosts): uname 'mastodon-display-name-face)) ;; normal combo author byline: - (mastodon-tl--byline-uname-+-handle data domain account))))) + (mastodon-tl--byline-uname-+-handle data domain))))) (defun mastodon-tl--format-byline-help-echo (toot) "Format a help-echo for byline of TOOT. @@ -796,14 +796,11 @@ 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 &optional detailed-p - domain base-toot group account ts) +(defun mastodon-tl--byline (toot &optional detailed-p + domain base-toot group ts) "Generate byline for TOOT. AUTHOR-BYLINE is a function for adding the author portion of the byline that takes one variable. -ACTION-BYLINE is a 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-author' DETAILED-P means display more detailed info. For now this just means displaying toot client. When DOMAIN, force inclusion of user's domain in their handle. @@ -811,7 +808,7 @@ BASE-TOOT is JSON for the base toot, if any. GROUP is the notification group if any. ACCOUNT is the notification account if any. TS is a timestamp from the server, if any." - (let* ((type (alist-get 'type group)) + (let* ((type (alist-get 'type (or group toot))) (created-time (or ts ;; mentions, statuses, folls/foll-reqs ;; bosts, faves, edits, polls in notifs view use base item @@ -822,17 +819,17 @@ TS is a timestamp from the server, if any." ;; (mastodon-tl--field auto fetches from reblogs if needed): (mastodon-tl--field 'created_at toot))) (parsed-time (when created-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)) - (type (alist-get 'type (or group toot))) - (base-toot-maybe (or base-toot ;; show edits for notifs - (mastodon-tl--toot-or-base toot))) ;; for boosts - (account (or account - (alist-get 'account base-toot-maybe))) + ;; non-grouped notifs now need to pull the following data from + ;; base toot: + (base-maybe (or base-toot ;; show edits for notifs + (mastodon-tl--toot-or-base toot))) ;; for boosts + (faved (eq t (mastodon-tl--field 'favourited base-maybe))) + (boosted (eq t (mastodon-tl--field 'reblogged base-maybe))) + (bookmarked (eq t (mastodon-tl--field 'bookmarked base-maybe))) + (visibility (mastodon-tl--field 'visibility base-maybe)) + (account (alist-get 'account base-maybe)) (avatar-url (alist-get 'avatar account)) - (edited-time (alist-get 'edited_at base-toot-maybe)) + (edited-time (alist-get 'edited_at base-maybe)) (edited-parsed (when edited-time (date-to-time edited-time)))) (concat ;; Boosted/favourited markers are not technically part of the byline, so @@ -862,7 +859,10 @@ TS is a timestamp from the server, if any." ;; NB: action-byline (boost) is now added in insert-status, so no ;; longer part of the byline. ;; (base) author byline: - (funcall author-byline toot nil domain :base account) + ;; we use base-toot if poss for fave/boost notifs that need to show + ;; base item in author byline + (mastodon-tl--byline-author (or base-toot toot) + nil domain :base) ;; visibility: (cond ((string= visibility "direct") (propertize (concat " " (mastodon-tl--symbol 'direct)) @@ -925,7 +925,7 @@ TS is a timestamp from the server, if any." 'edited edited-time 'edit-history (when edited-time (mastodon-toot--get-toot-edits - (alist-get 'id base-toot-maybe))) + (alist-get 'id base-maybe))) 'byline t)))) @@ -1324,7 +1324,7 @@ SENSITIVE is a flag from the item's JSON data." ;; if in notifs, also check notifs images custom: (if (or (mastodon-tl--buffer-type-eq 'notifications) (mastodon-tl--buffer-type-eq 'mentions)) - mastodon-notifications--images-in-notifs + mastodon-images-in-notifs t)) (mastodon-media--get-media-link-rendering ; placeholder: "[img]" .preview_url remote-url ; for shr-browse-url @@ -1652,7 +1652,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (string= reply-to-id prev-id))) (defun mastodon-tl--insert-status - (toot body author-byline action-byline &optional id base-toot + (toot body action-byline &optional id base-toot detailed-p thread domain unfolded no-byline) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. @@ -1707,8 +1707,7 @@ NO-BYLINE means just insert toot body, used for folding." "\n" (if no-byline "" - (mastodon-tl--byline toot author-byline detailed-p - domain base-toot))) + (mastodon-tl--byline toot detailed-p domain base-toot))) 'item-type 'toot 'item-id (or id ; notification's own id (alist-get 'id toot)) ; toot id @@ -1792,16 +1791,16 @@ NO-CW means treat content warnings as unfolded." ;; even though item may also have a "warn" filter: (unless (and filtered (assoc "hide" filters)) ;; no insert (mastodon-tl--insert-status - toot - (mastodon-tl--clean-tabs-and-nl spoiler-or-content) - #'mastodon-tl--byline-author #'mastodon-tl--byline-boost - nil nil detailed-p thread domain unfolded no-byline)))) + toot (mastodon-tl--clean-tabs-and-nl spoiler-or-content) + #'mastodon-tl--byline-boost nil nil detailed-p + thread domain unfolded no-byline)))) (defun mastodon-tl--timeline (toots &optional thread domain no-byline) "Display each toot in TOOTS. This function removes replies if user required. THREAD means the status will be displayed in a thread view. -When DOMAIN, force inclusion of user's domain in their handle." +When DOMAIN, force inclusion of user's domain in their handle. +NO-BYLINE means just insert toot body, used for folding." (let ((start-pos (point)) (toots ;; hack to *not* filter replies on profiles: (if (eq (mastodon-tl--get-buffer-type) 'profile-statuses) @@ -2254,8 +2253,9 @@ If we are in a notifications view, return `notifications-min-id'." (save-excursion (goto-char (point-max)) (mastodon-tl--property - (if (member (mastodon-tl--get-buffer-type) - '(mentions notifications)) + (if (and mastodon-group-notifications + (member (mastodon-tl--get-buffer-type) + '(mentions notifications))) 'notifications-min-id 'item-id) nil :backward))) @@ -2879,7 +2879,8 @@ the current view." (args (append args params)) (url (mastodon-http--api endpoint - (when (or (string= endpoint "notifications") + (when (or (and mastodon-group-notifications + (string= endpoint "notifications")) (string-suffix-p "search" endpoint)) "v2")))) (apply #'mastodon-http--get-json-async url args callback cbargs))) @@ -3272,7 +3273,8 @@ favourites and bookmarks. PARAMS is any parameters to send with the request. HIDE-REPLIES is a flag indicating if replies are hidden in the current buffer. INSTANCE is a string of another instance domain we are displaying -a timeline from." +a timeline from. +NO-BYLINE means just insert toot body, used for announcements." (let ((url (if instance (concat "https://" instance "/api/v1/" endpoint) (mastodon-http--api endpoint))) @@ -3292,7 +3294,8 @@ a timeline from." UPDATE-FUNCTION is used to recieve more toots. RESPONSE is the data returned from the server by `mastodon-http--process-json', with arg HEADERS a cons cell of -JSON and http headers, without it just the JSON." +JSON and http headers, without it just the JSON. +NO-BYLINE means just insert toot body, used for announcements." (let ((json (if headers (car response) response))) (cond ((not json) ; praying this is right here, else try "\n[]" ;; this means that whatever tl was inited won't load, which is not @@ -3364,7 +3367,8 @@ ENDPOINT-VERSION is a string, format Vx, e.g. V2." (defun mastodon-tl--do-init (json update-fun &optional domain no-byline) "Utility function for `mastodon-tl--init*' and `mastodon-tl--init-sync'. JSON is the data to call UPDATE-FUN on. -When DOMAIN, force inclusion of user's domain in their handle." +When DOMAIN, force inclusion of user's domain in their handle. +NO-BYLINE means just insert toot body, used for announcements." (remove-overlays) ; video overlays (cond (domain ;; maybe our update-fun doesn't always have 3 args...: (funcall update-fun json nil domain)) |