From 71c68ba64c5be9d6bcf473d46aea2c0977b80048 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 4 Oct 2024 11:42:52 +0200 Subject: add images in notifs customize --- lisp/mastodon-notifications.el | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 1c2aad7..1a1c4ed 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -70,6 +70,10 @@ If unset, profile notes of any size will be displayed, which may make them unweildy." :type '(integer)) +(defcustom mastodon-notifications--images-in-notifs nil + "Whether to display attached images in notifications." + :type '(boolean)) + (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--display-media-p) @@ -301,6 +305,8 @@ Call its function in that list on NOTE." (when fun (funcall fun note) (when mastodon-tl--display-media-p + ;; images-in-notifs custom is handeld in + ;; `mastodon-tl--media-attachment', not here (mastodon-media--inline-images start-pos (point)))))) (defun mastodon-notifications--timeline (json) -- cgit v1.2.3 From 567b116357143488980e0294caf900624b48468a Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 4 Oct 2024 11:46:56 +0200 Subject: notifs: don't require mastodon! require subr-x, autoloads --- lisp/mastodon-notifications.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 1a1c4ed..bab2e13 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -30,7 +30,7 @@ ;;; Code: -(require 'mastodon) +(eval-when-compile (require 'subr-x)) (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--get-params-async-json "mastodon-http") @@ -52,6 +52,10 @@ (autoload 'mastodon-tl--item-id "mastodon-tl") (autoload 'mastodon-tl--update "mastodon-tl") (autoload 'mastodon-views--view-follow-requests "mastodon-views") +(autoload 'mastodon-tl--current-filters "mastodon-views") +(autoload 'mastodon-tl--render-text "mastodon-tl") +(autoload 'mastodon-notifications-get "mastodon") + (defgroup mastodon-tl nil "Nofications in mastodon.el." @@ -76,6 +80,7 @@ make them unweildy." (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--display-media-p) +(defvar mastodon-mode-map) (defvar mastodon-notifications--types-alist '(("follow" . mastodon-notifications--follow) -- cgit v1.2.3 From 6d2865f5034043be7f3653f44f533ebb969e79c5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Tue, 8 Oct 2024 18:06:18 +0200 Subject: add mastodon-notifications--get-unread-count --- lisp/mastodon-notifications.el | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index bab2e13..ce3aea8 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -380,5 +380,12 @@ Status notifications are created when you call (mastodon-tl--reload-timeline-or-profile)) (message "Notification dismissed!"))))) +(defun mastodon-notifications--get-unread-count () + "Return the number of unread notifications for the current account." + ;; params: limit - max 1000, default 100, types[], exclude_types[], account_id + (let* ((endpoint "notifications/unread_count") + (url (mastodon-http--api endpoint))) + (mastodon-http--get-json url))) + (provide 'mastodon-notifications) ;;; mastodon-notifications.el ends here -- cgit v1.2.3 From 4b37b7c908ab1ebfa03ccdeafea42494c9c82614 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 10 Oct 2024 10:29:59 +0200 Subject: unread notifs: return number directly --- lisp/mastodon-notifications.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index ce3aea8..0c56cbb 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -384,8 +384,9 @@ Status notifications are created when you call "Return the number of unread notifications for the current account." ;; params: limit - max 1000, default 100, types[], exclude_types[], account_id (let* ((endpoint "notifications/unread_count") - (url (mastodon-http--api endpoint))) - (mastodon-http--get-json url))) + (url (mastodon-http--api endpoint)) + (resp (mastodon-http--get-json url))) + (alist-get 'count resp))) (provide 'mastodon-notifications) ;;; mastodon-notifications.el ends here -- cgit v1.2.3 From fbcec02f9072bd61908deef311b322f6b0719410 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 10 Oct 2024 19:45:40 +0200 Subject: 1st mockup of grouped notifs --- lisp/mastodon-notifications.el | 281 ++++++++++++++++++++++++----------------- lisp/mastodon.el | 3 +- 2 files changed, 164 insertions(+), 120 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 0c56cbb..0e27ca0 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -162,39 +162,39 @@ Can be called in notifications view or in follow-requests view." (interactive) (mastodon-notifications--follow-request-process :reject)) -(defun mastodon-notifications--mention (note) +(defun mastodon-notifications--mention (group json) "Format for a `mention' NOTE." - (mastodon-notifications--format-note note 'mention)) + (mastodon-notifications--format-note group json 'mention)) -(defun mastodon-notifications--follow (note) +(defun mastodon-notifications--follow (group json) "Format for a `follow' NOTE." - (mastodon-notifications--format-note note 'follow)) + (mastodon-notifications--format-note group json 'follow)) -(defun mastodon-notifications--follow-request (note) +(defun mastodon-notifications--follow-request (group json) "Format for a `follow-request' NOTE." - (mastodon-notifications--format-note note 'follow-request)) + (mastodon-notifications--format-note group json 'follow-request)) -(defun mastodon-notifications--favourite (note) +(defun mastodon-notifications--favourite (group json) "Format for a `favourite' NOTE." - (mastodon-notifications--format-note note 'favourite)) + (mastodon-notifications--format-note group json 'favourite)) -(defun mastodon-notifications--reblog (note) +(defun mastodon-notifications--reblog (group json) "Format for a `boost' NOTE." - (mastodon-notifications--format-note note 'boost)) + (mastodon-notifications--format-note group json 'reblog)) -(defun mastodon-notifications--status (note) +(defun mastodon-notifications--status (group json) "Format for a `status' NOTE. Status notifications are given when `mastodon-tl--enable-notify-user-posts' has been set." - (mastodon-notifications--format-note note 'status)) + (mastodon-notifications--format-note group json 'status)) -(defun mastodon-notifications--poll (note) +(defun mastodon-notifications--poll (group json) "Format for a `poll' NOTE." - (mastodon-notifications--format-note note 'poll)) + (mastodon-notifications--format-note group json 'poll)) -(defun mastodon-notifications--edit (note) +(defun mastodon-notifications--edit (group json) "Format for an `edit' NOTE." - (mastodon-notifications--format-note note 'edit)) + (mastodon-notifications--format-note group json 'edit)) (defun mastodon-notifications--comment-note-text (str) "Add comment face to all text in STR with `shr-text' face only." @@ -208,118 +208,161 @@ Status notifications are given when '(face (font-lock-comment-face shr-text))))) (buffer-string))) -(defun mastodon-notifications--format-note (note type) +(defvar mastodon-notifications-grouped-types + '(follow boost favourite) + "List of notification types for which grouping is implemented.") + +(defvar mastodon-notifications--action-alist + '((reblog . "Boosted") + (favourite . "Favourited") + (follow-request . "Requested to follow") + (follow . "Followed") + (mention . "Mentioned") + (status . "Posted") + (poll . "Posted a poll") + (edit . "Edited"))) + +(defun mastodon-notifications--alist-by-value (str field json) + "From JSON, return the alist whose FIELD value matches STR. +JSON is a list of alists." + (cl-some (lambda (y) + (when (string= str (alist-get field y)) + y)) + json)) + +(defun mastodon-notifications--group-accounts (ids json) + "For IDS, return account data in JSON." + (cl-loop + for x in ids + collect (mastodon-notifications--alist-by-value x 'id json))) + +(defun mastodon-notifications--format-note (group json type) "Format for a NOTE of TYPE." ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot' - (let* ((id (alist-get 'id note)) - (profile-note - (when (eq 'follow-request type) - (let ((str (mastodon-tl--field - 'note - (mastodon-tl--field 'account note)))) - (if mastodon-notifications--profile-note-in-foll-reqs-max-length - (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) - str)))) - (status (mastodon-tl--field 'status note)) - (follower (alist-get 'username (alist-get 'account note))) - (toot (alist-get 'status note)) - (filtered (mastodon-tl--field 'filtered toot)) - (filters (when filtered - (mastodon-tl--current-filters filtered)))) - (if (and filtered (assoc "hide" filters)) - nil - (mastodon-tl--insert-status - ;; toot - (cond ((or (eq type 'follow) - (eq type 'follow-request)) - ;; Using reblog with an empty id will mark this as something - ;; non-boostable/non-favable. - (cons '(reblog (id . nil)) note)) - ;; reblogs/faves use 'note' to process their own json - ;; not the toot's. this ensures following etc. work on such notifs - ((or (eq type 'favourite) - (eq type 'boost)) - note) - (t - status)) - ;; body - (let ((body (if-let ((match (assoc "warn" filters))) - (mastodon-tl--spoiler toot (cadr match)) - (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler status) - (mastodon-tl--spoiler status) - (if (eq 'follow-request type) - (mastodon-tl--render-text profile-note) - (mastodon-tl--content status))))))) - (cond ((or (eq type 'follow) - (eq type 'follow-request)) - (if (eq type 'follow) - (propertize "Congratulations, you have a new follower!" - 'face 'default) - (concat - (propertize - (format "You have a follow request from... %s" - follower) - 'face 'default) - (when mastodon-notifications--profile-note-in-foll-reqs - (concat - ":\n" - (mastodon-notifications--comment-note-text body)))))) - ((or (eq type 'favourite) - (eq type 'boost)) - (mastodon-notifications--comment-note-text body)) - (t body))) - ;; author-byline - (if (or (eq type 'follow) - (eq type 'follow-request) - (eq type 'mention)) - 'mastodon-tl--byline-author - (lambda (_status &rest _args) ; unbreak stuff - (mastodon-tl--byline-author note))) - ;; action-byline - (lambda (_status) - (mastodon-notifications--byline-concat - (cond ((eq type 'boost) - "Boosted") - ((eq type 'favourite) - "Favourited") - ((eq type 'follow-request) - "Requested to follow") - ((eq type 'follow) - "Followed") - ((eq type 'mention) - "Mentioned") - ((eq type 'status) - "Posted") - ((eq type 'poll) - "Posted a poll") - ((eq type 'edit) - "Edited")))) - id - ;; base toot - (when (or (eq type 'favourite) - (eq type 'boost)) - status))))) - -(defun mastodon-notifications--by-type (note) + ;; (if (member type mastodon-notifications-grouped-types) + (let-alist group + ;; .sample_account_ids .status_id .notifications_count + ;; .most_recent_notifiation_id + (let* ((status (mastodon-notifications--alist-by-value + .status_id 'id (alist-get 'statuses json))) + (accounts (mastodon-notifications--group-accounts + .sample_account_ids (alist-get 'accounts json)))) + (insert (symbol-name type) "\n" + "accounts: " (mapconcat 'identity .sample_account_ids ", ") "\n" + (if (not (> .notifications_count (length .sample_account_ids))) + "" + (concat + "and" + (number-to-string + (- .notifications_count + (length .sample_account_ids)))) + "others \n") + ;; "count: " (number-to-string .notifications_count) + (alist-get type mastodon-notifications--action-alist) + "\n toot: " (or .status_id "") "\n" + "\n\n")) + )) + +;; non-grouped notifs: +;; (let* ((id (alist-get 'id note)) +;; (profile-note +;; (when (eq 'follow-request type) +;; (let ((str (mastodon-tl--field +;; 'note +;; (mastodon-tl--field 'account note)))) +;; (if mastodon-notifications--profile-note-in-foll-reqs-max-length +;; (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) +;; str)))) +;; (status (mastodon-tl--field 'status note)) +;; (follower (alist-get 'username (alist-get 'account note))) +;; (toot (alist-get 'status note)) +;; (filtered (mastodon-tl--field 'filtered toot)) +;; (filters (when filtered +;; (mastodon-tl--current-filters filtered)))) +;; (if (and filtered (assoc "hide" filters)) +;; nil +;; (mastodon-tl--insert-status +;; ;; toot +;; (cond ((or (eq type 'follow) +;; (eq type 'follow-request)) +;; ;; Using reblog with an empty id will mark this as something +;; ;; non-boostable/non-favable. +;; (cons '(reblog (id . nil)) note)) +;; ;; reblogs/faves use 'note' to process their own json +;; ;; not the toot's. this ensures following etc. work on such notifs +;; ((or (eq type 'favourite) +;; (eq type 'boost)) +;; note) +;; (t +;; status)) +;; ;; body +;; (let ((body (if-let ((match (assoc "warn" filters))) +;; (mastodon-tl--spoiler toot (cadr match)) +;; (mastodon-tl--clean-tabs-and-nl +;; (if (mastodon-tl--has-spoiler status) +;; (mastodon-tl--spoiler status) +;; (if (eq 'follow-request type) +;; (mastodon-tl--render-text profile-note) +;; (mastodon-tl--content status))))))) +;; (cond ((or (eq type 'follow) +;; (eq type 'follow-request)) +;; (if (eq type 'follow) +;; (propertize "Congratulations, you have a new follower!" +;; 'face 'default) +;; (concat +;; (propertize +;; (format "You have a follow request from... %s" +;; follower) +;; 'face 'default) +;; (when mastodon-notifications--profile-note-in-foll-reqs +;; (concat +;; ":\n" +;; (mastodon-notifications--comment-note-text body)))))) +;; ((or (eq type 'favourite) +;; (eq type 'boost)) +;; (mastodon-notifications--comment-note-text body)) +;; (t body))) +;; ;; author-byline +;; (if (or (eq type 'follow) +;; (eq type 'follow-request) +;; (eq type 'mention)) +;; 'mastodon-tl--byline-author +;; (lambda (_status &rest _args) ; unbreak stuff +;; (mastodon-tl--byline-author note))) +;; ;; action-byline +;; (lambda (_status) +;; (mastodon-notifications--byline-concat +;; (alist-get type mastodon-notifications--action-alist) +;; )) +;; id +;; ;; base toot +;; (when (or (eq type 'favourite) +;; (eq type 'boost)) +;; status)))))) + +(defun mastodon-notifications--by-type (groups json) "Filter NOTE for those listed in `mastodon-notifications--types-alist'. Call its function in that list on NOTE." - (let* ((type (mastodon-tl--field 'type note)) - (fun (cdr (assoc type mastodon-notifications--types-alist))) - (start-pos (point))) - (when fun - (funcall fun note) - (when mastodon-tl--display-media-p - ;; images-in-notifs custom is handeld in - ;; `mastodon-tl--media-attachment', not here - (mastodon-media--inline-images start-pos (point)))))) + (cl-loop for g in groups + for type = (alist-get 'type g) + for fun = (cdr (assoc type mastodon-notifications--types-alist)) + for start-pos = (point) + do (when fun + (funcall fun g json) + (when mastodon-tl--display-media-p + ;; images-in-notifs custom is handeld in + ;; `mastodon-tl--media-attachment', not here + (mastodon-media--inline-images start-pos (point)))))) (defun mastodon-notifications--timeline (json) "Format JSON in Emacs buffer." (if (seq-empty-p json) (user-error "Looks like you have no (more) notifications for now") - (mapc #'mastodon-notifications--by-type json) - (goto-char (point-min)))) + (let ((groups (alist-get 'notification_groups json))) + ;; (mapc (lambda (x) + (mastodon-notifications--by-type groups json) + ;; grouped) + (goto-char (point-min))))) (defun mastodon-notifications--get-mentions () "Display mention notifications in buffer." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index a8714f3..cc02e8a 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -366,7 +366,8 @@ from the server and load anew." 'mastodon-notifications--timeline type (when max-id - `(("max_id" . ,(mastodon-tl--buffer-property 'max-id))))) + `(("max_id" . ,(mastodon-tl--buffer-property 'max-id)))) + nil nil nil "v2") (with-current-buffer buffer (use-local-map mastodon-notifications--map))))) -- cgit v1.2.3 From 7edfe0c4828145c75e5cb2e260c60463f8b24a4d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 09:20:56 +0200 Subject: remove notifs type funs --- lisp/mastodon-notifications.el | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 0e27ca0..6e21744 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -162,40 +162,6 @@ Can be called in notifications view or in follow-requests view." (interactive) (mastodon-notifications--follow-request-process :reject)) -(defun mastodon-notifications--mention (group json) - "Format for a `mention' NOTE." - (mastodon-notifications--format-note group json 'mention)) - -(defun mastodon-notifications--follow (group json) - "Format for a `follow' NOTE." - (mastodon-notifications--format-note group json 'follow)) - -(defun mastodon-notifications--follow-request (group json) - "Format for a `follow-request' NOTE." - (mastodon-notifications--format-note group json 'follow-request)) - -(defun mastodon-notifications--favourite (group json) - "Format for a `favourite' NOTE." - (mastodon-notifications--format-note group json 'favourite)) - -(defun mastodon-notifications--reblog (group json) - "Format for a `boost' NOTE." - (mastodon-notifications--format-note group json 'reblog)) - -(defun mastodon-notifications--status (group json) - "Format for a `status' NOTE. -Status notifications are given when -`mastodon-tl--enable-notify-user-posts' has been set." - (mastodon-notifications--format-note group json 'status)) - -(defun mastodon-notifications--poll (group json) - "Format for a `poll' NOTE." - (mastodon-notifications--format-note group json 'poll)) - -(defun mastodon-notifications--edit (group json) - "Format for an `edit' NOTE." - (mastodon-notifications--format-note group json 'edit)) - (defun mastodon-notifications--comment-note-text (str) "Add comment face to all text in STR with `shr-text' face only." (with-temp-buffer -- cgit v1.2.3 From f3af53067b7cd7827ccf133e5e729aeed72ce807 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 09:21:08 +0200 Subject: update notifs action alist: match server types --- lisp/mastodon-notifications.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 6e21744..46f2423 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -181,12 +181,14 @@ Can be called in notifications view or in follow-requests view." (defvar mastodon-notifications--action-alist '((reblog . "Boosted") (favourite . "Favourited") - (follow-request . "Requested to follow") + (follow_request . "Requested to follow") (follow . "Followed") (mention . "Mentioned") (status . "Posted") (poll . "Posted a poll") - (edit . "Edited"))) + (update . "Edited")) + "Action strings keyed by notification type. +Types are those of the Mastodon API.") (defun mastodon-notifications--alist-by-value (str field json) "From JSON, return the alist whose FIELD value matches STR. -- cgit v1.2.3 From 64fa8d9066b3a58895e595fc3ca44249edada5df Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 09:26:57 +0200 Subject: working v rough grouped notifs --- lisp/mastodon-notifications.el | 245 +++++++++++++++++++++++------------------ lisp/mastodon-tl.el | 28 +++-- 2 files changed, 153 insertions(+), 120 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 46f2423..a2c0453 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -204,123 +204,150 @@ JSON is a list of alists." for x in ids collect (mastodon-notifications--alist-by-value x 'id json))) -(defun mastodon-notifications--format-note (group json type) - "Format for a NOTE of TYPE." +(defun mastodon-notifications--format-note (group status accounts) + "Format for a GROUP notification. +JSON is the full notifications JSON." ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot' - ;; (if (member type mastodon-notifications-grouped-types) (let-alist group ;; .sample_account_ids .status_id .notifications_count ;; .most_recent_notifiation_id - (let* ((status (mastodon-notifications--alist-by-value - .status_id 'id (alist-get 'statuses json))) - (accounts (mastodon-notifications--group-accounts - .sample_account_ids (alist-get 'accounts json)))) - (insert (symbol-name type) "\n" - "accounts: " (mapconcat 'identity .sample_account_ids ", ") "\n" - (if (not (> .notifications_count (length .sample_account_ids))) - "" - (concat - "and" - (number-to-string - (- .notifications_count - (length .sample_account_ids)))) - "others \n") - ;; "count: " (number-to-string .notifications_count) - (alist-get type mastodon-notifications--action-alist) - "\n toot: " (or .status_id "") "\n" - "\n\n")) - )) - -;; non-grouped notifs: -;; (let* ((id (alist-get 'id note)) -;; (profile-note -;; (when (eq 'follow-request type) -;; (let ((str (mastodon-tl--field -;; 'note -;; (mastodon-tl--field 'account note)))) -;; (if mastodon-notifications--profile-note-in-foll-reqs-max-length -;; (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) -;; str)))) -;; (status (mastodon-tl--field 'status note)) -;; (follower (alist-get 'username (alist-get 'account note))) -;; (toot (alist-get 'status note)) -;; (filtered (mastodon-tl--field 'filtered toot)) -;; (filters (when filtered -;; (mastodon-tl--current-filters filtered)))) -;; (if (and filtered (assoc "hide" filters)) -;; nil -;; (mastodon-tl--insert-status -;; ;; toot -;; (cond ((or (eq type 'follow) -;; (eq type 'follow-request)) -;; ;; Using reblog with an empty id will mark this as something -;; ;; non-boostable/non-favable. -;; (cons '(reblog (id . nil)) note)) -;; ;; reblogs/faves use 'note' to process their own json -;; ;; not the toot's. this ensures following etc. work on such notifs -;; ((or (eq type 'favourite) -;; (eq type 'boost)) -;; note) -;; (t -;; status)) -;; ;; body -;; (let ((body (if-let ((match (assoc "warn" filters))) -;; (mastodon-tl--spoiler toot (cadr match)) -;; (mastodon-tl--clean-tabs-and-nl -;; (if (mastodon-tl--has-spoiler status) -;; (mastodon-tl--spoiler status) -;; (if (eq 'follow-request type) -;; (mastodon-tl--render-text profile-note) -;; (mastodon-tl--content status))))))) -;; (cond ((or (eq type 'follow) -;; (eq type 'follow-request)) -;; (if (eq type 'follow) -;; (propertize "Congratulations, you have a new follower!" -;; 'face 'default) -;; (concat -;; (propertize -;; (format "You have a follow request from... %s" -;; follower) -;; 'face 'default) -;; (when mastodon-notifications--profile-note-in-foll-reqs -;; (concat -;; ":\n" -;; (mastodon-notifications--comment-note-text body)))))) -;; ((or (eq type 'favourite) -;; (eq type 'boost)) -;; (mastodon-notifications--comment-note-text body)) -;; (t body))) -;; ;; author-byline -;; (if (or (eq type 'follow) -;; (eq type 'follow-request) -;; (eq type 'mention)) -;; 'mastodon-tl--byline-author -;; (lambda (_status &rest _args) ; unbreak stuff -;; (mastodon-tl--byline-author note))) -;; ;; action-byline -;; (lambda (_status) -;; (mastodon-notifications--byline-concat -;; (alist-get type mastodon-notifications--action-alist) -;; )) -;; id -;; ;; base toot -;; (when (or (eq type 'favourite) -;; (eq type 'boost)) -;; status)))))) + (let* ((type .type) + (type-sym (intern .type)) + (profile-note + (when (eq type-sym 'follow-request) + (let ((str (mastodon-tl--field + 'note + (car accounts)))) + (if mastodon-notifications--profile-note-in-foll-reqs-max-length + (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) + str)))) + (follower (car .sample_account_ids)) + (filtered (mastodon-tl--field 'filtered status)) ;;toot)) + (filters (when filtered + (mastodon-tl--current-filters filtered)))) + (if (and filtered (assoc "hide" filters)) + nil + (mastodon-tl--insert-status + ;; toot + (if (member type-sym '(follow follow_request)) + ;; Using reblog with an empty id will mark this as something + ;; non-boostable/non-favable. + (cons '(reblog (id . nil)) status) ;;note)) + ;; reblogs/faves use 'note' to process their own json not the + ;; toot's. this ensures following etc. work on such notifs + status) ;; FIXME: fix following on these notifs + ;; body + (let ((body (if-let ((match (assoc "warn" filters))) + (mastodon-tl--spoiler toot (cadr match)) + (mastodon-tl--clean-tabs-and-nl + (if (mastodon-tl--has-spoiler status) + (mastodon-tl--spoiler status) + (if (eq type 'follow-request) + (mastodon-tl--render-text profile-note) + (mastodon-tl--content status))))))) + (cond ((eq type-sym 'follow) + (propertize "Congratulations, you have a new follower!" + 'face 'default)) + ((eq type-sym 'follow-request) + (concat + (propertize + (format "You have a follow request from... %s" + follower) + 'face 'default) + (when mastodon-notifications--profile-note-in-foll-reqs + (concat + ":\n" + (mastodon-notifications--comment-note-text body))))) + ((member type-sym '(favourite boost)) + (mastodon-notifications--comment-note-text body)) + (t body))) + ;; author-byline + (lambda (&rest _args) + (mastodon-notifications--byline-account accounts status)) + ;; action-byline + (lambda (_status) + (mastodon-notifications--byline-concat + (alist-get type-sym mastodon-notifications--action-alist))) + .status_id + ;; base toot + (when (member type-sym '(favourite boost)) + status) + nil nil nil nil + nil group))))) ;; insert status still needs our group data + +;; FIXME: REFACTOR with -tl--byline: +;; we provide account directly, rather than let-alisting toot +;; almost everything is .account.field anyway +;; but toot still needed also, for attachments, etc. +(defun mastodon-notifications--byline-account + (accounts toot &optional avatar domain) + "Propertize author byline ACCOUNT for TOOT, the item responded to. +With arg AVATAR, include the account's avatar image. +When DOMAIN, force inclusion of user's domain in their handle." + (cl-loop + for account in accounts + concat + (let-alist account + (concat + ;; 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 .avatar)) + ;; username: + (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))) + ;; handle: + " (" + (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)) + ")" + (if (< 1 (length accounts)) "\n" ""))))) (defun mastodon-notifications--by-type (groups json) "Filter NOTE for those listed in `mastodon-notifications--types-alist'. Call its function in that list on NOTE." - (cl-loop for g in groups - for type = (alist-get 'type g) - for fun = (cdr (assoc type mastodon-notifications--types-alist)) - for start-pos = (point) - do (when fun - (funcall fun g json) - (when mastodon-tl--display-media-p - ;; images-in-notifs custom is handeld in - ;; `mastodon-tl--media-attachment', not here - (mastodon-media--inline-images start-pos (point)))))) + (setq masto-grouped-notifs json) + (cl-loop + for g in groups + for start-pos = (point) + for accounts = (mastodon-notifications--group-accounts + (alist-get 'sample_account_ids g) + (alist-get 'accounts json)) + for status = (mastodon-notifications--alist-by-value + (alist-get 'status_id g) 'id + (alist-get 'statuses json)) + do (mastodon-notifications--format-note g status accounts) + (when mastodon-tl--display-media-p + ;; images-in-notifs custom is handeld in + ;; `mastodon-tl--media-attachment', not here + (mastodon-media--inline-images start-pos (point))))) (defun mastodon-notifications--timeline (json) "Format JSON in Emacs buffer." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 2e0588f..f611c89 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -711,7 +711,8 @@ LETTER is a string, F for favourited, B for boosted, or K for bookmarked." (image-transforms-p))) (defun mastodon-tl--byline (toot author-byline action-byline - &optional detailed-p domain base-toot) + &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. @@ -723,13 +724,15 @@ 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))) @@ -1519,7 +1522,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) "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 @@ -1539,7 +1542,10 @@ 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))) @@ -1572,7 +1578,7 @@ NO-BYLINE means just insert toot body, used for folding." "\n" (unless no-byline (mastodon-tl--byline toot author-byline action-byline - detailed-p domain base-toot))) + detailed-p domain base-toot group))) 'item-type 'toot 'item-id (or id ; notification's own id (alist-get 'id toot)) ; toot id -- cgit v1.2.3 From c714d1524d2f369228252d265f0a23fe1c166b14 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 10:05:28 +0200 Subject: fix foll_reqs, add group/accounts props to notifs --- lisp/mastodon-notifications.el | 15 +++++++-------- lisp/mastodon-tl.el | 10 ++++++---- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index a2c0453..a67ec0f 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -214,14 +214,13 @@ JSON is the full notifications JSON." (let* ((type .type) (type-sym (intern .type)) (profile-note - (when (eq type-sym 'follow-request) - (let ((str (mastodon-tl--field - 'note - (car accounts)))) + (when (eq type-sym 'follow_request) + (let ((str (mastodon-tl--field 'note (car accounts)))) (if mastodon-notifications--profile-note-in-foll-reqs-max-length (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) str)))) (follower (car .sample_account_ids)) + (follower-name (mastodon-tl--field 'username (car accounts))) (filtered (mastodon-tl--field 'filtered status)) ;;toot)) (filters (when filtered (mastodon-tl--current-filters filtered)))) @@ -242,17 +241,17 @@ JSON is the full notifications JSON." (mastodon-tl--clean-tabs-and-nl (if (mastodon-tl--has-spoiler status) (mastodon-tl--spoiler status) - (if (eq type 'follow-request) + (if (eq type-sym 'follow_request) (mastodon-tl--render-text profile-note) (mastodon-tl--content status))))))) (cond ((eq type-sym 'follow) (propertize "Congratulations, you have a new follower!" 'face 'default)) - ((eq type-sym 'follow-request) + ((eq type-sym 'follow_request) (concat (propertize (format "You have a follow request from... %s" - follower) + follower-name) 'face 'default) (when mastodon-notifications--profile-note-in-foll-reqs (concat @@ -273,7 +272,7 @@ JSON is the full notifications JSON." (when (member type-sym '(favourite boost)) status) nil nil nil nil - nil group))))) ;; insert status still needs our group data + nil group accounts))))) ;; insert status still needs our group data ;; FIXME: REFACTOR with -tl--byline: ;; we provide account directly, rather than let-alisting toot diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index f611c89..1b3b9ec 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1522,7 +1522,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 group) + 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 @@ -1549,7 +1549,7 @@ NO-BYLINE means just insert toot body, used for folding." (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)))) @@ -1590,9 +1590,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) -- cgit v1.2.3 From 95940ee54de27f4a76860c8932ac339db2b664f3 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 11 Oct 2024 11:16:44 +0200 Subject: notifs: type always reblog, not boost --- lisp/mastodon-notifications.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index a67ec0f..73c20f1 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -175,7 +175,7 @@ Can be called in notifications view or in follow-requests view." (buffer-string))) (defvar mastodon-notifications-grouped-types - '(follow boost favourite) + '(follow reblog favourite) "List of notification types for which grouping is implemented.") (defvar mastodon-notifications--action-alist @@ -257,7 +257,7 @@ JSON is the full notifications JSON." (concat ":\n" (mastodon-notifications--comment-note-text body))))) - ((member type-sym '(favourite boost)) + ((member type-sym '(favourite reblog)) (mastodon-notifications--comment-note-text body)) (t body))) ;; author-byline @@ -269,7 +269,7 @@ JSON is the full notifications JSON." (alist-get type-sym mastodon-notifications--action-alist))) .status_id ;; base toot - (when (member type-sym '(favourite boost)) + (when (member type-sym '(favourite reblog)) status) nil nil nil nil nil group accounts))))) ;; insert status still needs our group data -- cgit v1.2.3 From 64a0a0a276b5cadc8b4d98ee28ef1c23b4a799b7 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 12 Oct 2024 17:30:41 +0200 Subject: use byline-username/-handle in notifications--byline-accounts --- lisp/mastodon-notifications.el | 71 ++++++++++++++---------------------------- lisp/mastodon-tl.el | 10 +++--- 2 files changed, 29 insertions(+), 52 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 73c20f1..7632173 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -278,56 +278,33 @@ JSON is the full notifications JSON." ;; we provide account directly, rather than let-alisting toot ;; almost everything is .account.field anyway ;; but toot still needed also, for attachments, etc. -(defun mastodon-notifications--byline-account - (accounts toot &optional avatar domain) +(defun mastodon-notifications--byline-accounts + (accounts toot group &optional avatar domain) "Propertize author byline ACCOUNT for TOOT, the item responded to. With arg AVATAR, include the account's avatar image. When DOMAIN, force inclusion of user's domain in their handle." - (cl-loop - for account in accounts - concat - (let-alist account - (concat - ;; 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 .avatar)) - ;; username: - (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))) - ;; handle: - " (" - (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)) - ")" - (if (< 1 (length accounts)) "\n" ""))))) + (let ((others-count (- (alist-get 'notifications_count group) + (length accounts)))) + (concat + (cl-loop + for account in accounts + concat + (let-alist account + (concat + ;; 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 .avatar)) + ;; username: + (mastodon-tl--byline-username toot account) + ;; handle: + " (" (mastodon-tl--byline-handle toot nil account) ")" + (if (< 1 (length accounts)) "\n" "")))) + (if (< 0 others-count) + (format "and %s others" others-count))))) (defun mastodon-notifications--by-type (groups json) "Filter NOTE for those listed in `mastodon-notifications--types-alist'. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 0f04e58..ca5ec6f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -589,9 +589,9 @@ 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-username (toot) +(defun mastodon-tl--byline-username (toot &optional account) "Format a byline username from account in TOOT." - (let-alist (alist-get 'account toot) + (let-alist (or account (alist-get 'account toot)) (propertize (if (not (string-empty-p .display_name)) .display_name .username) @@ -609,10 +609,10 @@ Do so if type of status at poins is not follow_request/follow." (string-suffix-p "-following*" (buffer-name))) (mastodon-tl--format-byline-help-echo toot))))) -(defun mastodon-tl--byline-handle (toot &optional domain) +(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 (alist-get 'account toot) + (let-alist (or account (alist-get 'account toot)) (propertize (concat "@" .acct (when domain (concat "@" @@ -621,7 +621,7 @@ DOMAIN is optionally added to the handle." 'face 'mastodon-handle-face 'mouse-face 'highlight 'mastodon-tab-stop 'user-handle - 'account .account + 'account account 'shr-url .url 'keymap mastodon-tl--link-keymap 'mastodon-handle (concat "@" .acct) -- cgit v1.2.3 From 56e555945b06662bad0d687c1bc53fabe4beafed Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 12 Oct 2024 18:05:29 +0200 Subject: WIP: hacking for grouped notifs to work w new byline code. --- lisp/mastodon-notifications.el | 13 ++++++++++--- lisp/mastodon-tl.el | 13 +++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 7632173..b758c6f 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -231,6 +231,7 @@ JSON is the full notifications JSON." (if (member type-sym '(follow follow_request)) ;; Using reblog with an empty id will mark this as something ;; non-boostable/non-favable. + ;; status (cons '(reblog (id . nil)) status) ;;note)) ;; reblogs/faves use 'note' to process their own json not the ;; toot's. this ensures following etc. work on such notifs @@ -261,10 +262,16 @@ JSON is the full notifications JSON." (mastodon-notifications--comment-note-text body)) (t body))) ;; author-byline - (lambda (&rest _args) - (mastodon-notifications--byline-account accounts status)) + (cond ((member type-sym '(favourite reblog mention)) + (lambda (&rest _args) + (mastodon-notifications--byline-accounts accounts status group))) + ((eq type-sym 'follow_request) + (lambda (&rest _args) + (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) + (t #'mastodon-tl--byline-author)) + ;; #'mastodon-tl--byline-author ;; action-byline - (lambda (_status) + (lambda (&rest _args) (mastodon-notifications--byline-concat (alist-get type-sym mastodon-notifications--action-alist))) .status_id diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index ca5ec6f..cf7f9aa 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -589,6 +589,11 @@ 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) "Format a byline username from account in TOOT." (let-alist (or account (alist-get 'account toot)) @@ -627,6 +632,11 @@ DOMAIN is optionally added to the handle." '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. @@ -649,8 +659,7 @@ If BASE is nil, we are a boosted byline, so show less info." (alist-get 'account data)))) (if (not base) (mastodon-tl--byline-handle data domain) - (concat (mastodon-tl--byline-username data) - " (" (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. -- cgit v1.2.3 From 03f308c695452e1d831d50e542f4760e2c29bbb5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 12:48:14 +0200 Subject: rough overhaul of notifs byline code for grouped notifications --- lisp/mastodon-notifications.el | 310 +++++++++++++++++++++++++---------------- lisp/mastodon-tl.el | 17 ++- 2 files changed, 199 insertions(+), 128 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index b758c6f..aa38302 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -31,6 +31,7 @@ ;;; Code: (eval-when-compile (require 'subr-x)) +(require 'cl-lib) (autoload 'mastodon-http--api "mastodon-http") (autoload 'mastodon-http--get-params-async-json "mastodon-http") @@ -55,7 +56,12 @@ (autoload 'mastodon-tl--current-filters "mastodon-views") (autoload 'mastodon-tl--render-text "mastodon-tl") (autoload 'mastodon-notifications-get "mastodon") - +(autoload 'mastodon-tl--byline-uname-+-handle "mastodon-tl") +(autoload 'mastodon-tl--byline-username "mastodon-tl") +(autoload 'mastodon-tl--byline-handle "mastodon-tl") +(autoload 'mastodon-http--get-json "mastodon-http") +(autoload 'mastodon-media--get-avatar-rendering "mastodon-media") +(autoload 'mastodon-tl--image-trans-check "mastodon-tl") (defgroup mastodon-tl nil "Nofications in mastodon.el." @@ -81,6 +87,8 @@ make them unweildy." (defvar mastodon-tl--buffer-spec) (defvar mastodon-tl--display-media-p) (defvar mastodon-mode-map) +(defvar mastodon-tl--fold-toots-at-length) +(defvar mastodon-tl--show-avatars) (defvar mastodon-notifications--types-alist '(("follow" . mastodon-notifications--follow) @@ -95,13 +103,13 @@ make them unweildy." (defvar mastodon-notifications--response-alist '(("Followed" . "you") - ("Favourited" . "your status from") - ("Boosted" . "your status from") + ("Favourited" . "your post") + ("Boosted" . "your post") ("Mentioned" . "you") ("Posted a poll" . "that has now ended") ("Requested to follow" . "you") ("Posted" . "a post") - ("Edited" . "a post from")) + ("Edited" . "their post")) "Alist of subjects for notification types.") (defvar mastodon-notifications--map @@ -115,8 +123,9 @@ make them unweildy." (defun mastodon-notifications--byline-concat (message) "Add byline for TOOT with MESSAGE." - (concat " " (propertize message 'face 'highlight) - " " (cdr (assoc message mastodon-notifications--response-alist)))) + (concat "\n " (propertize message 'face 'highlight) + " " (cdr (assoc message mastodon-notifications--response-alist)) + "\n")) (defun mastodon-notifications--follow-request-process (&optional reject) "Process the follow request at point. @@ -206,141 +215,204 @@ JSON is a list of alists." (defun mastodon-notifications--format-note (group status accounts) "Format for a GROUP notification. -JSON is the full notifications JSON." - ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot' - (let-alist group - ;; .sample_account_ids .status_id .notifications_count - ;; .most_recent_notifiation_id - (let* ((type .type) - (type-sym (intern .type)) - (profile-note - (when (eq type-sym 'follow_request) - (let ((str (mastodon-tl--field 'note (car accounts)))) - (if mastodon-notifications--profile-note-in-foll-reqs-max-length - (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) - str)))) - (follower (car .sample_account_ids)) - (follower-name (mastodon-tl--field 'username (car accounts))) - (filtered (mastodon-tl--field 'filtered status)) ;;toot)) - (filters (when filtered - (mastodon-tl--current-filters filtered)))) - (if (and filtered (assoc "hide" filters)) - nil - (mastodon-tl--insert-status - ;; toot - (if (member type-sym '(follow follow_request)) - ;; Using reblog with an empty id will mark this as something - ;; non-boostable/non-favable. - ;; status - (cons '(reblog (id . nil)) status) ;;note)) - ;; reblogs/faves use 'note' to process their own json not the - ;; toot's. this ensures following etc. work on such notifs - status) ;; FIXME: fix following on these notifs - ;; body - (let ((body (if-let ((match (assoc "warn" filters))) - (mastodon-tl--spoiler toot (cadr match)) - (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler status) - (mastodon-tl--spoiler status) - (if (eq type-sym 'follow_request) - (mastodon-tl--render-text profile-note) - (mastodon-tl--content status))))))) - (cond ((eq type-sym 'follow) - (propertize "Congratulations, you have a new follower!" - 'face 'default)) - ((eq type-sym 'follow_request) - (concat - (propertize - (format "You have a follow request from... %s" - follower-name) - 'face 'default) - (when mastodon-notifications--profile-note-in-foll-reqs - (concat - ":\n" - (mastodon-notifications--comment-note-text body))))) - ((member type-sym '(favourite reblog)) - (mastodon-notifications--comment-note-text body)) - (t body))) - ;; author-byline - (cond ((member type-sym '(favourite reblog mention)) - (lambda (&rest _args) - (mastodon-notifications--byline-accounts accounts status group))) - ((eq type-sym 'follow_request) - (lambda (&rest _args) - (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) - (t #'mastodon-tl--byline-author)) - ;; #'mastodon-tl--byline-author - ;; action-byline - (lambda (&rest _args) - (mastodon-notifications--byline-concat - (alist-get type-sym mastodon-notifications--action-alist))) - .status_id - ;; base toot - (when (member type-sym '(favourite reblog)) - status) - nil nil nil nil - nil group accounts))))) ;; insert status still needs our group data - -;; FIXME: REFACTOR with -tl--byline: +STATUS is the status's JSON. +ACCOUNTS is data of the accounts that have reacted to the notification." + (let ((folded nil)) + ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot' + (let-alist group + ;; .sample_account_ids .status_id .notifications_count + ;; .most_recent_notifiation_id + (let* (;(type .type) + (type-sym (intern .type)) + (profile-note + (when (eq type-sym 'follow_request) + (let ((str (mastodon-tl--field 'note (car accounts)))) + (if mastodon-notifications--profile-note-in-foll-reqs-max-length + (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) + str)))) + ;; (follower (car .sample_account_ids)) + (follower-name (mastodon-tl--field 'username (car accounts))) + (filtered (mastodon-tl--field 'filtered status)) ;;toot)) + (filters (when filtered + (mastodon-tl--current-filters filtered)))) + (unless (and filtered (assoc "hide" filters)) + (if (member type-sym '(follow follow_request)) + ;; FIXME: handle follow requests, polls + (insert "TODO: follow-req\n") + (mastodon-notifications--insert-note + ;; toot + (if (member type-sym '(follow follow_request)) + ;; Using reblog with an empty id will mark this as something + ;; non-boostable/non-favable. + ;; status + status + ;; (cons '(reblog (id . nil)) status) ;;note)) + ;; reblogs/faves use 'note' to process their own json not the + ;; toot's. this ensures following etc. work on such notifs + status) ;; FIXME: fix following on these notifs + ;; body + (let ((body (if-let ((match (assoc "warn" filters))) + (mastodon-tl--spoiler status (cadr match)) + (mastodon-tl--clean-tabs-and-nl + (if (mastodon-tl--has-spoiler status) + (mastodon-tl--spoiler status) + (if (eq type-sym 'follow_request) + (mastodon-tl--render-text profile-note) + (mastodon-tl--content status))))))) + (cond ((eq type-sym 'follow) + (propertize "Congratulations, you have a new follower!" + 'face 'default)) + ((eq type-sym 'follow_request) + (concat + (propertize + (format "You have a follow request from... %s" + follower-name) + 'face 'default) + (when mastodon-notifications--profile-note-in-foll-reqs + (concat + ":\n" + (mastodon-notifications--comment-note-text body))))) + ((member type-sym '(favourite reblog)) + (mastodon-notifications--comment-note-text body)) + (t body))) + ;; author-byline + #'mastodon-tl--byline-author + ;; action-byline + (unless (member type-sym '(mention)) + (mastodon-notifications--byline-concat + (alist-get type-sym mastodon-notifications--action-alist))) + ;; action authors + (cond ((member type-sym '(mention)) + "") ;; mentions are normal statuses + ((member type-sym '(favourite reblog update)) + (mastodon-notifications--byline-accounts accounts status group)) + ((eq type-sym 'follow_request) + (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) + .status_id + ;; base toot + (when (member type-sym '(favourite reblog)) + status) + folded group accounts))))))) ;; insert status still needs our group data + +;; FIXME: this is copied from `mastodon-tl--insert-status' +;; we could probably cull a lot of the code so its just for notifs +(defun mastodon-notifications--insert-note + (toot body author-byline action-byline action-authors + &optional id base-toot unfolded 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 +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 `item-id' property if provided. If the +status is a favourite or boost notification, BASE-TOOT is the +JSON of the toot responded to. +UNFOLDED is a boolean meaning whether to unfold or fold item if foldable. +NO-BYLINE means just insert toot body, used for folding." + (let* ((type (alist-get 'type (or group toot))) + (toot-foldable + (and mastodon-tl--fold-toots-at-length + (length> body mastodon-tl--fold-toots-at-length)))) + (insert + (propertize ;; body + byline: + (concat + (concat action-authors + action-byline) + (propertize ;; body only: + body + 'toot-body t) ;; includes newlines etc. for folding + ;; byline: + "\n" + (mastodon-tl--byline toot author-byline nil nil + base-toot group)) + 'item-type 'toot + 'item-id (or id ; notification's own id + (alist-get 'id toot)) ; toot id + 'base-item-id (mastodon-tl--item-id + ;; if status is a notif, get id from base-toot + ;; (-tl--item-id toot) will not work here: + (or base-toot + toot)) ; else normal toot with reblog check + 'item-json toot + 'base-toot base-toot + 'cursor-face 'mastodon-cursor-highlight-face + 'toot-foldable toot-foldable + 'toot-folded (and toot-foldable (not unfolded)) + 'notification-type type + 'notification-group group + 'notification-accounts accounts) + "\n"))) + +;; FIXME: REFACTOR with -tl--byline?: ;; we provide account directly, rather than let-alisting toot ;; almost everything is .account.field anyway ;; but toot still needed also, for attachments, etc. (defun mastodon-notifications--byline-accounts - (accounts toot group &optional avatar domain) - "Propertize author byline ACCOUNT for TOOT, the item responded to. + (accounts toot group &optional avatar compact) + "Propertize author byline ACCOUNTS for TOOT, the item responded to. With arg AVATAR, include the account's avatar image. When DOMAIN, force inclusion of user's domain in their handle." - (let ((others-count (- (alist-get 'notifications_count group) - (length accounts)))) + (let ((total (alist-get 'notifications_count group)) + (accts 2)) (concat (cl-loop for account in accounts + repeat accts concat (let-alist account (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 .avatar)) - ;; username: - (mastodon-tl--byline-username toot account) - ;; handle: - " (" (mastodon-tl--byline-handle toot nil account) ")" - (if (< 1 (length accounts)) "\n" "")))) - (if (< 0 others-count) - (format "and %s others" others-count))))) - -(defun mastodon-notifications--by-type (groups json) - "Filter NOTE for those listed in `mastodon-notifications--types-alist'. -Call its function in that list on NOTE." - (setq masto-grouped-notifs json) - (cl-loop - for g in groups - for start-pos = (point) - for accounts = (mastodon-notifications--group-accounts - (alist-get 'sample_account_ids g) - (alist-get 'accounts json)) - for status = (mastodon-notifications--alist-by-value - (alist-get 'status_id g) 'id - (alist-get 'statuses json)) - do (mastodon-notifications--format-note g status accounts) - (when mastodon-tl--display-media-p - ;; images-in-notifs custom is handeld in - ;; `mastodon-tl--media-attachment', not here - (mastodon-media--inline-images start-pos (point))))) + (let ((uname (mastodon-tl--byline-username toot account)) + (handle (concat + "(" + (mastodon-tl--byline-handle toot nil account) + ")"))) + (if compact + ;; FIXME: this doesn't work to make a link from a username: + (propertize handle 'display uname) + (concat uname handle))) + "\n"))) ;; FIXME: only if not last handle + (if (< accts total) + (let ((diff (- total accts))) + ;; FIXME: help echo all remaining accounts? + (format "\nand %s other%s" diff (if (= 1 diff) "" "s"))))))) + +(defun mastodon-notifications--render (json) + "Display grouped notifications in JSON." + ;; (setq masto-grouped-notifs json) + (let ((groups (alist-get 'notification_groups json))) + (cl-loop + for g in groups + for start-pos = (point) + for accounts = (mastodon-notifications--group-accounts + (alist-get 'sample_account_ids g) + (alist-get 'accounts json)) + for status = (mastodon-notifications--alist-by-value + (alist-get 'status_id g) 'id + (alist-get 'statuses json)) + do (mastodon-notifications--format-note g status accounts) + (when mastodon-tl--display-media-p + ;; images-in-notifs custom is handeld in + ;; `mastodon-tl--media-attachment', not here + (mastodon-media--inline-images start-pos (point)))))) (defun mastodon-notifications--timeline (json) "Format JSON in Emacs buffer." (if (seq-empty-p json) (user-error "Looks like you have no (more) notifications for now") - (let ((groups (alist-get 'notification_groups json))) - ;; (mapc (lambda (x) - (mastodon-notifications--by-type groups json) - ;; grouped) - (goto-char (point-min))))) + (mastodon-notifications--render json) + (goto-char (point-min)))) (defun mastodon-notifications--get-mentions () "Display mention notifications in buffer." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 3ebfa4e..efc16ac 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -598,11 +598,10 @@ 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) +;; 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)) @@ -634,12 +633,12 @@ DOMAIN is optionally added to the handle." (url-generic-parse-url .url))))) 'face 'mastodon-handle-face 'mouse-face 'highlight - 'mastodon-tab-stop 'user-handle + 'mastodon-tab-stop 'user-handle 'account account - 'shr-url .url - 'keymap mastodon-tl--link-keymap + 'shr-url .url + 'keymap mastodon-tl--link-keymap 'mastodon-handle (concat "@" .acct) - 'help-echo (concat "Browse user profile of @" .acct)))) + 'help-echo (concat "Browse user profile of @" .acct)))) (defun mastodon-tl--byline-uname-+-handle (data &optional domain account) "" -- cgit v1.2.3 From 7800c16bf9cf28cc60fc8c8bd2dbe858fe6f290f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 12:57:28 +0200 Subject: notifs: action symbol for action byline str --- lisp/mastodon-notifications.el | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index aa38302..c969c8e 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -62,6 +62,7 @@ (autoload 'mastodon-http--get-json "mastodon-http") (autoload 'mastodon-media--get-avatar-rendering "mastodon-media") (autoload 'mastodon-tl--image-trans-check "mastodon-tl") +(autoload 'mastodon-tl--symbol "mastodon-tl") (defgroup mastodon-tl nil "Nofications in mastodon.el." @@ -123,7 +124,16 @@ make them unweildy." (defun mastodon-notifications--byline-concat (message) "Add byline for TOOT with MESSAGE." - (concat "\n " (propertize message 'face 'highlight) + (concat "\n " + (mastodon-tl--symbol + (cond ((string= message "Favourited") + 'favourite) + ((string= message "Boosted") + 'boost) + ((string= message "Edited") + 'edited))) + " " + (propertize message 'face 'highlight) " " (cdr (assoc message mastodon-notifications--response-alist)) "\n")) -- cgit v1.2.3 From f114f3c19066e5bd7211389e6730b23a17c35e09 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 13:39:30 +0200 Subject: notifs: fix foll_reqs --- lisp/mastodon-notifications.el | 154 ++++++++++++++++++++++------------------- lisp/mastodon-tl.el | 19 ++--- 2 files changed, 92 insertions(+), 81 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index c969c8e..599b4aa 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -232,77 +232,80 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (let-alist group ;; .sample_account_ids .status_id .notifications_count ;; .most_recent_notifiation_id - (let* (;(type .type) - (type-sym (intern .type)) + (let* ((type-sym (intern .type)) (profile-note - (when (eq type-sym 'follow_request) + (when (member type-sym '(follow follow_request)) (let ((str (mastodon-tl--field 'note (car accounts)))) (if mastodon-notifications--profile-note-in-foll-reqs-max-length (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) str)))) - ;; (follower (car .sample_account_ids)) - (follower-name (mastodon-tl--field 'username (car accounts))) - (filtered (mastodon-tl--field 'filtered status)) ;;toot)) + (follower (when (member type-sym + '(reblog favourite follow follow_request)) + (car accounts))) + (follower-name (mastodon-tl--field 'username follower)) + (filtered (mastodon-tl--field 'filtered status)) (filters (when filtered (mastodon-tl--current-filters filtered)))) (unless (and filtered (assoc "hide" filters)) - (if (member type-sym '(follow follow_request)) - ;; FIXME: handle follow requests, polls - (insert "TODO: follow-req\n") - (mastodon-notifications--insert-note - ;; toot - (if (member type-sym '(follow follow_request)) - ;; Using reblog with an empty id will mark this as something - ;; non-boostable/non-favable. - ;; status - status - ;; (cons '(reblog (id . nil)) status) ;;note)) - ;; reblogs/faves use 'note' to process their own json not the - ;; toot's. this ensures following etc. work on such notifs - status) ;; FIXME: fix following on these notifs - ;; body - (let ((body (if-let ((match (assoc "warn" filters))) - (mastodon-tl--spoiler status (cadr match)) - (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler status) - (mastodon-tl--spoiler status) - (if (eq type-sym 'follow_request) - (mastodon-tl--render-text profile-note) - (mastodon-tl--content status))))))) - (cond ((eq type-sym 'follow) - (propertize "Congratulations, you have a new follower!" - 'face 'default)) - ((eq type-sym 'follow_request) - (concat - (propertize - (format "You have a follow request from... %s" - follower-name) - 'face 'default) - (when mastodon-notifications--profile-note-in-foll-reqs - (concat - ":\n" - (mastodon-notifications--comment-note-text body))))) - ((member type-sym '(favourite reblog)) - (mastodon-notifications--comment-note-text body)) - (t body))) - ;; author-byline - #'mastodon-tl--byline-author - ;; action-byline - (unless (member type-sym '(mention)) - (mastodon-notifications--byline-concat - (alist-get type-sym mastodon-notifications--action-alist))) - ;; action authors - (cond ((member type-sym '(mention)) - "") ;; mentions are normal statuses - ((member type-sym '(favourite reblog update)) - (mastodon-notifications--byline-accounts accounts status group)) + (mastodon-notifications--insert-note + ;; toot + ;; FIXME: fix following on grouped notifs + ;; FIXME: block boost/fave on boost/fave notifs? + (if (member type-sym + ;; reblogs/faves use 'note' to process their own + ;; json not the toot's. this ensures following etc. + ;; work on such notifs + '(reblog favourite follow follow_request)) + ;; FIXME: breaks item stats! + follower + ;; Using reblog with an empty id will mark this as something + ;; non-boostable/non-favable. + ;; (cons '(reblog (id . nil)) status) ;;note)) + status) + ;; body + (let ((body (if-let ((match (assoc "warn" filters))) + (mastodon-tl--spoiler status (cadr match)) + (mastodon-tl--clean-tabs-and-nl + (if (mastodon-tl--has-spoiler status) + (mastodon-tl--spoiler status) + (if (eq type-sym 'follow_request) + (mastodon-tl--render-text profile-note) + (mastodon-tl--content status))))))) + (cond ((eq type-sym 'follow) + (propertize "Congratulations, you have a new follower!" + 'face 'default)) ((eq type-sym 'follow_request) - (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) - .status_id - ;; base toot - (when (member type-sym '(favourite reblog)) - status) - folded group accounts))))))) ;; insert status still needs our group data + (concat + (propertize + (format "You have a follow request from... %s" + follower-name) + 'face 'default) + (when mastodon-notifications--profile-note-in-foll-reqs + (concat + ":\n" + (mastodon-notifications--comment-note-text body))))) + ((member type-sym '(favourite reblog)) + (mastodon-notifications--comment-note-text body)) + (t body))) + ;; author-byline + #'mastodon-tl--byline-author + ;; action-byline + (unless (member type-sym '(follow follow_request mention)) + (mastodon-notifications--byline-concat + (alist-get type-sym mastodon-notifications--action-alist))) + ;; action authors + (cond + ((member type-sym '(follow_request mention)) + "") ;; mentions are normal statuses + ((member type-sym '(favourite reblog update)) + (mastodon-notifications--byline-accounts accounts status group)) + ((eq type-sym 'follow_request) + (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) + .status_id + ;; base toot + (when (member type-sym '(favourite reblog)) + status) + folded group accounts)))))) ;; FIXME: this is copied from `mastodon-tl--insert-status' ;; we could probably cull a lot of the code so its just for notifs @@ -314,16 +317,19 @@ 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'. +ACTION-BYLINE is a string, obtained by calling +`mastodon-notifications--byline-concat'. +ACTION-AUTHORS is a string of those who have responded to the +current item, obtained by calling +`mastodon-notifications--byline-accounts' ID is that of the status if it is a notification, which is attached as a `item-id' property if provided. If the status is a favourite or boost notification, BASE-TOOT is the JSON of the toot responded to. -UNFOLDED is a boolean meaning whether to unfold or fold item if foldable. -NO-BYLINE means just insert toot body, used for folding." +UNFOLDED is a boolean meaning whether to unfold or fold item if +foldable. +GROUP is the notification group data. +ACCOUNTS is the notification accounts data." (let* ((type (alist-get 'type (or group toot))) (toot-foldable (and mastodon-tl--fold-toots-at-length @@ -339,7 +345,9 @@ NO-BYLINE means just insert toot body, used for folding." ;; byline: "\n" (mastodon-tl--byline toot author-byline nil nil - base-toot group)) + base-toot group + (if (member type '("follow" "follow_request")) + toot))) ;; account data! 'item-type 'toot 'item-id (or id ; notification's own id (alist-get 'id toot)) ; toot id @@ -365,8 +373,10 @@ NO-BYLINE means just insert toot body, used for folding." (defun mastodon-notifications--byline-accounts (accounts toot group &optional avatar compact) "Propertize author byline ACCOUNTS for TOOT, the item responded to. -With arg AVATAR, include the account's avatar image. -When DOMAIN, force inclusion of user's domain in their handle." +GROUP is the group notification data. +When AVATAR, include the account's avatar image. +When DOMAIN, force inclusion of user's domain in their handle. +When COMPACT, just display username, not also handle." (let ((total (alist-get 'notifications_count group)) (accts 2)) (concat @@ -385,7 +395,7 @@ When DOMAIN, force inclusion of user's domain in their handle." (mastodon-media--get-avatar-rendering .avatar)) (let ((uname (mastodon-tl--byline-username toot account)) (handle (concat - "(" + " (" (mastodon-tl--byline-handle toot nil account) ")"))) (if compact diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index efc16ac..f6460e1 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -645,7 +645,7 @@ DOMAIN is optionally added to the handle." (concat (mastodon-tl--byline-username data account) " (" (mastodon-tl--byline-handle data domain account) ")")) -(defun mastodon-tl--byline-author (toot &optional avatar domain base) +(defun mastodon-tl--byline-author (toot &optional avatar domain base account) "Propertize author of TOOT. If TOOT contains a reblog, return author of reblogged item. With arg AVATAR, include the account's avatar image. @@ -666,8 +666,8 @@ If BASE is nil, we are a boosted byline, so show less info." (alist-get 'avatar (alist-get 'account data)))) (if (not base) - (mastodon-tl--byline-handle data domain) - (mastodon-tl--byline-uname-+-handle data domain))))) + (mastodon-tl--byline-handle data domain account) + (mastodon-tl--byline-uname-+-handle data domain account))))) (defun mastodon-tl--format-byline-help-echo (toot) "Format a help-echo for byline of TOOT. @@ -760,7 +760,7 @@ LETTER is a string, F for favourited, B for boosted, or K for bookmarked." (image-transforms-p))) (defun mastodon-tl--byline (toot author-byline &optional detailed-p - domain base-toot group) + domain base-toot group account) "Generate byline for TOOT. AUTHOR-BYLINE is a function for adding the author portion of the byline that takes one variable. @@ -789,7 +789,8 @@ BASE-TOOT is JSON for the base toot, if any." (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)) + (account (or 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)))) @@ -828,7 +829,7 @@ BASE-TOOT is JSON for the base toot, if any." (propertize (concat " " (mastodon-tl--symbol 'private)) 'help-echo visibility))) ;; (base) author byline: - (funcall author-byline toot nil domain :base) + (funcall author-byline toot nil domain :base account) " " ;; timestamp: (let ((ts (format-time-string @@ -852,10 +853,10 @@ BASE-TOOT is JSON for the base toot, if any." 'face 'mastodon-display-name-face 'follow-link t 'mouse-face 'highlight - 'mastodon-tab-stop 'shr-url - 'shr-url app-url + 'mastodon-tab-stop 'shr-url + 'shr-url app-url 'help-echo app-url - 'keymap mastodon-tl--shr-map-replacement))))) + 'keymap mastodon-tl--shr-map-replacement))))) ;; edited: (when edited-time (concat -- cgit v1.2.3 From d573d80f023813ce4c429dc73da6714b0a29af8c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 13:53:06 +0200 Subject: notifs: string-trim action authors --- lisp/mastodon-notifications.el | 47 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 599b4aa..fc82edd 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -380,29 +380,30 @@ When COMPACT, just display username, not also handle." (let ((total (alist-get 'notifications_count group)) (accts 2)) (concat - (cl-loop - for account in accounts - repeat accts - concat - (let-alist account - (concat - ;; 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 .avatar)) - (let ((uname (mastodon-tl--byline-username toot account)) - (handle (concat - " (" - (mastodon-tl--byline-handle toot nil account) - ")"))) - (if compact - ;; FIXME: this doesn't work to make a link from a username: - (propertize handle 'display uname) - (concat uname handle))) - "\n"))) ;; FIXME: only if not last handle + (string-trim ;; remove trailing newline + (cl-loop + for account in accounts + repeat accts + concat + (let-alist account + (concat + ;; 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 .avatar)) + (let ((uname (mastodon-tl--byline-username toot account)) + (handle (concat + " (" + (mastodon-tl--byline-handle toot nil account) + ")"))) + (if compact + ;; FIXME: this doesn't work to make a link from a username: + (propertize handle 'display uname) + (concat uname handle))) + "\n")))) (if (< accts total) (let ((diff (- total accts))) ;; FIXME: help echo all remaining accounts? -- cgit v1.2.3 From f53d252a27fc451bd41c8fb6fe2049695b9bedc0 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 13:53:26 +0200 Subject: notifs: revert add fave/boost to foll_req condition --- lisp/mastodon-notifications.el | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index fc82edd..bbc77a8 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -240,7 +240,7 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) str)))) (follower (when (member type-sym - '(reblog favourite follow follow_request)) + '(follow follow_request)) (car accounts))) (follower-name (mastodon-tl--field 'username follower)) (filtered (mastodon-tl--field 'filtered status)) @@ -249,18 +249,14 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (unless (and filtered (assoc "hide" filters)) (mastodon-notifications--insert-note ;; toot - ;; FIXME: fix following on grouped notifs + ;; FIXME: fix following etc. on action authors ;; FIXME: block boost/fave on boost/fave notifs? (if (member type-sym ;; reblogs/faves use 'note' to process their own ;; json not the toot's. this ensures following etc. ;; work on such notifs - '(reblog favourite follow follow_request)) - ;; FIXME: breaks item stats! + '(follow follow_request)) follower - ;; Using reblog with an empty id will mark this as something - ;; non-boostable/non-favable. - ;; (cons '(reblog (id . nil)) status) ;;note)) status) ;; body (let ((body (if-let ((match (assoc "warn" filters))) -- cgit v1.2.3 From 0ed127907f34dd8dbc1aad9d131e0fda1ce4d35d Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Wed, 16 Oct 2024 18:33:59 +0200 Subject: bylines/notifs: use new uname/handle combo in reaction notifs --- lisp/mastodon-notifications.el | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index bbc77a8..8517a84 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -390,15 +390,12 @@ When COMPACT, just display username, not also handle." mastodon-tl--display-media-p (mastodon-tl--image-trans-check)) (mastodon-media--get-avatar-rendering .avatar)) - (let ((uname (mastodon-tl--byline-username toot account)) - (handle (concat - " (" - (mastodon-tl--byline-handle toot nil account) - ")"))) - (if compact - ;; FIXME: this doesn't work to make a link from a username: - (propertize handle 'display uname) - (concat uname handle))) + (let ((uname + (if (not (string-empty-p (alist-get 'display_name account))) + (alist-get 'display_name account) + (alist-get 'username account)))) + (mastodon-tl--byline-handle toot nil account + uname 'mastodon-display-name-face)) "\n")))) (if (< accts total) (let ((diff (- total accts))) -- cgit v1.2.3 From 3e7f1eccd386c3c041a482b9250ed0ef5f768354 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 13:09:19 +0200 Subject: notifs: top byline: action symbol, action author, action str --- lisp/mastodon-notifications.el | 48 +++++++++++++++++++++++------------------- lisp/mastodon-tl.el | 2 ++ 2 files changed, 28 insertions(+), 22 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 8517a84..eef68a2 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -124,16 +124,8 @@ make them unweildy." (defun mastodon-notifications--byline-concat (message) "Add byline for TOOT with MESSAGE." - (concat "\n " - (mastodon-tl--symbol - (cond ((string= message "Favourited") - 'favourite) - ((string= message "Boosted") - 'boost) - ((string= message "Edited") - 'edited))) - " " - (propertize message 'face 'highlight) + (concat " " + (propertize message 'face 'mastodon-boosted-face) " " (cdr (assoc message mastodon-notifications--response-alist)) "\n")) @@ -281,22 +273,31 @@ ACCOUNTS is data of the accounts that have reacted to the notification." ":\n" (mastodon-notifications--comment-note-text body))))) ((member type-sym '(favourite reblog)) - (mastodon-notifications--comment-note-text body)) + (propertize + (mastodon-notifications--comment-note-text body) + ;; indent faves/boosts (maybe remove): + 'line-prefix " " + 'wrap-prefix " ")) (t body))) ;; author-byline #'mastodon-tl--byline-author ;; action-byline (unless (member type-sym '(follow follow_request mention)) - (mastodon-notifications--byline-concat - (alist-get type-sym mastodon-notifications--action-alist))) + (downcase + (mastodon-notifications--byline-concat + (alist-get type-sym mastodon-notifications--action-alist)))) ;; action authors (cond ((member type-sym '(follow_request mention)) "") ;; mentions are normal statuses ((member type-sym '(favourite reblog update)) - (mastodon-notifications--byline-accounts accounts status group)) + (mastodon-notifications--byline-accounts + accounts status group)) ((eq type-sym 'follow_request) (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) + ;; action symbol: + (when (member type-sym '(favourite reblog update)) + (mastodon-tl--symbol type-sym)) .status_id ;; base toot (when (member type-sym '(favourite reblog)) @@ -306,7 +307,7 @@ ACCOUNTS is data of the accounts that have reacted to the notification." ;; FIXME: this is copied from `mastodon-tl--insert-status' ;; we could probably cull a lot of the code so its just for notifs (defun mastodon-notifications--insert-note - (toot body author-byline action-byline action-authors + (toot body author-byline action-byline action-authors action-symbol &optional id base-toot unfolded group accounts) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. @@ -331,15 +332,17 @@ ACCOUNTS is the notification accounts data." (and mastodon-tl--fold-toots-at-length (length> body mastodon-tl--fold-toots-at-length)))) (insert - (propertize ;; body + byline: + (propertize ;; top byline, body + byline: (concat - (concat action-authors - action-byline) - (propertize ;; body only: + (propertize ;; top byline + (concat action-symbol " " action-authors + action-byline) + 'byline-top t) + (propertize ;; body only body 'toot-body t) ;; includes newlines etc. for folding - ;; byline: "\n" + ;; actual byline: (mastodon-tl--byline toot author-byline nil nil base-toot group (if (member type '("follow" "follow_request")) @@ -396,11 +399,12 @@ When COMPACT, just display username, not also handle." (alist-get 'username account)))) (mastodon-tl--byline-handle toot nil account uname 'mastodon-display-name-face)) - "\n")))) + ", "))) + nil ", ") (if (< accts total) (let ((diff (- total accts))) ;; FIXME: help echo all remaining accounts? - (format "\nand %s other%s" diff (if (= 1 diff) "" "s"))))))) + (format " and %s other%s" diff (if (= 1 diff) "" "s"))))))) (defun mastodon-notifications--render (json) "Display grouped notifications in JSON." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 74c79c3..c5ada75 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -155,6 +155,7 @@ nil." (defcustom mastodon-tl--symbols '((reply . ("💬" . "R")) (boost . ("🔁" . "B")) + (reblog . ("🔁" . "B")) ;; server compat (favourite . ("⭐" . "F")) (bookmark . ("🔖" . "K")) (media . ("📹" . "[media]")) @@ -163,6 +164,7 @@ nil." (private . ("🔒" . "[followers]")) (direct . ("✉" . "[direct]")) (edited . ("✍" . "[edited]")) + (update . ("✍" . "[edited]")) ;; server compat (replied . ("⬇" . "↓")) (reply-bar . ("┃" . "|"))) "A set of symbols (and fallback strings) to be used in timeline. -- cgit v1.2.3 From 8eab2d38ebcde6946b16aeba7c6c0c480141ecdf Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 13:17:25 +0200 Subject: notifs: comment faved/boosted toot body line-prefix (breaks cursor highlight) --- lisp/mastodon-notifications.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index eef68a2..a61492a 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -275,9 +275,13 @@ ACCOUNTS is data of the accounts that have reacted to the notification." ((member type-sym '(favourite reblog)) (propertize (mastodon-notifications--comment-note-text body) - ;; indent faves/boosts (maybe remove): - 'line-prefix " " - 'wrap-prefix " ")) + ;; indent faves/boosts (maybe remove, as it makes + ;; cursor highlight ugly) + ;; but it's nice to be able to differentiate top + ;; byline a little from body of item acted on + ;; 'line-prefix "" + ;; 'wrap-prefix "" + )) (t body))) ;; author-byline #'mastodon-tl--byline-author -- cgit v1.2.3 From 5c1a8d5a3b0a6a772f712e6ad21f0889a4081325 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 14:09:04 +0200 Subject: grouped notifs: fix foll req process: use notif-type prop not item-json --- lisp/mastodon-notifications.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index a61492a..262ed57 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -139,7 +139,9 @@ follow-requests view." (let* ((item-json (mastodon-tl--property 'item-json)) (f-reqs-view-p (string= "follow_requests" (plist-get mastodon-tl--buffer-spec 'endpoint))) - (f-req-p (or (string= "follow_request" (alist-get 'type item-json)) ;notifs + (f-req-p (or (string= "follow_request" + (mastodon-tl--property 'notification-type + :no-move)) f-reqs-view-p))) (if (not f-req-p) (user-error "No follow request at point?") -- cgit v1.2.3 From 94a7083c282b0d65984ef6dffa891e3ea397386e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 14:17:28 +0200 Subject: flycheck --- lisp/mastodon-notifications.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 262ed57..f8f093b 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -324,7 +324,8 @@ ACTION-BYLINE is a string, obtained by calling `mastodon-notifications--byline-concat'. ACTION-AUTHORS is a string of those who have responded to the current item, obtained by calling -`mastodon-notifications--byline-accounts' +`mastodon-notifications--byline-accounts'. +ACTION-SYMBOL is a symbol indicating a favourite, boost, or edit. ID is that of the status if it is a notification, which is attached as a `item-id' property if provided. If the status is a favourite or boost notification, BASE-TOOT is the @@ -376,12 +377,11 @@ ACCOUNTS is the notification accounts data." ;; almost everything is .account.field anyway ;; but toot still needed also, for attachments, etc. (defun mastodon-notifications--byline-accounts - (accounts toot group &optional avatar compact) + (accounts toot group &optional avatar) "Propertize author byline ACCOUNTS for TOOT, the item responded to. GROUP is the group notification data. When AVATAR, include the account's avatar image. -When DOMAIN, force inclusion of user's domain in their handle. -When COMPACT, just display username, not also handle." +When DOMAIN, force inclusion of user's domain in their handle." (let ((total (alist-get 'notifications_count group)) (accts 2)) (concat -- cgit v1.2.3 From 3c3ef2e98ff81e94446c6e749759f0422f2aa140 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 15:06:13 +0200 Subject: notifs: improve insert-note text props. fixes pagination (hack) --- lisp/mastodon-notifications.el | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index f8f093b..14f2be5 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -354,19 +354,23 @@ ACCOUNTS is the notification accounts data." base-toot group (if (member type '("follow" "follow_request")) toot))) ;; account data! - 'item-type 'toot - 'item-id (or id ; notification's own id - (alist-get 'id toot)) ; toot id - 'base-item-id (mastodon-tl--item-id - ;; if status is a notif, get id from base-toot - ;; (-tl--item-id toot) will not work here: - (or base-toot - toot)) ; else normal toot with reblog check - 'item-json toot - 'base-toot base-toot - 'cursor-face 'mastodon-cursor-highlight-face + 'item-type 'notification + 'item-id (or + ;; grouped notifications pagination max_id: + ;; NB: their min id used for our max id param + (alist-get 'page_min_id group) + (alist-get 'id toot)) ; toot id + 'base-item-id (mastodon-tl--item-id + ;; if status is a notif, get id from base-toot + ;; (-tl--item-id toot) will not work here: + (or base-toot + toot)) ; else normal toot with reblog check + 'item-json toot + 'base-toot base-toot + 'cursor-face 'mastodon-cursor-highlight-face 'toot-foldable toot-foldable - 'toot-folded (and toot-foldable (not unfolded)) + 'toot-folded (and toot-foldable (not unfolded)) + ;; grouped notifs data: 'notification-type type 'notification-group group 'notification-accounts accounts) -- cgit v1.2.3 From 532f608fe52f1dd326df4995dcef69fb5c431c1e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 15:15:02 +0200 Subject: notifs: item-type = toot (for nav, item actions) --- lisp/mastodon-notifications.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 14f2be5..c2d1962 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -354,7 +354,7 @@ ACCOUNTS is the notification accounts data." base-toot group (if (member type '("follow" "follow_request")) toot))) ;; account data! - 'item-type 'notification + 'item-type 'toot ;; for nav, actions, etc. 'item-id (or ;; grouped notifications pagination max_id: ;; NB: their min id used for our max id param -- cgit v1.2.3 From c784cb81ab693d0979425b1cd223df106f9802fc Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 19:28:08 +0200 Subject: notifs: fix pagination using grouped min/max ids --- lisp/mastodon-notifications.el | 12 ++++++------ lisp/mastodon-tl.el | 20 ++++++++++++++++---- 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index c2d1962..debc760 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -355,11 +355,8 @@ ACCOUNTS is the notification accounts data." (if (member type '("follow" "follow_request")) toot))) ;; account data! 'item-type 'toot ;; for nav, actions, etc. - 'item-id (or - ;; grouped notifications pagination max_id: - ;; NB: their min id used for our max id param - (alist-get 'page_min_id group) - (alist-get 'id toot)) ; toot id + 'item-id (or (alist-get 'page_max_id group) ;; newest notif + (alist-get 'id toot)) ; toot id 'base-item-id (mastodon-tl--item-id ;; if status is a notif, get id from base-toot ;; (-tl--item-id toot) will not work here: @@ -373,7 +370,10 @@ ACCOUNTS is the notification accounts data." ;; grouped notifs data: 'notification-type type 'notification-group group - 'notification-accounts accounts) + 'notification-accounts accounts + ;; for pagination: + 'notifications-min-id (alist-get 'page_min_id group) + 'notifications-max-id (alist-get 'page_max_id group)) "\n"))) ;; FIXME: REFACTOR with -tl--byline?: diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 6005a54..99663ac 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -2216,16 +2216,28 @@ BACKWARD means move backward (up) the timeline." (get-text-property (point) prop))))) (defun mastodon-tl--newest-id () - "Return item-id from the top of the buffer." + "Return item-id from the top of the buffer. +If we are in a notifications view, return `notifications-max-id'." (save-excursion (goto-char (point-min)) - (mastodon-tl--property 'item-id))) + (mastodon-tl--property + (if (eq (mastodon-tl--get-buffer-type) + (member (mastodon-tl--get-buffer-type) + '(mentions notifications))) + 'notifications-max-id + 'item-id)))) (defun mastodon-tl--oldest-id () - "Return item-id from the bottom of the buffer." + "Return item-id from the bottom of the buffer. +If we are in a notifications view, return `notifications-min-id'." (save-excursion (goto-char (point-max)) - (mastodon-tl--property 'item-id nil :backward))) + (mastodon-tl--property + (if (member (mastodon-tl--get-buffer-type) + '(mentions notifications)) + 'notifications-min-id + 'item-id) + nil :backward))) (defun mastodon-tl--as-string (numeric) "Convert NUMERIC to string." -- cgit v1.2.3 From 34979a5e64c8d07d028e7a8a59d4f3f156fb869c Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 20:09:52 +0200 Subject: notifs: make action authors work for all notif types --- lisp/mastodon-notifications.el | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index debc760..59b90fd 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -293,19 +293,15 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (mastodon-notifications--byline-concat (alist-get type-sym mastodon-notifications--action-alist)))) ;; action authors - (cond - ((member type-sym '(follow_request mention)) - "") ;; mentions are normal statuses - ((member type-sym '(favourite reblog update)) - (mastodon-notifications--byline-accounts - accounts status group)) - ((eq type-sym 'follow_request) - (mastodon-tl--byline-uname-+-handle status nil (car accounts)))) + (cond ((member type-sym '(follow_request mention)) + "") ;; mentions are normal statuses + (t (mastodon-notifications--byline-accounts + accounts status group))) ;; action symbol: (when (member type-sym '(favourite reblog update)) (mastodon-tl--symbol type-sym)) .status_id - ;; base toot + ;; base toot (no need for update/poll/?) (when (member type-sym '(favourite reblog)) status) folded group accounts)))))) -- cgit v1.2.3 From 4653bdadfcd9a5487e8d1b01c8186a0458578f9f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 20:11:16 +0200 Subject: notifs: mastodon-notifications--types --- lisp/mastodon-notifications.el | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 59b90fd..9ec3252 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -91,16 +91,10 @@ make them unweildy." (defvar mastodon-tl--fold-toots-at-length) (defvar mastodon-tl--show-avatars) -(defvar mastodon-notifications--types-alist - '(("follow" . mastodon-notifications--follow) - ("favourite" . mastodon-notifications--favourite) - ("reblog" . mastodon-notifications--reblog) - ("mention" . mastodon-notifications--mention) - ("poll" . mastodon-notifications--poll) - ("follow_request" . mastodon-notifications--follow-request) - ("status" . mastodon-notifications--status) - ("update" . mastodon-notifications--edit)) - "Alist of notification types and their corresponding function.") +(defvar mastodon-notifications--types + '("favourite" "reblog" "mention" "poll" + "follow_request" "follow" "status" "update") + "A list of notification types according to their name on the server.") (defvar mastodon-notifications--response-alist '(("Followed" . "you") @@ -293,7 +287,7 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (mastodon-notifications--byline-concat (alist-get type-sym mastodon-notifications--action-alist)))) ;; action authors - (cond ((member type-sym '(follow_request mention)) + (cond ((member type-sym '(follow follow_request mention)) "") ;; mentions are normal statuses (t (mastodon-notifications--byline-accounts accounts status group))) @@ -467,8 +461,7 @@ Status notifications are created when you call (defun mastodon-notifications--filter-types-list (type) "Return a list of notification types with TYPE removed." - (let ((types (mapcar #'car mastodon-notifications--types-alist))) - (remove type types))) + (remove type mastodon-notifications--types)) (defun mastodon-notifications--clear-all () "Clear all notifications." -- cgit v1.2.3 From 61e85a022c573193afa97d11798ed0553f2364d4 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 20:45:06 +0200 Subject: add some more symbols, for notifs actions --- lisp/mastodon-notifications.el | 2 +- lisp/mastodon-tl.el | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 9ec3252..339857c 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -292,7 +292,7 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (t (mastodon-notifications--byline-accounts accounts status group))) ;; action symbol: - (when (member type-sym '(favourite reblog update)) + (unless (eq type-sym 'mention) (mastodon-tl--symbol type-sym)) .status_id ;; base toot (no need for update/poll/?) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 28fbb64..f4051a3 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -153,20 +153,24 @@ nil." :type 'boolean) (defcustom mastodon-tl--symbols - '((reply . ("💬" . "R")) - (boost . ("🔁" . "B")) - (reblog . ("🔁" . "B")) ;; server compat - (favourite . ("⭐" . "F")) - (bookmark . ("🔖" . "K")) - (media . ("📹" . "[media]")) - (verified . ("" . "V")) - (locked . ("🔒" . "[locked]")) - (private . ("🔒" . "[followers]")) - (direct . ("✉" . "[direct]")) - (edited . ("✍" . "[edited]")) - (update . ("✍" . "[edited]")) ;; server compat - (replied . ("⬇" . "↓")) - (reply-bar . ("┃" . "|"))) + '((reply . ("💬" . "R")) + (boost . ("🔁" . "B")) + (reblog . ("🔁" . "B")) ;; server compat + (favourite . ("⭐" . "F")) + (bookmark . ("🔖" . "K")) + (media . ("📹" . "[media]")) + (verified . ("" . "V")) + (locked . ("🔒" . "[locked]")) + (private . ("🔒" . "[followers]")) + (direct . ("✉" . "[direct]")) + (edited . ("✍" . "[edited]")) + (update . ("✍" . "[edited]")) ;; server compat + (status . ("✍" . "[posted]")) + (replied . ("⬇" . "↓")) + (reply-bar . ("┃" . "|")) + (poll . ("📊" . "")) + (follow . ("👤" . "+")) + (follow_request . ("👤" . "+"))) "A set of symbols (and fallback strings) to be used in timeline. If a symbol does not look right (tofu), it means your font settings do not support it." -- cgit v1.2.3 From e8787743b5ba661927b00bef37fe4cdf08429a97 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 20:47:24 +0200 Subject: notifs: clean up format-note. adjust some notif type conditionals --- lisp/mastodon-notifications.el | 65 ++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 40 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 339857c..7d85200 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -218,17 +218,14 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (let ((folded nil)) ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot' (let-alist group - ;; .sample_account_ids .status_id .notifications_count - ;; .most_recent_notifiation_id (let* ((type-sym (intern .type)) (profile-note - (when (member type-sym '(follow follow_request)) + (when (member type-sym '(follow_request)) (let ((str (mastodon-tl--field 'note (car accounts)))) (if mastodon-notifications--profile-note-in-foll-reqs-max-length (string-limit str mastodon-notifications--profile-note-in-foll-reqs-max-length) str)))) - (follower (when (member type-sym - '(follow follow_request)) + (follower (when (member type-sym '(follow follow_request)) (car accounts))) (follower-name (mastodon-tl--field 'username follower)) (filtered (mastodon-tl--field 'filtered status)) @@ -238,47 +235,35 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (mastodon-notifications--insert-note ;; toot ;; FIXME: fix following etc. on action authors - ;; FIXME: block boost/fave on boost/fave notifs? - (if (member type-sym - ;; reblogs/faves use 'note' to process their own - ;; json not the toot's. this ensures following etc. - ;; work on such notifs - '(follow follow_request)) + (if (member type-sym '(follow follow_request)) follower status) ;; body (let ((body (if-let ((match (assoc "warn" filters))) (mastodon-tl--spoiler status (cadr match)) (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler status) - (mastodon-tl--spoiler status) - (if (eq type-sym 'follow_request) - (mastodon-tl--render-text profile-note) - (mastodon-tl--content status))))))) - (cond ((eq type-sym 'follow) - (propertize "Congratulations, you have a new follower!" - 'face 'default)) - ((eq type-sym 'follow_request) - (concat - (propertize - (format "You have a follow request from... %s" - follower-name) - 'face 'default) - (when mastodon-notifications--profile-note-in-foll-reqs - (concat - ":\n" - (mastodon-notifications--comment-note-text body))))) - ((member type-sym '(favourite reblog)) - (propertize - (mastodon-notifications--comment-note-text body) - ;; indent faves/boosts (maybe remove, as it makes - ;; cursor highlight ugly) - ;; but it's nice to be able to differentiate top - ;; byline a little from body of item acted on - ;; 'line-prefix "" - ;; 'wrap-prefix "" - )) - (t body))) + (cond ((mastodon-tl--has-spoiler status) + (mastodon-tl--spoiler status)) + ((eq type-sym 'follow_request) + (mastodon-tl--render-text profile-note)) + (t (mastodon-tl--content status))))))) + (cond + ((eq type-sym 'follow) + (propertize "Congratulations, you have a new follower!" + 'face 'default)) + ((eq type-sym 'follow_request) + (concat + (propertize (format "You have a follow request from %s" + follower-name) + 'face 'default) + (when mastodon-notifications--profile-note-in-foll-reqs + (concat + ":\n" + (mastodon-notifications--comment-note-text body))))) + ((member type-sym '(favourite reblog)) + (propertize + (mastodon-notifications--comment-note-text body))) + (t body))) ;; author-byline #'mastodon-tl--byline-author ;; action-byline -- cgit v1.2.3 From be46982de5a59bfa0da674953079c72d71153395 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 21:06:41 +0200 Subject: notifs : remove stale id arg --- lisp/mastodon-notifications.el | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 7d85200..6b63c3e 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -279,7 +279,6 @@ ACCOUNTS is data of the accounts that have reacted to the notification." ;; action symbol: (unless (eq type-sym 'mention) (mastodon-tl--symbol type-sym)) - .status_id ;; base toot (no need for update/poll/?) (when (member type-sym '(favourite reblog)) status) @@ -289,7 +288,7 @@ ACCOUNTS is data of the accounts that have reacted to the notification." ;; we could probably cull a lot of the code so its just for notifs (defun mastodon-notifications--insert-note (toot body author-byline action-byline action-authors action-symbol - &optional id base-toot unfolded group accounts) + &optional base-toot unfolded 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 -- cgit v1.2.3 From c9370483b3beacc164438cd158f7e8b2965fbc42 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 21:06:49 +0200 Subject: notifs: byline authors: help-echo remaining byline authors --- lisp/mastodon-notifications.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 6b63c3e..b5a0ff4 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -387,8 +387,12 @@ When DOMAIN, force inclusion of user's domain in their handle." nil ", ") (if (< accts total) (let ((diff (- total accts))) - ;; FIXME: help echo all remaining accounts? - (format " and %s other%s" diff (if (= 1 diff) "" "s"))))))) + (propertize ;; help-echo remaining notifs authors: + (format " and %s other%s" diff (if (= 1 diff) "" "s")) + 'help-echo (mapconcat (lambda (a) + (alist-get 'username a)) + (cddr accounts) ;; not first two + " "))))))) (defun mastodon-notifications--render (json) "Display grouped notifications in JSON." -- cgit v1.2.3 From 6da29b195192d65e1567e593ad761107e1dbfe1f Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Thu, 17 Oct 2024 21:09:46 +0200 Subject: notifs: remove comment --- lisp/mastodon-notifications.el | 2 -- 1 file changed, 2 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index b5a0ff4..b54b012 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -284,8 +284,6 @@ ACCOUNTS is data of the accounts that have reacted to the notification." status) folded group accounts)))))) -;; FIXME: this is copied from `mastodon-tl--insert-status' -;; we could probably cull a lot of the code so its just for notifs (defun mastodon-notifications--insert-note (toot body author-byline action-byline action-authors action-symbol &optional base-toot unfolded group accounts) -- cgit v1.2.3 From 390c1d0c2dec6f247830cd507d8d1e8ca4db3479 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Fri, 18 Oct 2024 09:13:07 +0200 Subject: bump version, copyright --- lisp/mastodon-discover.el | 2 +- lisp/mastodon-http.el | 2 +- lisp/mastodon-inspect.el | 2 +- lisp/mastodon-media.el | 2 +- lisp/mastodon-notifications.el | 2 +- lisp/mastodon-profile.el | 2 +- lisp/mastodon-tl.el | 2 +- lisp/mastodon-toot.el | 2 +- lisp/mastodon-views.el | 2 +- lisp/mastodon.el | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index c34d85f..9278432 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -1,7 +1,7 @@ ;;; mastodon-discover.el --- Use Mastodon.el with discover.el -*- lexical-binding: t -*- ;; Copyright (C) 2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index c0402f0..42b599d 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -1,7 +1,7 @@ ;;; mastodon-http.el --- HTTP request/response functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index 43c8ba4..adc6d64 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -1,7 +1,7 @@ ;;; mastodon-inspect.el --- Client for Mastodon -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index 2ec498e..fff5d23 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -1,7 +1,7 @@ ;;; mastodon-media.el --- Functions for inlining Mastodon media -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index b54b012..c2257b2 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -1,7 +1,7 @@ ;;; mastodon-notifications.el --- Notification functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 900e9c0..8db1d69 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -1,7 +1,7 @@ ;;; mastodon-profile.el --- Functions for inspecting Mastodon profiles -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 77eb320..92bf0a6 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -1,7 +1,7 @@ ;;; mastodon-tl.el --- Timeline functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 386b720..b5322b3 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1,7 +1,7 @@ ;;; mastodon-toot.el --- Minor mode for sending Mastodon toots -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index ac62b1f..3112c20 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -1,6 +1,6 @@ ;;; mastodon-views.el --- Minor views functions for mastodon.el -*- lexical-binding: t -*- -;; Copyright (C) 2020-2022 Marty Hiatt +;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Marty Hiatt ;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 80b6d8c..e754b28 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -6,7 +6,7 @@ ;; Author: Johnson Denen ;; Marty Hiatt ;; Maintainer: Marty Hiatt -;; Version: 1.0.27 +;; Version: 1.1.0 ;; Package-Requires: ((emacs "27.1") (request "0.3.0") ;; (persist "0.4") (tp "0.1")) ;; Homepage: https://codeberg.org/martianh/mastodon.el -- cgit v1.2.3 From deaedf0d8d8f516909afa1d2bafda654896f958e Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 19 Oct 2024 12:23:39 +0200 Subject: notifs: remove stray space at beginning of mentions --- lisp/mastodon-notifications.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index c2257b2..f163863 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -314,8 +314,10 @@ ACCOUNTS is the notification accounts data." (propertize ;; top byline, body + byline: (concat (propertize ;; top byline - (concat action-symbol " " action-authors - action-byline) + (if (equal type "mention") + "" + (concat action-symbol " " action-authors + action-byline)) 'byline-top t) (propertize ;; body only body -- cgit v1.2.3 From cfe4703513dc574a58baf1fd7883082563bdbcc5 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sat, 19 Oct 2024 21:55:39 +0200 Subject: notifs: remove stale notifs code from tl--insert-status --- lisp/mastodon-notifications.el | 1 - lisp/mastodon-tl.el | 24 +++++++++--------------- 2 files changed, 9 insertions(+), 16 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index f163863..cb36616 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -46,7 +46,6 @@ (autoload 'mastodon-tl--find-property-range "mastodon-tl") (autoload 'mastodon-tl--has-spoiler "mastodon-tl") (autoload 'mastodon-tl--init "mastodon-tl") -(autoload 'mastodon-tl--insert-status "mastodon-tl") (autoload 'mastodon-tl--property "mastodon-tl") (autoload 'mastodon-tl--reload-timeline-or-profile "mastodon-tl") (autoload 'mastodon-tl--spoiler "mastodon-tl") diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 95632cd..5d0fafc 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -798,7 +798,9 @@ 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. -BASE-TOOT is JSON for the base toot, if any." +BASE-TOOT is JSON for the base toot, if any. +GROUP is the notification group if any. +ACCOUNT is the notification account if any." (let* ((created-time (if group (mastodon-tl--field 'latest_page_notification_at group) @@ -814,9 +816,7 @@ BASE-TOOT is JSON for the base toot, if any." (boosted (eq t (mastodon-tl--field 'reblogged toot))) (bookmarked (eq t (mastodon-tl--field 'bookmarked toot))) (visibility (mastodon-tl--field 'visibility toot)) - (type (if group - (alist-get 'type group) - (alist-get 'type 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 @@ -1648,7 +1648,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 group accounts) + 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. AUTHOR-BYLINE is an optional function for adding the author @@ -1668,14 +1668,11 @@ 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 - (if group - (alist-get 'status_id group) - (alist-get 'in_reply_to_id toot))) + (let* ((reply-to-id (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 (or group toot))) + ;; (type (alist-get 'type toot)) (toot-foldable (and mastodon-tl--fold-toots-at-length (length> body mastodon-tl--fold-toots-at-length)))) @@ -1706,7 +1703,7 @@ NO-BYLINE means just insert toot body, used for folding." (if no-byline "" (mastodon-tl--byline toot author-byline detailed-p - domain base-toot group))) + domain base-toot))) 'item-type 'toot 'item-id (or id ; notification's own id (alist-get 'id toot)) ; toot id @@ -1719,10 +1716,7 @@ NO-BYLINE means just insert toot body, used for folding." 'base-toot base-toot 'cursor-face 'mastodon-cursor-highlight-face 'toot-foldable toot-foldable - 'toot-folded (and toot-foldable (not unfolded)) - 'notification-type type - 'notification-group group - 'notification-accounts accounts) + 'toot-folded (and toot-foldable (not unfolded))) (if no-byline "" "\n")))) (defun mastodon-tl--is-reply (toot) -- cgit v1.2.3 From bfb2b4b2276622830b7a5ed1066c64ef6d5693e8 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 20 Oct 2024 10:11:40 +0200 Subject: refactor display-or-uname --- lisp/mastodon-notifications.el | 5 +---- lisp/mastodon-search.el | 4 +--- lisp/mastodon-tl.el | 34 ++++++++++++++++------------------ 3 files changed, 18 insertions(+), 25 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index cb36616..0177ba7 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -376,10 +376,7 @@ When DOMAIN, force inclusion of user's domain in their handle." mastodon-tl--display-media-p (mastodon-tl--image-trans-check)) (mastodon-media--get-avatar-rendering .avatar)) - (let ((uname - (if (not (string-empty-p (alist-get 'display_name account))) - (alist-get 'display_name account) - (alist-get 'username account)))) + (let ((uname (mastodon-tl--display-or-uname account))) (mastodon-tl--byline-handle toot nil account uname 'mastodon-display-name-face)) ", "))) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 262f75c..cead17e 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -331,9 +331,7 @@ If NOTE is non-nil, include user's profile note. This is also (defun mastodon-search--get-user-info (account) "Get user handle, display name, account URL and profile note from ACCOUNT." - (list (if (not (string-empty-p (alist-get 'display_name account))) - (alist-get 'display_name account) - (alist-get 'username account)) + (list (mastodon-tl--display-or-uname account) (alist-get 'acct account) (alist-get 'url account) (alist-get 'note account))) diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 5d0fafc..437a5e3 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -661,6 +661,12 @@ ACCOUNT is optionally acccount data to use." (concat (mastodon-tl--byline-username data account) " (" (mastodon-tl--byline-handle data domain account) ")")) +(defun mastodon-tl--display-or-uname (account) + "Return display name or username from ACCOUNT data." + (if (not (string-empty-p (alist-get 'display_name account))) + (alist-get 'display_name account) + (alist-get 'username account))) + (defun mastodon-tl--byline-author (toot &optional avatar domain base account) "Propertize author of TOOT. If TOOT contains a reblog, return author of reblogged item. @@ -673,9 +679,7 @@ ACCOUNT is optionally acccount data to use." (mastodon-tl--toot-or-base toot) toot)) (account (or account (alist-get 'account data))) - (uname (if (not (string-empty-p (alist-get 'display_name account))) - (alist-get 'display_name account) - (alist-get 'username account)))) + (uname (mastodon-tl--display-or-uname account))) (concat ;; avatar insertion moved up to `mastodon-tl--byline' by default to ;; be outside 'byline propt. @@ -684,8 +688,7 @@ ACCOUNT is optionally acccount data to use." mastodon-tl--display-media-p (mastodon-tl--image-trans-check)) (mastodon-media--get-avatar-rendering - (alist-get 'avatar - (alist-get 'account data)))) + (map-nested-elt data '(account avatar)))) (if (not base) ;; boost symbol: (concat (mastodon-tl--symbol 'boost) @@ -873,10 +876,9 @@ ACCOUNT is the notification account if any." 'help-echo ts)) ;; detailed: (when detailed-p - (let* ((app (alist-get 'application toot)) - (app-name (alist-get 'name app)) - (app-url (alist-get 'website app))) - (when app + (let* ((app-name (map-nested-elt toot '(application name))) + (app-url (map-nested-elt toot '(application website)))) + (when app-name (concat (propertize " via " 'face 'default) (propertize app-name @@ -973,9 +975,8 @@ links in the text. If TOOT is nil no parsing occurs." (get-text-property (car region) 'shr-url)) (when (proper-list-p toot) ;; not on profile fields cons cells ;; render card author maybe: - (let* ((card (alist-get 'card toot)) - (card-url (alist-get 'url card)) - (authors (alist-get 'authors card)) + (let* ((card-url (map-nested-elt toot '(card url))) + (authors (map-nested-elt toot '(card authors))) (url (buffer-substring (car region) (cdr region))) (url-no-query (car (split-string url "?")))) (when (and (string= url-no-query card-url) @@ -1121,7 +1122,7 @@ the toot)." (url-generic-parse-url instance-url))) (parsed (url-generic-parse-url url)) (path (url-filename parsed)) - (split (string-split path "/"))) + (split (split-string path "/"))) (when (and (string= instance-host (url-host parsed)) (string-prefix-p "/tag" path)) ;; "/tag/" or "/tags/" (nth 2 split)))) @@ -2395,8 +2396,7 @@ If UNMUTE, unmute it." (defun mastodon-tl--map-account-id-from-toot (statuses) "Return a list of the account IDs of the author of each toot in STATUSES." (mapcar (lambda (status) - (alist-get 'id - (alist-get 'account status))) + (map-nested-elt status '(account id))) statuses)) (defun mastodon-tl--user-in-thread-p (id) @@ -2628,9 +2628,7 @@ display of the user's boosts in your timeline." ;; muting/blocking, select from handles in current status (mastodon-profile--item-json)))))) (user-id (alist-get 'id account)) - (name (if (string-empty-p (alist-get 'display_name account)) - (alist-get 'username account) - (alist-get 'display_name account))) + (name (mastodon-tl--display-or-uname account)) (args (cond (notify `(("notify" . ,notify))) (langs langs) (reblogs `(("reblogs" . ,reblogs))) -- cgit v1.2.3 From c7305179fcca04ebdf090c93dabd2c82bad5b6ff Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 20 Oct 2024 10:36:49 +0200 Subject: remove stale fixme --- lisp/mastodon-notifications.el | 1 - 1 file changed, 1 deletion(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index cb36616..a7f358b 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -233,7 +233,6 @@ ACCOUNTS is data of the accounts that have reacted to the notification." (unless (and filtered (assoc "hide" filters)) (mastodon-notifications--insert-note ;; toot - ;; FIXME: fix following etc. on action authors (if (member type-sym '(follow follow_request)) follower status) -- cgit v1.2.3 From ef6762986de6f4c85405dbc01ae19854cd2687fd Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 20 Oct 2024 13:39:06 +0200 Subject: change email address --- README.org | 2 +- lisp/mastodon-async.el | 2 +- lisp/mastodon-auth.el | 2 +- lisp/mastodon-client.el | 2 +- lisp/mastodon-discover.el | 4 ++-- lisp/mastodon-http.el | 4 ++-- lisp/mastodon-inspect.el | 4 ++-- lisp/mastodon-iso.el | 2 +- lisp/mastodon-media.el | 4 ++-- lisp/mastodon-notifications.el | 4 ++-- lisp/mastodon-profile.el | 4 ++-- lisp/mastodon-search.el | 4 ++-- lisp/mastodon-tl.el | 4 ++-- lisp/mastodon-toot.el | 4 ++-- lisp/mastodon-transient.el | 2 +- lisp/mastodon-views.el | 4 ++-- lisp/mastodon.el | 4 ++-- mastodon.texi | 2 +- 18 files changed, 29 insertions(+), 29 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/README.org b/README.org index cf6aed5..1898366 100644 --- a/README.org +++ b/README.org @@ -487,7 +487,7 @@ If you prefer emailing patches to the process described below, feel free to send If you'd like to support continued development of =mastodon.el=, I accept donations via paypal: [[https://paypal.me/martianh][paypal.me/martianh]]. If you would prefer a different -payment method, please write to me at and I can +payment method, please write to me at and I can provide IBAN or other bank account details. I don't have a tech worker's income, so even a small tip would help out. diff --git a/lisp/mastodon-async.el b/lisp/mastodon-async.el index 317be93..b059407 100644 --- a/lisp/mastodon-async.el +++ b/lisp/mastodon-async.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2017 Alex J. Griffith ;; Author: Alex J. Griffith -;; Maintainer: Marty Hiatt +;; Maintainer: Marty Hiatt ;; Package-Requires: ((emacs "27.1")) ;; Homepage: https://codeberg.org/martianh/mastodon.el diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 3796b7e..01639fb 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2021 Abhiseck Paira ;; Author: Johnson Denen -;; Maintainer: Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-client.el b/lisp/mastodon-client.el index 6e55829..c0db3d6 100644 --- a/lisp/mastodon-client.el +++ b/lisp/mastodon-client.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2021 Abhiseck Paira ;; Author: Johnson Denen -;; Maintainer: Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-discover.el b/lisp/mastodon-discover.el index 9278432..993cc27 100644 --- a/lisp/mastodon-discover.el +++ b/lisp/mastodon-discover.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 5035cb4..1093de1 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-inspect.el b/lisp/mastodon-inspect.el index adc6d64..4981943 100644 --- a/lisp/mastodon-inspect.el +++ b/lisp/mastodon-inspect.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-iso.el b/lisp/mastodon-iso.el index 8ea5635..6199cbe 100644 --- a/lisp/mastodon-iso.el +++ b/lisp/mastodon-iso.el @@ -1,7 +1,7 @@ ;;; mastodon-iso.el --- ISO language code lists for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2022 Marty Hiatt -;; Author: Marty Hiatt +;; Author: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-media.el b/lisp/mastodon-media.el index ccd258c..8601410 100644 --- a/lisp/mastodon-media.el +++ b/lisp/mastodon-media.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 8d2c928..b16b5a6 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index c6a0276..40f834c 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index cead17e..25db7d8 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -1,8 +1,8 @@ ;;; mastodon-search.el --- Search functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Marty Hiatt -;; Author: Marty Hiatt -;; Maintainer: Marty Hiatt +;; Author: Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 437a5e3..1a4df7f 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 95fccc3..fc5825a 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -3,8 +3,8 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Copyright (C) 2020-2024 Marty Hiatt ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon-transient.el b/lisp/mastodon-transient.el index fe70eac..526dfa4 100644 --- a/lisp/mastodon-transient.el +++ b/lisp/mastodon-transient.el @@ -2,7 +2,7 @@ ;; Copyright (C) 2024 martian hiatus -;; Author: martian hiatus +;; Author: martian hiatus ;; Keywords: convenience ;; This program is free software; you can redistribute it and/or modify diff --git a/lisp/mastodon-views.el b/lisp/mastodon-views.el index 3112c20..8d356fb 100644 --- a/lisp/mastodon-views.el +++ b/lisp/mastodon-views.el @@ -1,8 +1,8 @@ ;;; mastodon-views.el --- Minor views functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2020-2024 Marty Hiatt -;; Author: Marty Hiatt -;; Maintainer: Marty Hiatt +;; Author: Marty Hiatt +;; Maintainer: Marty Hiatt ;; Homepage: https://codeberg.org/martianh/mastodon.el ;; This file is not part of GNU Emacs. diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 37da99c..cb5731a 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -4,8 +4,8 @@ ;; Copyright (C) 2020-2022 Marty Hiatt ;; Copyright (C) 2021 Abhiseck Paira ;; Author: Johnson Denen -;; Marty Hiatt -;; Maintainer: Marty Hiatt +;; Marty Hiatt +;; Maintainer: Marty Hiatt ;; Version: 1.1.0 ;; Package-Requires: ((emacs "28.1") (request "0.3.0") ;; (persist "0.4") (tp "0.1")) diff --git a/mastodon.texi b/mastodon.texi index dafa92d..d1c9268 100644 --- a/mastodon.texi +++ b/mastodon.texi @@ -818,7 +818,7 @@ There's no need for a blank line after the first docstring line (one is added au If you'd like to support continued development of @samp{mastodon.el}, I accept donations via paypal: @uref{https://paypal.me/martianh, paypal.me/martianh}. If you would prefer a different -payment method, please write to me at and I can +payment method, please write to me at and I can provide IBAN or other bank account details. I don't have a tech worker's income, so even a small tip would help out. -- cgit v1.2.3