diff options
-rw-r--r-- | lisp/mastodon-tl.el | 27 | ||||
-rw-r--r-- | lisp/mastodon.el | 1 |
2 files changed, 27 insertions, 1 deletions
diff --git a/lisp/mastodon-tl.el b/lisp/mastodon-tl.el index 14623e6..10284d2 100644 --- a/lisp/mastodon-tl.el +++ b/lisp/mastodon-tl.el @@ -45,6 +45,7 @@ ;; try an autoload for new follow fun (autoload 'mastodon-profile--toot-json "mastodon-profile.el") (autoload 'mastodon-profile--account-field "mastodon-profile.el") +(autoload 'mastodon-profile--extract-users-handles "mastodon-profile.el") (defvar mastodon-instance-url) (defvar mastodon-toot-timestamp-format) (defvar shr-use-fonts) ;; need to declare it since Emacs24 didn't have this @@ -799,7 +800,7 @@ webapp" (message "Toot deleted! There may be a delay before it disappears from your profile.")))))) (defun mastodon-tl--follow-user (user-handle) - "Query user for user id from current status and follow that user." + "Query for user id from current status and follow that user." (interactive (list (let ((user-handles (mastodon-profile--extract-users-handles @@ -820,6 +821,30 @@ webapp" (message "User %s (@%s) followed!" name user-handle)))) (message "Cannot find a user with handle %S" user-handle)))) +(defun mastodon-tl--unfollow-user (user-handle) + "Query for user id from current status and unfollow that user." + (interactive + (list + (let ((user-handles (mastodon-profile--extract-users-handles + (mastodon-profile--toot-json)))) + (completing-read "User handle: " + user-handles + nil ; predicate + 'confirm)))) + (let* ((account (mastodon-profile--lookup-account-in-status + user-handle (mastodon-profile--toot-json))) + (user-id (mastodon-profile--account-field account 'id)) + (name (mastodon-profile--account-field account 'display_name)) + (url (mastodon-http--api (format "accounts/%s/unfollow" user-id)))) + (if account + (when (y-or-n-p (format "Unfollow user %s? " name)) + (let ((response (mastodon-http--post url nil nil))) + (mastodon-http--triage response + (lambda () + (message "User %s (@%s) unfollowed!" name user-handle)))) + (message "Cannot find a user with handle %S" user-handle))))) + + (defun mastodon-tl--more () "Append older toots to timeline." (interactive) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index a6609ac..22c7c1c 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -108,6 +108,7 @@ Use. e.g. \"%c\" for your locale's date and time format." (define-key map (kbd "g") #'undefined) (define-key map (kbd "D") #'mastodon-tl--delete-toot) (define-key map (kbd "W") #'mastodon-tl--follow-user) + (define-key map (kbd "C-S-W") #'mastodon-tl--unfollow-user) map) "Keymap for `mastodon-mode'.") |