diff options
author | mousebot <mousebot@riseup.net> | 2021-12-24 14:36:37 +0100 |
---|---|---|
committer | mousebot <mousebot@riseup.net> | 2021-12-24 14:36:37 +0100 |
commit | a164bda8719733f4a13e22ba7257ca4bcab0fb17 (patch) | |
tree | f73ac107bdfa4ffde72bb9859f31fe1b4e18415b | |
parent | d544d6774542afe82ab4b513c7d3717e9d692efc (diff) |
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.
-rw-r--r-- | lisp/mastodon-notifications.el | 61 | ||||
-rw-r--r-- | lisp/mastodon-profile.el | 46 | ||||
-rw-r--r-- | lisp/mastodon.el | 8 |
3 files changed, 33 insertions, 82 deletions
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." diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 05cacde..21b40b3 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -69,8 +69,6 @@ (let ((map (make-sparse-keymap))) (define-key map (kbd "s") #'mastodon-profile--open-followers) (define-key map (kbd "g") #'mastodon-profile--open-following) - (define-key map (kbd "a") #'mastodon-profile--follow-request-accept) - (define-key map (kbd "j") #'mastodon-profile--follow-request-reject) map) "Keymap for `mastodon-profile-mode'.") @@ -153,50 +151,6 @@ extra keybindings." "follow_requests" 'mastodon-profile--add-author-bylines)) -(defun mastodon-profile--follow-request-accept () - "Accept the follow request of user at point." - (interactive) - (if (mastodon-tl--find-property-range 'toot-json (point)) - (let* ((acct-json (mastodon-profile--toot-json)) - (id (alist-get 'id acct-json)) - (handle (alist-get 'acct acct-json)) - (name (alist-get 'username acct-json))) - (if id - (let ((response - (mastodon-http--post - (concat - (mastodon-http--api "follow_requests") - (format "/%s/authorize" id)) - nil nil))) - (mastodon-http--triage response - (lambda () - (message "Follow request of %s (@%s) accepted!" - name handle)))) - (message "No account result at point?"))) - (message "No follow request at point?"))) - -(defun mastodon-profile--follow-request-reject () - "Reject the follow request of user at point." - (interactive) - (if (mastodon-tl--find-property-range 'toot-json (point)) - (let* ((acct-json (mastodon-profile--toot-json)) - (id (alist-get 'id acct-json)) - (handle (alist-get 'acct acct-json)) - (name (alist-get 'username acct-json))) - (if id - (let ((response - (mastodon-http--post - (concat - (mastodon-http--api "follow_requests") - (format "/%s/reject" id)) - nil nil))) - (mastodon-http--triage response - (lambda () - (message "Follow request of %s (@%s) rejected!" - name handle)))) - (message "No account result at point?"))) - (message "No follow request at point?"))) - (defun mastodon-profile--update-user-profile-note () "Fetch user's profile note and display for editing." (interactive) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index d5f9b6e..f65a86d 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -69,8 +69,8 @@ (autoload 'mastodon-profile--my-profile "mastodon-profile") (autoload 'mastodon-profile--view-favourites "mastodon-profile") (autoload 'mastodon-profile--view-follow-requests "mastodon-profile") -(autoload 'mastodon-notifications--follow-request-accept-notifs "mastodon-profile") -(autoload 'mastodon-notifications--follow-request-reject-notifs "mastodon-profile") +(autoload 'mastodon-notifications--follow-request-accept "mastodon-notifications") +(autoload 'mastodon-notifications--follow-request-reject "mastodon-notifications") (autoload 'mastodon-search--search-query "mastodon-search") ;; (autoload 'mastodon-toot--delete-toot "mastodon-toot") ;; (autoload 'mastodon-toot--copy-toot-url "mastodon-toot") @@ -160,8 +160,8 @@ Use. e.g. \"%c\" for your locale's date and time format." ;; (define-key map (kbd "C-c l") #'mastodon-async--stream-local) ;; (define-key map (kbd "C-c n") #'mastodon-async--stream-notifications) (define-key map (kbd "U") #'mastodon-profile--update-user-profile-note) - (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept-notifs) - (define-key map (kbd "j") #'mastodon-notifications--follow-request-reject-notifs) + (define-key map (kbd "a") #'mastodon-notifications--follow-request-accept) + (define-key map (kbd "j") #'mastodon-notifications--follow-request-reject) (define-key map (kbd "v") #'mastodon-tl--poll-vote) (define-key map (kbd "k") #'mastodon-toot--bookmark-toot-toggle) (define-key map (kbd "K") #'mastodon-profile--view-bookmarks) |