aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus@riseup.net>2024-10-16 13:39:30 +0200
committermarty hiatt <martianhiatus@riseup.net>2024-10-16 13:39:30 +0200
commitf114f3c19066e5bd7211389e6730b23a17c35e09 (patch)
tree5dd0202cc97d154a891d17b95757d9821807a690
parent7800c16bf9cf28cc60fc8c8bd2dbe858fe6f290f (diff)
notifs: fix foll_reqs
-rw-r--r--lisp/mastodon-notifications.el154
-rw-r--r--lisp/mastodon-tl.el19
2 files changed, 92 insertions, 81 deletions
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