aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.org8
-rw-r--r--lisp/mastodon-http.el25
-rw-r--r--lisp/mastodon-profile.el69
-rw-r--r--lisp/mastodon.el4
4 files changed, 94 insertions, 12 deletions
diff --git a/README.org b/README.org
index 6da0f4b..c6eab5a 100644
--- a/README.org
+++ b/README.org
@@ -6,13 +6,15 @@ It adds the following features:
| Profiles: | |
| | display profile metadata fields |
+| | display pinned toots on profiles |
| | display relationship (follows you/followed by you) on profiles |
| | display toots/follows/followers counts on profiles |
-| | links and tags in profiles are tab stops like in posts |
+| | links and tags in profiles and metadata fields are tab stops like in posts |
| =R=, =a=, =r= | view/accept/reject follow requests |
| =v= | view your favorited toots |
-| =i= | (un)pin toots, display pinned toots on profiles |
+| =i= | (un)pin toots |
| =S-C-P= | jump to your profile |
+| =U= | update your profile bio note |
| Timelines: | |
| =W=, =M=, =B= | (un)follow, (un)mute, (un)block users |
| | images are links to the full image, can be zoomed/rotated/saved (see their keymap) |
@@ -37,7 +39,7 @@ I did this for my own use and to learn more Elisp. If the code is terrible, feel
(code adapted from https://github.com/alexjgriffith/mastodon-future.el).
-Works for federated, local, and home timelines and for notifications. It's pretty necro, so use at your own risk. Not a super high priority for me, but some people dig it. The command prefix is =mastodon-async--stream=
+Works for federated, local, and home timelines and for notifications. It's pretty necro, so use at your own risk. Not a super high priority for me, but some people dig it. The command prefix is =mastodon-async--stream=.
** NB: dependency
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el
index e85429f..678e628 100644
--- a/lisp/mastodon-http.el
+++ b/lisp/mastodon-http.el
@@ -137,7 +137,7 @@ Pass response buffer to CALLBACK function."
(with-temp-buffer
(url-retrieve-synchronously url))))
-;; http functions for search:
+;; search functions:
(defun mastodon-http--process-json-search ()
"Process JSON returned by a search query to the server."
(goto-char (point-min))
@@ -168,6 +168,29 @@ Pass response buffer to CALLBACK function."
(url-retrieve-synchronously url)
(url-retrieve-synchronously url nil nil mastodon-http--timeout))))
+;; profile update functions
+
+(defun mastodon-http--patch-json (url)
+ "Make synchronous PATCH request to URL. Return JSON response."
+ (with-current-buffer (mastodon-http--patch url)
+ (mastodon-http--process-json)))
+
+;; hard coded just for bio note for now:
+(defun mastodon-http--patch (base-url &optional note)
+ "Make synchronous PATCH request to URL.
+
+Pass response buffer to CALLBACK function."
+ (let ((url-request-method "PATCH")
+ (url (if note
+ (concat base-url "?note=" (url-hexify-string note))
+ base-url))
+ (url-request-extra-headers
+ `(("Authorization" . ,(concat "Bearer "
+ (mastodon-auth--access-token))))))
+ (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4)
+ (url-retrieve-synchronously url)
+ (url-retrieve-synchronously url nil nil mastodon-http--timeout))))
+
;; Asynchronous functions
(defun mastodon-http--get-async (url &optional callback &rest cbargs)
diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el
index 84664c0..0b7ecc4 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -53,15 +53,28 @@
(autoload 'mastodon-tl--toot-id "mastodon-tl")
(autoload 'mastodon-tl--toot "mastodon-tl")
(autoload 'mastodon-tl--init "mastodon-tl.el")
+(autoload 'mastodon-http--patch "mastodon-http")
+(autoload 'mastodon-http--patch-json "mastodon-http")
(defvar mastodon-instance-url)
(defvar mastodon-tl--buffer-spec)
(defvar mastodon-tl--update-point)
+
(defvar mastodon-profile--account nil
"The data for the account being described in the current profile buffer.")
(make-variable-buffer-local 'mastodon-profile--account)
+;; this way you can update it with C-M-x:
+(defvar mastodon-profile-mode-map
+ (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 "a") #'mastodon-profile--follow-request-accept)
+ (define-key map (kbd "r") #'mastodon-profile--follow-request-reject)
+ map)
+ "Keymap for `mastodon-profile-mode'.")
+
(define-minor-mode mastodon-profile-mode
"Toggle mastodon profile minor mode.
@@ -70,12 +83,26 @@ extra keybindings."
:init-value nil
;; The mode line indicator.
:lighter " Profile"
- ;; The key bindings
- :keymap '(((kbd "O") . mastodon-profile--open-followers)
- ((kbd "o") . mastodon-profile--open-following)
- ((kbd "a") . mastodon-profile--follow-request-accept)
- ((kbd "r") . mastodon-profile--follow-request-reject))
- :group 'mastodon)
+ :keymap mastodon-profile-mode-map
+ ;; :keymap '(((kbd "O") . mastodon-profile--open-followers)
+ ;; ((kbd "o") . mastodon-profile--open-following)
+ ;; ((kbd "a") . mastodon-profile--follow-request-accept)
+ ;; ((kbd "r") . mastodon-profile--follow-request-reject)
+ :group 'mastodon
+ :global nil)
+
+(defvar mastodon-profile-update-mode-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "C-c C-c") #'mastodon-profile--user-profile-send-updated)
+ (define-key map (kbd "C-c C-k") #'kill-buffer-and-window)
+ map)
+ "Keymap for `mastodon-profile-update-mode'.")
+
+(define-minor-mode mastodon-profile-update-mode
+ "Minor mode to update Mastodon user profile."
+ :group 'mastodon-profile
+ :keymap mastodon-profile-update-mode-map
+ :global nil)
(defun mastodon-profile--toot-json ()
"Get the next toot-json."
@@ -112,6 +139,7 @@ following the current profile."
(defun mastodon-profile--view-favourites ()
"Open a new buffer displaying the user's favourites."
(interactive)
+ (message "Loading your favourited toots...")
(mastodon-tl--init "favourites"
"favourites"
'mastodon-tl--timeline))
@@ -164,6 +192,33 @@ following the current profile."
name handle))))
(message "No account result at point?"))))
+(defun mastodon-profile--update-user-profile-note ()
+ "Fetch user's profile note and display for editing."
+ (interactive)
+ (let* ((url (concat mastodon-instance-url
+ "/api/v1/accounts/update_credentials"))
+ ;; (buffer (mastodon-http--patch url))
+ (json (mastodon-http--patch-json url))
+ (source (cdr (assoc 'source json)))
+ (note (cdr (assoc 'note source)))
+ (buffer (get-buffer-create "*mastodon-update-profile*"))
+ (inhibit-read-only t))
+ (switch-to-buffer-other-window buffer)
+ (mastodon-profile-update-mode t)
+ (insert note)
+ (goto-char (point-min))
+ (message "Edit your profile note. C-c C-c to send, C-c C-k to cancel.")))
+
+(defun mastodon-profile--user-profile-send-updated ()
+ "Send PATCH request with the updated profile note."
+ (interactive)
+ (let* ((note (buffer-substring-no-properties (point-min) (point-max)))
+ (url (concat mastodon-instance-url
+ "/api/v1/accounts/update_credentials")))
+ (kill-buffer-and-window)
+ (let ((response (mastodon-http--patch url note)))
+ (mastodon-http--triage response
+ (lambda () (message "Profile note updated!"))))))
(defun mastodon-profile--relationships-get (id)
"Fetch info about logged-in user's relationship to user with id ID."
@@ -205,7 +260,7 @@ Returns a list of lists."
(format " :: %s" (cadr field)))
;; (make-string (- (+ 1 right-width) (length (cdr field))) ?_)
;; " |")
- nil))
+ field)) ; nil)) ; hack to make links tabstops
fields "")))
(defun mastodon-profile--get-statuses-pinned (account)
diff --git a/lisp/mastodon.el b/lisp/mastodon.el
index 4d0b940..c1c4360 100644
--- a/lisp/mastodon.el
+++ b/lisp/mastodon.el
@@ -73,6 +73,7 @@
(autoload 'mastodon-async--stream-local "mastodon-async")
(autoload 'mastodon-async--stream-home "mastodon-async")
(autoload 'mastodon-async--stream-notifications "mastodon-async")
+(autoload 'mastodon-profile--update-user-profile-note "mastodon-profile")
(defgroup mastodon nil
"Interface with Mastodon."
@@ -143,7 +144,8 @@ Use. e.g. \"%c\" for your locale's date and time format."
(define-key map (kbd "C-c h") #'mastodon-async--stream-home)
(define-key map (kbd "C-c f") #'mastodon-async--stream-federated)
(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 "C-c n") #'mastodon-async--stream-notifications)
+ (define-key map (kbd "U") #'mastodon-profile--update-user-profile-note)
map)
"Keymap for `mastodon-mode'.")