aboutsummaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authormarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-10-29 16:32:24 +0200
committermarty hiatt <martianhiatus [a t] riseup [d o t] net>2022-10-29 16:32:24 +0200
commitf6b983e04fe3ac091398dd74cdbf3a986b969b2a (patch)
tree6c41dafc51d90c2661b69177e61c6a7ad8b272fe /lisp
parent946758ebf2fb9ffc8773c2fa072c79fea143d24c (diff)
working meta fields update
Diffstat (limited to 'lisp')
-rw-r--r--lisp/mastodon-http.el6
-rw-r--r--lisp/mastodon-profile.el46
2 files changed, 36 insertions, 16 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 590f463..6ecabb2 100644
--- a/lisp/mastodon-profile.el
+++ b/lisp/mastodon-profile.el
@@ -404,25 +404,43 @@ This endpoint only holds a few preferences. For others, see
their-id))))
(mastodon-http--get-json url)))
-(defun mastodon-profile-update-meta-fields ()
+;; 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* ((fields-updated (mastodon-profile--update-meta-fields-alist))
- (fields-json (json-encode
- (mapcar (lambda (x)
- (list (cons 'name (car x))
- (cons 'value (cdr x))
- (cons 'verified_at nil)))
- fields-updated))))
- (mastodon-profile--update-preference 'fields_attributes fields-json)))
+ (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-pref 'fields)))
+ (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