aboutsummaryrefslogtreecommitdiff
path: root/lisp/mastodon-notifications.el
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus@riseup.net>2024-08-09 14:13:24 +0200
committermarty hiatt <martianhiatus@riseup.net>2024-08-09 14:13:24 +0200
commit3bd81ee203d880ca83e3ec22172c0a2508c4d78e (patch)
tree5a89f9b3e5e815edf33fa49e03f9e9ccdb1820e5 /lisp/mastodon-notifications.el
parent8594adb38659bc7e823dea9c379f50c1f35b2969 (diff)
apply filters to notifications. #575.
Diffstat (limited to 'lisp/mastodon-notifications.el')
-rw-r--r--lisp/mastodon-notifications.el150
1 files changed, 79 insertions, 71 deletions
diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el
index f43a9b3..1b93f1b 100644
--- a/lisp/mastodon-notifications.el
+++ b/lisp/mastodon-notifications.el
@@ -212,77 +212,85 @@ Status notifications are given when
(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))))
- (mastodon-tl--insert-status
- ;; toot
- (cond ((or (equal type 'follow)
- (equal 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 (equal type 'favourite)
- (equal type 'boost))
- note)
- (t
- status))
- ;; body
- (let ((body (mastodon-tl--clean-tabs-and-nl
- (if (mastodon-tl--has-spoiler status)
- (mastodon-tl--spoiler status)
- (if (equal 'follow-request type)
- (mastodon-tl--render-text profile-note)
- (mastodon-tl--content status))))))
- (cond ((or (eq type 'follow)
- (eq type 'follow-request))
- (if (equal 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 (equal type 'follow)
- (equal type 'follow-request)
- (equal 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 ((equal type 'boost)
- "Boosted")
- ((equal type 'favourite)
- "Favourited")
- ((equal type 'follow-request)
- "Requested to follow")
- ((equal type 'follow)
- "Followed")
- ((equal type 'mention)
- "Mentioned")
- ((equal type 'status)
- "Posted")
- ((equal type 'poll)
- "Posted a poll")
- ((equal type 'edit)
- "Edited"))))
- id
- ;; base toot
- (when (or (equal type 'favourite)
- (equal type 'boost))
- status))))
+ (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 (equal type 'follow)
+ (equal 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 (equal type 'favourite)
+ (equal 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 (equal 'follow-request type)
+ (mastodon-tl--render-text profile-note)
+ (mastodon-tl--content status)))))))
+ (cond ((or (eq type 'follow)
+ (eq type 'follow-request))
+ (if (equal 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 (equal type 'follow)
+ (equal type 'follow-request)
+ (equal 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 ((equal type 'boost)
+ "Boosted")
+ ((equal type 'favourite)
+ "Favourited")
+ ((equal type 'follow-request)
+ "Requested to follow")
+ ((equal type 'follow)
+ "Followed")
+ ((equal type 'mention)
+ "Mentioned")
+ ((equal type 'status)
+ "Posted")
+ ((equal type 'poll)
+ "Posted a poll")
+ ((equal type 'edit)
+ "Edited"))))
+ id
+ ;; base toot
+ (when (or (equal type 'favourite)
+ (equal type 'boost))
+ status)))))
(defun mastodon-notifications--by-type (note)
"Filter NOTE for those listed in `mastodon-notifications--types-alist'.