diff options
Diffstat (limited to 'lisp/mastodon-notifications.el')
-rw-r--r-- | lisp/mastodon-notifications.el | 213 |
1 files changed, 90 insertions, 123 deletions
diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index bb05103..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) @@ -75,14 +77,21 @@ " " (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))) (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,142 +100,112 @@ (mastodon-http--post (concat (mastodon-http--api "follow_requests") - (format "/%s/authorize" id)) + (format "/%s/%s" id (if reject + "reject" + "authorize"))) 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) %s!" + name handle (if reject + "rejected" + "accepted"))))) (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." - (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--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)) + (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) + "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")))) 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 +220,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'." |