diff options
Diffstat (limited to 'lisp/mastodon-profile.el')
-rw-r--r-- | lisp/mastodon-profile.el | 54 |
1 files changed, 51 insertions, 3 deletions
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) |