diff options
author | mousebot <mousebot@riseup.net> | 2021-08-09 17:46:19 +0200 |
---|---|---|
committer | mousebot <mousebot@riseup.net> | 2021-08-09 18:23:44 +0200 |
commit | 2efdb5eb4ddc824ad269af096cb508b8f6867077 (patch) | |
tree | 03d178a15467ed1ac8b64148260a02ce2bb7186e /lisp/mastodon-notifications.el | |
parent | cef6093d477323635e553655498703c480bf00aa (diff) |
follow requests accept/reject from notifications +
- new bindings for f-req accept/reject (in both notifs and in f-req views)
- check if we are at an f-req before accept/rejecting
- flycheck / docstrings
- fix notifs byline formatting for f-reqs
Diffstat (limited to 'lisp/mastodon-notifications.el')
-rw-r--r-- | lisp/mastodon-notifications.el | 77 |
1 files changed, 64 insertions, 13 deletions
diff --git a/lisp/mastodon-notifications.el b/lisp/mastodon-notifications.el index 676b4a8..caeb9cd 100644 --- a/lisp/mastodon-notifications.el +++ b/lisp/mastodon-notifications.el @@ -54,7 +54,7 @@ ("Followed" . "you") ("Favourited" . "your status from") ("Boosted" . "your status from") - ("Follow request" . "requested to follow you")) + ("Requested to follow" . "you")) "Alist of subjects for notification types.") (defun mastodon-notifications--byline-concat (message) @@ -65,6 +65,59 @@ " " (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." + (interactive) + (when (mastodon-tl--find-property-range 'toot-json (point)) + (let* ((toot-json (mastodon-tl--property 'toot-json)) + (f-req-p (string= "follow_request" (cdr (assoc 'type toot-json))))) + (if f-req-p + (let* ((account (cdr (assoc 'account toot-json))) + (id (cdr (assoc 'id account))) + (handle (cdr (assoc 'acct account))) + (name (cdr (assoc 'username account)))) + (if id + (let ((response + (mastodon-http--post + (concat + (mastodon-http--api "follow_requests") + (format "/%s/authorize" id)) + nil nil))) + (mastodon-http--triage response + (lambda () + (mastodon-notifications--get) + (message "Follow request of %s (@%s) accepted!" + name handle)))) + (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." + (interactive) + (when (mastodon-tl--find-property-range 'toot-json (point)) + (let* ((toot-json (mastodon-tl--property 'toot-json)) + (f-req-p (string= "follow_request" (cdr (assoc 'type toot-json))))) + (if f-req-p + (let* ((account (cdr (assoc 'account toot-json))) + (id (cdr (assoc 'id account))) + (handle (cdr (assoc 'acct account))) + (name (cdr (assoc '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?"))))) + (defun mastodon-notifications--mention (note) "Format for a `mention' NOTE." (let ((id (cdr (assoc 'id note))) @@ -97,19 +150,16 @@ (defun mastodon-notifications--follow-request (note) "Format for a `follow-request' NOTE." (let ((id (cdr (assoc 'id note))) - (status (mastodon-tl--field 'status note)) (follower (cdr (assoc 'username (cdr (assoc 'account note)))))) (mastodon-notifications--insert-status - ;; Using reblog with an empty id will mark this as something - ;; non-boostable/non-favable. - (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 you")) - id))) + (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))) (defun mastodon-notifications--favourite (note) "Format for a `favourite' NOTE." @@ -155,7 +205,8 @@ 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'" +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 |