From 075f1f9ba41100a0fb3161598065a55bf09aaedd Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 30 Oct 2022 11:13:44 +0100 Subject: re-write --make-meta-fields-params to build normal params alist --- lisp/mastodon-http.el | 6 ++---- lisp/mastodon-profile.el | 32 ++++++++++++++------------------ 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 0491927..f32ccd4 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -211,16 +211,14 @@ Optionally specify the PARAMS to send." (with-current-buffer (mastodon-http--patch url params) (mastodon-http--process-json))) -(defun mastodon-http--patch (base-url &optional params no-build) +(defun mastodon-http--patch (base-url &optional params) "Make synchronous PATCH request to BASE-URL. Optionally specify the PARAMS to send." (mastodon-http--authorized-request "PATCH" (let ((url (concat base-url "?" - (if no-build - params - (mastodon-http--build-query-string params))))) + (mastodon-http--build-query-string params)))) (mastodon-http--url-retrieve-synchronously url)))) ;; Asynchronous functions diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 6724038..33c4181 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -365,35 +365,31 @@ Current settings are fetched from the server." (interactive) (mastodon-profile--edit-string-value 'display_name)) -;; TODO: ideally this would return an alist to use like normal params (defun mastodon-profile--make-meta-fields-params (fields) "Construct a parameter query string from metadata alist FIELDS." - (let ((count 0) - (loop-list (cl-loop for x in fields - for count from 0 to 4 - collect (concat - (format "fields_attributes[%s][name]" count) - "=" - (url-hexify-string (car x)) - "&" - (format "fields_attributes[%s][value]" count) - "=" - (url-hexify-string (cdr x)))))) - (mapconcat #'identity loop-list "&"))) + (let ((keys (cl-loop for count from 1 to 5 + collect (cons (format "fields_attributes[%s][name]" count) + (format "fields_attributes[%s][value]" count))))) + (cl-loop for a-pair in keys + for b-pair in fields + append (list (cons (car a-pair) + (car b-pair)) + (cons (cdr a-pair) + (cdr b-pair)))))) (defun mastodon-profile-update-meta-fields () "Prompt for new metadata fields information and PATCH the server." (interactive) (let* ((url (mastodon-http--api "accounts/update_credentials")) - (fields-updated (or data (mastodon-profile--update-meta-fields-alist))) - (param-str (mastodon-profile--make-meta-fields-params fields-updated)) - (response (mastodon-http--patch url param-str :no-build))) - (setq test-fields-str param-str) + (fields-updated (mastodon-profile--update-meta-fields-alist)) + (params (mastodon-profile--make-meta-fields-params fields-updated)) + (response (mastodon-http--patch url params))) + (setq test-fields-str params) (mastodon-http--triage response (lambda () (mastodon-profile-fetch-server-account-settings) (message "Account setting %s updated to %s!" - "metadata fields" params))))) + "metadata fields" fields-updated))))) (defun mastodon-profile--update-meta-fields-alist () "Prompt for new metadata fields information." -- cgit v1.2.3