From 2fb09762a4150d6a14fb3217b2debef948df6ff9 Mon Sep 17 00:00:00 2001 From: marty hiatt Date: Sun, 30 Oct 2022 13:05:08 +0100 Subject: hack to limit meta fields to 255 w/o using string-limit --- lisp/mastodon-profile.el | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'lisp/mastodon-profile.el') diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 505dbc4..d6819db 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -385,7 +385,6 @@ Returns an alist." (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) @@ -398,19 +397,30 @@ Returns the results as an alist." (let ((fields-old (mastodon-profile--fields-get nil ;; we must fetch the plaintext version: - (mastodon-profile--get-source-value 'fields))) - fields-new) + (mastodon-profile--get-source-value 'fields)))) ;; offer empty fields if user currently has less than four filled: (while (< (length fields-old) 4) (setq fields-old (append fields-old '(("" . ""))))) - (cl-loop for f in fields-old - for x from 1 to 5 - collect - (cons (read-string (format "Edit account metadata key [%s/4]: " x) - (car f)) - (read-string (format "Edit account metadata value [%s/4]: " x) - (cdr f)))))) + (let ((alist + (cl-loop for f in fields-old + for x from 1 to 5 + collect + (cons (read-string + (format "Metadata key [%s/4] (max. 255 chars): " x) + (car f)) + (read-string + (format "Metadata value [%s/4] (max. 255 chars): " x) + (cdr f)))))) + ;; hack to avoiding using `string-limit', which req. 28.1: + (mapcar (lambda (x) + (cons (mastodon-profile--limit-to-255 (car x)) + (mastodon-profile--limit-to-255 (cdr x)))) + alist)))) + +(defun mastodon-profile--limit-to-255 (x) + "Limit string X to 255 chars max." + (if (> (length x) 255) (substring x 0 255) x)) (defun mastodon-profile--get-preferences-pref (pref) "Fetch PREF from the endpoint \"/preferences\". -- cgit v1.2.3