[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/mastodon 0e75fc74ee 01/50: group-notifs custom (for server
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/mastodon 0e75fc74ee 01/50: group-notifs custom (for servers without). #608. WIP. |
Date: |
Sat, 2 Nov 2024 13:00:50 -0400 (EDT) |
branch: elpa/mastodon
commit 0e75fc74eebd142601d725cb814d7fe18b87c25e
Author: marty hiatt <martianhiatus@disroot.org>
Commit: marty hiatt <martianhiatus@disroot.org>
group-notifs custom (for servers without). #608. WIP.
---
lisp/mastodon-notifications.el | 137 +++++++++++++++++++++++++++++++++++------
lisp/mastodon.el | 5 +-
2 files changed, 123 insertions(+), 19 deletions(-)
diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index f4615fbcb6..4bf797d6c6 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -85,6 +85,10 @@ make them unweildy."
"Whether to display attached images in notifications."
:type '(boolean))
+(defcustom mastodon-notifications--group-notifications t
+ "Whether to use grouped notifications."
+ :type '(boolean))
+
(defvar mastodon-tl--buffer-spec)
(defvar mastodon-tl--display-media-p)
(defvar mastodon-mode-map)
@@ -231,7 +235,101 @@ JSON is a list of alists."
"\nfor account: "
.target_account)))
-(defun mastodon-notifications--format-note (group status accounts)
+(defun mastodon-notifications--format-note (note)
+ "Format for a NOTE of TYPE."
+ ;; FIXME: apply/refactor filtering as per/with `mastodon-tl--toot'
+ (let* ((id (alist-get 'id note))
+ (type (intern (alist-get 'type 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 'reblog)
+ "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 'update)
+ "Edited"))))
+ id
+ ;; base toot
+ (when (or (eq type 'favourite)
+ (eq type 'boost))
+ status)))))
+
+(defun mastodon-notifications--format-group-note (group status accounts)
"Format for a GROUP notification.
STATUS is the status's JSON.
ACCOUNTS is data of the accounts that have reacted to the notification."
@@ -420,30 +518,33 @@ When DOMAIN, force inclusion of user's domain in their
handle."
(cddr accounts) ;; not first two
", ")))))))
-(defun mastodon-notifications--render (json)
+(defun mastodon-notifications--render (json no-group)
"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))))))
+ (if no-group
+ (cl-loop for x in json
+ do (mastodon-notifications--format-note x))
+ (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-group-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")
- (mastodon-notifications--render json)
+ (mastodon-notifications--render json (not
mastodon-notifications--group-notifications))
(goto-char (point-min))))
(defun mastodon-notifications--get-mentions ()
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index deee0c12db..86810b7699 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -372,7 +372,10 @@ MAX-ID is a request parameter for pagination."
type
(when max-id
`(("max_id" . ,(mastodon-tl--buffer-property 'max-id))))
- nil nil nil "v2")
+ nil nil nil
+ (if (not mastodon-notifications--group-notifications)
+ "v1"
+ "v2"))
(with-current-buffer (get-buffer-create buffer)
(use-local-map mastodon-notifications--map))))
- [nongnu] elpa/mastodon c09935b100 37/50: tl: remove stale args to insert status, inc. action-byline arg, (continued)
- [nongnu] elpa/mastodon c09935b100 37/50: tl: remove stale args to insert status, inc. action-byline arg, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon b47390993b 46/50: Merge branch 'poll-var' into develop, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 94ea642a1a 38/50: notifs: improve byline docstrings for new byline logic, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 071c33eed2 32/50: Merge branch 'develop' into non-group-notifs, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon babb3a1adf 28/50: fold-toot - respect CW state, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 1606b34c5d 45/50: Merge branch 'read-less' into develop, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 7623478121 48/50: bump, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 7af46336f2 42/50: add read less button to unfolded long posts (read more). FIX #614, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon bf82092dde 44/50: autoload ht-get, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 639745a885 04/50: move notifs customizes into mastodon.el, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 0e75fc74ee 01/50: group-notifs custom (for servers without). #608. WIP.,
ELPA Syncer <=
- [nongnu] elpa/mastodon bfb17cdf91 10/50: docstrings tl.el, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon f3602493da 03/50: fix notifs custom group, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 8446f239bb 02/50: working v1 notifications custom. #608, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon b529690f96 06/50: notifs: refactor some v1/v2 calling code, mastodon-notifiations--body-arg, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 14e3fa36cb 11/50: start on pagination for v1 notifs. #610, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 4505b4e818 05/50: index, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 1ba949586e 29/50: tl: improve ctrl flow in --spoiler + --toot. FIX #579, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 5cb2bf1c04 16/50: FIX #610 fix note/base toot in format-note/author byline., ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon b6676c180b 27/50: tl: improve ctrl flow in --spoiler + --toot, ELPA Syncer, 2024/11/02
- [nongnu] elpa/mastodon 089eee6485 15/50: notifs: fix author action byline, top, for ungrouped. FIX #612, ELPA Syncer, 2024/11/02