diff options
author | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2023-08-22 18:20:30 +0200 |
---|---|---|
committer | marty hiatt <martianhiatus [a t] riseup [d o t] net> | 2023-08-22 18:39:46 +0200 |
commit | ef0db16833485400704c1b65d5a4e464256a94b7 (patch) | |
tree | d670f6b9ebe1a7d5df8f67176290e3b2c23e6055 | |
parent | 38d6382a1f8bc50c76f77a407ae5db4ff0d75156 (diff) |
new fun: mastodon-return-credential-account, var: mastodon-profile-credential-account
FIX #480.
-rw-r--r-- | lisp/mastodon-auth.el | 9 | ||||
-rw-r--r-- | lisp/mastodon-profile.el | 11 | ||||
-rw-r--r-- | lisp/mastodon.el | 12 |
3 files changed, 21 insertions, 11 deletions
diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index 4d43962..eb57368 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -44,6 +44,7 @@ (autoload 'mastodon-http--concat-params-to-url "mastodon-http") (autoload 'mastodon-http--get-json "mastodon-http") (autoload 'mastodon-http--post "mastodon-http") +(autoload 'mastodon-return-credential-account "mastodon") (defvar mastodon-instance-url) (defvar mastodon-client-scopes) @@ -209,16 +210,12 @@ Handle any errors from the server." (defun mastodon-auth--get-account-name () "Request user credentials and return an account name." (alist-get 'acct - (mastodon-http--get-json (mastodon-http--api - "accounts/verify_credentials") - nil - :silent))) + (mastodon-return-credential-account))) (defun mastodon-auth--get-account-id () "Request user credentials and return an account name." (alist-get 'id - (mastodon-http--get-json (mastodon-http--api - "accounts/verify_credentials")))) + (mastodon-return-credential-account))) (defun mastodon-auth--user-acct () "Return a mastodon user acct name." diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index bbd286e..de235b3 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -105,6 +105,10 @@ extra keybindings." :group 'mastodon :global nil) +(defvar mastodon-profile-credential-account nil + "Holds the JSON data of the CredentialAccount entity, + containing details of the current user's account.") + (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) @@ -212,8 +216,7 @@ NO-REBLOGS means do not display boosts in statuses." (defun mastodon-profile--get-json-value (val) "Fetch current VAL ue from account." - (let* ((url (mastodon-http--api "accounts/verify_credentials")) - (response (mastodon-http--get-json url))) + (let* ((response (mastodon-return-credential-account))) (if (eq (alist-get val response) :json-false) nil (alist-get val response)))) @@ -232,9 +235,7 @@ NO-REBLOGS means do not display boosts in statuses." (defun mastodon-profile--update-user-profile-note () "Fetch user's profile note and display for editing." (interactive) - (let* ((endpoint "accounts/verify_credentials") - (url (mastodon-http--api endpoint)) - (json (mastodon-http--get-json url)) + (let* ((json (mastodon-return-credential-account)) (source (alist-get 'source json)) (note (alist-get 'note source)) (buffer (get-buffer-create "*mastodon-update-profile*")) diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 84d3d1d..a3b372d 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -281,6 +281,7 @@ See `mastodon-toot-display-orig-in-reply-buffer'.") (string-prefix-p "*mastodon-" (buffer-name x)) (get-buffer x))) (buffer-list))))) ; catch any other masto buffer + (mastodon-return-credential-account) (if buffer (switch-to-buffer buffer) (mastodon-tl--get-home-timeline) @@ -288,6 +289,17 @@ See `mastodon-toot-display-orig-in-reply-buffer'.") (mastodon-auth--user-acct) mastodon-instance-url)))) +(defvar mastodon-profile-credential-account nil) + +(defun mastodon-return-credential-account () + "Return the CredentialAccount entity. +Either from `mastodon-profile-credential-account' or from the server." + (or mastodon-profile-credential-account + (setq mastodon-profile-credential-account + (mastodon-http--get-json + (mastodon-http--api "accounts/verify_credentials") + nil :silent)))) + ;;;###autoload (defun mastodon-toot (&optional user reply-to-id reply-json) "Update instance with new toot. Content is captured in a new buffer. |