From a164bda8719733f4a13e22ba7257ca4bcab0fb17 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 24 Dec 2021 14:36:37 +0100 Subject: refactor follow request accept/reject functions. previously we had duplication of functions depending on whether we were in follow requests view or notificaitons view. now we just check which kind of f-req we have and act accordingly. main function being `mastodon-notifications--follow-request-process'. also updates keybindings for both views. we no longer need them included separately in profile-mode. --- lisp/mastodon-notifications.el | 61 ++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 32 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index bb05103..c8b93a2 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -75,14 +75,24 @@ " " (cdr (assoc message mastodon-notifications--response-alist)))) -(defun mastodon-notifications--follow-request-accept-notifs () - "Accept the follow request of user at point, in notifications view." +(defun mastodon-notifications--follow-request-process (&optional reject) + "Process the follow request at point. +With no argument, the request is accepted. Argument REJECT means +reject the request. Can be called in notifications view or in +follow-requests view." (interactive) (when (mastodon-tl--find-property-range 'toot-json (point)) (let* ((toot-json (mastodon-tl--property 'toot-json)) - (f-req-p (string= "follow_request" (alist-get 'type toot-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 toot-json)) ;notifs + f-reqs-view-p)) + (accept-reject-string (if reject + "reject" + "accept"))) (if f-req-p - (let* ((account (alist-get 'account toot-json)) + (let* ((account (or (alist-get 'account toot-json) ;notifs + toot-json)) ;f-reqs (id (alist-get 'id account)) (handle (alist-get 'acct account)) (name (alist-get 'username account))) @@ -91,41 +101,28 @@ (mastodon-http--post (concat (mastodon-http--api "follow_requests") - (format "/%s/authorize" id)) + (format "/%s/%s" id accept-reject-string)) nil nil))) (mastodon-http--triage response (lambda () - (mastodon-notifications--get) - (message "Follow request of %s (@%s) accepted!" - name handle)))) + (unless f-reqs-view-p + (mastodon-notifications--get)) + (message "Follow request of %s (@%s) %sed!" + name handle accept-reject-string)))) (message "No account result at point?"))) (message "No follow request at point?"))))) -(defun mastodon-notifications--follow-request-reject-notifs () - "Reject the follow request of user at point, in notifications view." +(defun mastodon-notifications--follow-request-accept () + "Accept a follow request. +Can be called in notifications view or in follow-requests view." (interactive) - (when (mastodon-tl--find-property-range 'toot-json (point)) - (let* ((toot-json (mastodon-tl--property 'toot-json)) - (f-req-p (string= "follow_request" (alist-get 'type toot-json)))) - (if f-req-p - (let* ((account (alist-get 'account toot-json)) - (id (alist-get 'id account)) - (handle (alist-get 'acct account)) - (name (alist-get 'username account))) - (if id - (let ((response - (mastodon-http--post - (concat - (mastodon-http--api "follow_requests") - (format "/%s/reject" id)) - nil nil))) - (mastodon-http--triage response - (lambda () - (mastodon-notifications--get) - (message "Follow request of %s (@%s) rejected!" - name handle)))) - (message "No account result at point?"))) - (message "No follow request at point?"))))) + (mastodon-notifications--follow-request-process)) + +(defun mastodon-notifications--follow-request-reject () + "Reject a follow request. +Can be called in notifications view or in follow-requests view." + (interactive) + (mastodon-notifications--follow-request-process t)) (defun mastodon-notifications--mention (note) "Format for a `mention' NOTE." -- cgit v1.2.3 From a56e2bfcaaa7706a2b27656413170c83bffa6ef0 Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 24 Dec 2021 15:10:19 +0100 Subject: refactor mastodon-notifications--insert-status which was a copy of mastodon-tl--insert-status. we revert to having just the latter as main function with optional argument. mastodon-notifications--insert-status just calls it with the arg ID. the reason we need the difference is to ensure notifications have their own ID, and not that of the toot the notif refers to, attached as property "toot-id". then we have all functionality working on notifications, such as boosting mentions and so on. --- lisp/mastodon-notifications.el | 16 ++-------------- lisp/mastodon-tl.el | 10 +++++++--- 2 files changed, 9 insertions(+), 17 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index bb05103..2de53b1 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -226,7 +226,7 @@ Status notifications are given when "Posted")) id))) -(defun mastodon-notifications--insert-status (toot body author-byline action-byline &optional id) +(defun mastodon-notifications--insert-status (toot body author-byline action-byline id) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. @@ -241,19 +241,7 @@ takes a single function. By default it is `mastodon-tl--byline-boosted'. ID is the notification's own id, which is attached as a property." - (let ((start-pos (point))) - (insert - (propertize - (concat "\n" - body - " \n" - (mastodon-tl--byline toot author-byline action-byline)) - 'toot-id id - 'base-toot-id (mastodon-tl--toot-id toot) - 'toot-json toot) - "\n") - (when mastodon-tl--display-media-p - (mastodon-media--inline-images start-pos (point))))) + (mastodon-tl--insert-status toot body author-byline action-byline id)) (defun mastodon-notifications--by-type (note) "Filters NOTE for those listed in `mastodon-notifications--types-alist'." diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index b2b8026..87b8dfc 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -734,7 +734,7 @@ Runs `mastodon-tl--render-text' and fetches poll or media." (mastodon-tl--get-poll toot)) (mastodon-tl--media toot)))) -(defun mastodon-tl--insert-status (toot body author-byline action-byline) +(defun mastodon-tl--insert-status (toot body author-byline action-byline &optional id) "Display the content and byline of timeline element TOOT. BODY will form the section of the toot above the byline. @@ -744,7 +744,10 @@ portion of the byline that takes one variable. By default it is 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'" +`mastodon-tl--byline-boosted'. + +ID is that of the toot, which is attached as a property if it is +a notification." (let ((start-pos (point))) (insert (propertize @@ -752,7 +755,8 @@ takes a single function. By default it is body " \n" (mastodon-tl--byline toot author-byline action-byline)) - 'toot-id (alist-get 'id toot) + 'toot-id (or id ; for notifications + (alist-get 'id toot)) 'base-toot-id (mastodon-tl--toot-id toot) 'toot-json toot) "\n") -- cgit v1.2.3 From b694bcca54822bd7e95e24fc1df16eb86fa87c85 Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 29 Dec 2021 16:58:08 +0100 Subject: fix follow-request-process: change "accept" to "authorize" --- lisp/mastodon-notifications.el | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index d0d221c..6205ebf 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -86,10 +86,7 @@ follow-requests view." (f-reqs-view-p (string= "follow_requests" (plist-get mastodon-tl--buffer-spec 'endpoint))) (f-req-p (or (string= "follow_request" (alist-get 'type toot-json)) ;notifs - f-reqs-view-p)) - (accept-reject-string (if reject - "reject" - "accept"))) + f-reqs-view-p))) (if f-req-p (let* ((account (or (alist-get 'account toot-json) ;notifs toot-json)) ;f-reqs @@ -101,14 +98,18 @@ follow-requests view." (mastodon-http--post (concat (mastodon-http--api "follow_requests") - (format "/%s/%s" id accept-reject-string)) + (format "/%s/%s" id (if reject + "reject" + "authorize"))) nil nil))) (mastodon-http--triage response (lambda () (unless f-reqs-view-p (mastodon-notifications--get)) - (message "Follow request of %s (@%s) %sed!" - name handle accept-reject-string)))) + (message "Follow request of %s (@%s) %s!" + name handle (if reject + "rejected" + "accepted"))))) (message "No account result at point?"))) (message "No follow request at point?"))))) -- cgit v1.2.3 From f6b7e5f3107e1b1d4abfb93f9dad1c2dfffee958 Mon Sep 17 00:00:00 2001 From: mousebot Date: Mon, 3 Jan 2022 23:18:41 +0100 Subject: refactor notification functions --- lisp/mastodon-notifications.el | 123 ++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 75 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 6205ebf..921fdc7 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -127,101 +127,74 @@ Can be called in notifications view or in follow-requests view." (defun mastodon-notifications--mention (note) "Format for a `mention' NOTE." - (let ((id (alist-get 'id note)) - (status (mastodon-tl--field 'status note))) - (mastodon-notifications--insert-status - status - (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler status) - (mastodon-tl--spoiler status) - (mastodon-tl--content status))) - 'mastodon-tl--byline-author - (lambda (_status) - (mastodon-notifications--byline-concat - "Mentioned")) - id))) + (mastodon-notifications--format-note note 'mention)) (defun mastodon-notifications--follow (note) "Format for a `follow' NOTE." - (mastodon-tl--insert-status - ;; Using reblog with an empty id will mark this as something - ;; non-boostable/non-favable. - (cons '(reblog (id . nil)) note) - (propertize "Congratulations, you have a new follower!" - 'face 'default) - 'mastodon-tl--byline-author - (lambda (_status) - (mastodon-notifications--byline-concat - "Followed")))) + (mastodon-notifications--format-note note 'follow)) (defun mastodon-notifications--follow-request (note) "Format for a `follow-request' NOTE." - (let ((id (alist-get 'id note)) - (follower (alist-get 'username (alist-get 'account note)))) - (mastodon-notifications--insert-status - (cons '(reblog (id . nil)) note) - (propertize (format "You have a follow request from... %s" follower) - 'face 'default) - 'mastodon-tl--byline-author - (lambda (_status) - (mastodon-notifications--byline-concat - "Requested to follow")) - id))) + (mastodon-notifications--format-note note 'follow-request)) (defun mastodon-notifications--favourite (note) "Format for a `favourite' NOTE." - (let ((id (alist-get 'id note)) - (status (mastodon-tl--field 'status note))) - (mastodon-notifications--insert-status - status - (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler status) - (mastodon-tl--spoiler status) - (mastodon-tl--content status))) - (lambda (_status) - (mastodon-tl--byline-author - note)) - (lambda (_status) - (mastodon-notifications--byline-concat - "Favourited")) - id))) + (mastodon-notifications--format-note note 'favorite)) (defun mastodon-notifications--reblog (note) "Format for a `boost' NOTE." - (let ((id (alist-get 'id note)) - (status (mastodon-tl--field 'status note))) - (mastodon-notifications--insert-status - status - (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler status) - (mastodon-tl--spoiler status) - (mastodon-tl--content status))) - (lambda (_status) - (mastodon-tl--byline-author - note)) - (lambda (_status) - (mastodon-notifications--byline-concat - "Boosted")) - id))) + (mastodon-notifications--format-note note 'boost)) (defun mastodon-notifications--status (note) "Format for a `status' NOTE. Status notifications are given when `mastodon-tl--enable-notify-user-posts' has been set." - (let ((id (cdr (assoc 'id note))) - (status (mastodon-tl--field 'status note))) + (mastodon-notifications--format-note note 'status)) + +(defun mastodon-notifications--format-note (note type) + "Format for a NOTE of TYPE." + (let ((id (alist-get 'id note)) + (status (mastodon-tl--field 'status note)) + (follower (alist-get 'username (alist-get 'account note)))) (mastodon-notifications--insert-status - status - (mastodon-tl--clean-tabs-and-nl - (if (mastodon-tl--has-spoiler status) - (mastodon-tl--spoiler status) - (mastodon-tl--content status))) - (lambda (_status) - (mastodon-tl--byline-author - note)) + (if (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) + status) + (if (or (equal type 'follow) + (equal type 'follow-request)) + (propertize (if (equal type 'follow) + "Congratulations, you have a new follower!" + (format "You have a follow request from... %s" + follower) + 'face 'default)) + (mastodon-tl--clean-tabs-and-nl + (if (mastodon-tl--has-spoiler status) + (mastodon-tl--spoiler status) + (mastodon-tl--content status)))) + (if (or (equal type 'follow) + (equal type 'follow-request) + (equal type 'mention)) + 'mastodon-tl--byline-author + (lambda (_status) + (mastodon-tl--byline-author + note))) (lambda (_status) (mastodon-notifications--byline-concat - "Posted")) + (cond ((equal type 'boost) + "Boosted") + ((equal type 'favorite) + "Favorited") + ((equal type 'follow-request) + "Requested to follow") + ((equal type 'follow) + "Followed") + ((equal type 'mention) + "Mentioned") + ((equal type 'status) + "Posted")))) id))) (defun mastodon-notifications--insert-status (toot body author-byline action-byline id) -- cgit v1.2.3 From 4eb0b578b5e4ba920999427c137b98043b41c9d4 Mon Sep 17 00:00:00 2001 From: mousebot Date: Wed, 5 Jan 2022 14:14:36 +0100 Subject: add support for poll notifications finally we now display all types of notifications! it's about bloody time. --- lisp/mastodon-notifications.el | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lisp/mastodon-notifications.el') diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 921fdc7..9444658 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -55,7 +55,8 @@ ("favourite" . mastodon-notifications--favourite) ("reblog" . mastodon-notifications--reblog) ("follow_request" . mastodon-notifications--follow-request) - ("status" . mastodon-notifications--status)) + ("status" . mastodon-notifications--status) + ("poll" . mastodon-notifications--poll)) "Alist of notification types and their corresponding function.") (defvar mastodon-notifications--response-alist @@ -64,7 +65,8 @@ ("Favourited" . "your status from") ("Boosted" . "your status from") ("Requested to follow" . "you") - ("Posted" . "a post")) + ("Posted" . "a post") + ("Posted a poll" . "that has now ended")) "Alist of subjects for notification types.") (defun mastodon-notifications--byline-concat (message) @@ -151,6 +153,10 @@ Status notifications are given when `mastodon-tl--enable-notify-user-posts' has been set." (mastodon-notifications--format-note note 'status)) +(defun mastodon-notifications--poll (note) + "Format for a `poll' NOTE." + (mastodon-notifications--format-note note 'poll)) + (defun mastodon-notifications--format-note (note type) "Format for a NOTE of TYPE." (let ((id (alist-get 'id note)) @@ -186,7 +192,7 @@ Status notifications are given when (cond ((equal type 'boost) "Boosted") ((equal type 'favorite) - "Favorited") + "Favourited") ((equal type 'follow-request) "Requested to follow") ((equal type 'follow) @@ -194,7 +200,9 @@ Status notifications are given when ((equal type 'mention) "Mentioned") ((equal type 'status) - "Posted")))) + "Posted") + ((equal type 'poll) + "Posted a poll")))) id))) (defun mastodon-notifications--insert-status (toot body author-byline action-byline id) -- cgit v1.2.3