diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-notifications.el | 77 | ||||
-rw-r--r-- | lisp/mastodon-profile.el | 81 | ||||
-rw-r--r-- | lisp/mastodon.el | 4 |
3 files changed, 110 insertions, 52 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 diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 0c1ec91..82eb4db 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -46,6 +46,7 @@ (autoload 'mastodon-tl--byline-author "mastodon-tl.el") (autoload 'mastodon-tl--goto-next-toot "mastodon-tl.el") (autoload 'mastodon-tl--property "mastodon-tl.el") +(autoload 'mastodon-tl--find-property-range "mastodon-tl.el") (autoload 'mastodon-tl--render-text "mastodon-tl.el") (autoload 'mastodon-tl--set-face "mastodon-tl.el") (autoload 'mastodon-tl--timeline "mastodon-tl.el") @@ -70,8 +71,8 @@ (let ((map (make-sparse-keymap))) (define-key map (kbd "O") #'mastodon-profile--open-followers) (define-key map (kbd "o") #'mastodon-profile--open-following) - (define-key map (kbd "C-c a") #'mastodon-profile--follow-request-accept) - (define-key map (kbd "C-c r") #'mastodon-profile--follow-request-reject) + (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'.") @@ -110,13 +111,12 @@ extra keybindings." (mastodon-tl--property 'toot-json)) (defun mastodon-profile--make-author-buffer (account) - "Take a ACCOUNT and inserts a user account into a new buffer." + "Take a ACCOUNT and insert a user account into a new buffer." (mastodon-profile--make-profile-buffer-for account "statuses" #'mastodon-tl--timeline)) (defun mastodon-profile--open-following () - "Open a profile buffer for the current profile showing the accounts -that current profile follows." + "Open a profile buffer showing the accounts that current profile follows." (interactive) (if mastodon-profile--account (mastodon-profile--make-profile-buffer-for @@ -126,8 +126,7 @@ that current profile follows." (error "Not in a mastodon profile"))) (defun mastodon-profile--open-followers () - "Open a profile buffer for the current profile showing the accounts -following the current profile." + "Open a profile buffer showing the accounts following the current profile." (interactive) (if mastodon-profile--account (mastodon-profile--make-profile-buffer-for @@ -155,42 +154,46 @@ following the current profile." (defun mastodon-profile--follow-request-accept () "Accept the follow request of user at point." (interactive) - (let* ((acct-json (mastodon-profile--toot-json)) - (id (cdr (assoc 'id acct-json))) - (handle (cdr (assoc 'acct acct-json))) - (name (cdr (assoc '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?")))) + (if (mastodon-tl--find-property-range 'toot-json (point)) + (let* ((acct-json (mastodon-profile--toot-json)) + (id (cdr (assoc 'id acct-json))) + (handle (cdr (assoc 'acct acct-json))) + (name (cdr (assoc '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) - (let* ((acct-json (mastodon-profile--toot-json)) - (id (cdr (assoc 'id acct-json))) - (handle (cdr (assoc 'acct acct-json))) - (name (cdr (assoc '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?")))) + (if (mastodon-tl--find-property-range 'toot-json (point)) + (let* ((acct-json (mastodon-profile--toot-json)) + (id (cdr (assoc 'id acct-json))) + (handle (cdr (assoc 'acct acct-json))) + (name (cdr (assoc '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." diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 96a092f..a918b44 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -66,6 +66,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-search--search-query "mastodon-search") (autoload 'mastodon-toot--delete-toot "mastodon-toot") (autoload 'mastodon-toot--copy-toot-url "mastodon-toot") @@ -149,6 +151,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) map) "Keymap for `mastodon-mode'.") |