From 158bfd8785e46f134f699c5d6423e8c1785daf1c Mon Sep 17 00:00:00 2001 From: mousebot Date: Fri, 29 Oct 2021 19:00:22 +0200 Subject: make get-max-toot-chars async --- lisp/mastodon-toot.el | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lisp/mastodon-toot.el') diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 309b64a..3e3619c 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -154,12 +154,17 @@ Valid values are \"direct\", \"private\" (followers-only), \"unlisted\", and \"p "Keymap for `mastodon-toot'.") (defun mastodon-toot--get-max-toot-chars () - "Fetch max_toot_chars from `mastodon-instance-url'." - (let ((instance-json (mastodon-http--get-json - (mastodon-http--api "instance")))) - (setq mastodon-toot--max-toot-chars - (number-to-string - (cdr (assoc 'max_toot_chars instance-json)))))) + "Fetch max_toot_chars from `mastodon-instance-url' asynchronously." + (mastodon-http--get-json-async + (mastodon-http--api "instance") 'mastodon-toot--get-max-toot-chars-callback)) + +(defun mastodon-toot--get-max-toot-chars-callback (json-response) + "Set max_toot_chars returned in JSON-RESPONSE." + (setq mastodon-toot--max-toot-chars + (number-to-string + (cdr (assoc 'max_toot_chars json-response)))) + (with-current-buffer "*new toot*" + (mastodon-toot--update-status-fields))) (defun mastodon-toot--action-success (marker byline-region remove) "Insert/remove the text MARKER with 'success face in byline. -- cgit v1.2.3