diff options
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/mastodon-http.el | 6 | ||||
-rw-r--r-- | lisp/mastodon-profile.el | 54 |
2 files changed, 55 insertions, 5 deletions
diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index f32ccd4..0491927 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -211,14 +211,16 @@ 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) +(defun mastodon-http--patch (base-url &optional params no-build) "Make synchronous PATCH request to BASE-URL. Optionally specify the PARAMS to send." (mastodon-http--authorized-request "PATCH" (let ((url (concat base-url "?" - (mastodon-http--build-query-string params)))) + (if no-build + 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 054f6e5..0b35fa4 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -404,10 +404,58 @@ This endpoint only holds a few preferences. For others, see their-id)))) (mastodon-http--get-json url))) -(defun mastodon-profile--fields-get (account) +;; TODO: ideally we wd make a nice alist of all these params +(defun mastodon-profile--make-meta-fields-params (fields) + "" + (let ((count 0) + 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)))))) + +(defun mastodon-profile-update-meta-fields (&optional data) + "" + (interactive) + (let* ((url (mastodon-http--api "accounts/update_credentials")) + (fields-updated (or data(mastodon-profile--update-meta-fields-alist))) + (params (mastodon-profile--make-meta-fields-params fields-updated)) + (param-str (mapconcat #'identity params "&")) + (response (mastodon-http--patch url param-str :no-build))) + (setq test-fields-str param-str) + (mastodon-http--triage response + (lambda () + (mastodon-profile-fetch-server-account-settings) + (message "Account setting %s updated to %s!" + "metadata fields" params))))) + +(defun mastodon-profile--update-meta-fields-alist () + "" + (let ((fields-old (mastodon-profile--fields-get + nil + ;; we must fetch the plaintext version: + (mastodon-profile--get-source-value 'fields))) + fields-new) + (dolist (f fields-old (reverse fields-new)) + (push + (cons (read-string "Edit account metadata key: " + (car f)) + (read-string "Edit account metadata value: " + (cdr f))) + fields-new)))) + +(defun mastodon-profile--fields-get (&optional account fields) "Fetch the fields vector (aka profile metadata) from profile of ACCOUNT. -Returns an alist." - (let ((fields (mastodon-profile--account-field account 'fields))) +Returns an alist. +FIELDS means provide a fields vector fetched by other means." + (let ((fields (or fields + (mastodon-profile--account-field account 'fields)))) (when fields (mapcar (lambda (el) (cons (alist-get 'name el) |