From 5a3c7cf98532d7ae74c79cc1198f902895e2209a Mon Sep 17 00:00:00 2001 From: default Date: Mon, 18 Sep 2023 11:13:30 +0200 Subject: [PATCH] Added web UI to store profile metadata (as key/value pairs). --- html.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/html.c b/html.c index 42c9215..1dab77f 100644 --- a/html.c +++ b/html.c @@ -581,6 +581,11 @@ xs_str *html_top_controls(snac *snac, xs_str *s) "

\n" "

\n" + "

%s:
\n" + "

\n" + "

%s:
\n" "

\n" @@ -636,6 +641,19 @@ xs_str *html_top_controls(snac *snac, xs_str *s) xs *es5 = encode_html(telegram_chat_id); xs *es6 = encode_html(purge_days); + xs *metadata = xs_str_new(NULL); + xs_dict *md = xs_dict_get(snac->config, "metadata"); + xs_str *k; + xs_str *v; + + while (xs_dict_iter(&md, &k, &v)) { + xs *kp = xs_fmt("%s=%s", k, v); + + if (*metadata) + metadata = xs_str_cat(metadata, "\n"); + metadata = xs_str_cat(metadata, kp); + } + xs *s1 = xs_fmt(_tmpl, L("New Post..."), snac->actor, @@ -686,6 +704,10 @@ xs_str *html_top_controls(snac *snac, xs_str *s) L("Drop direct messages from people you don't follow"), xs_type(bot) == XSTYPE_TRUE ? "checked" : "", L("This account is a bot"), + + L("Profile metadata (key=value pairs in each line)"), + metadata, + L("New password"), L("Repeat new password"), L("Update user info") @@ -2467,6 +2489,25 @@ int html_post_handler(const xs_dict *req, const char *q_path, snac.config = xs_dict_set(snac.config, "bot", xs_stock_true); else snac.config = xs_dict_set(snac.config, "bot", xs_stock_false); + if ((v = xs_dict_get(p_vars, "metadata")) != NULL) { + /* split the metadata and store it as a dict */ + xs_dict *md = xs_dict_new(); + xs *l = xs_split(v, "\n"); + xs_list *p = l; + xs_str *kp; + + while (xs_list_iter(&p, &kp)) { + xs *kpl = xs_split_n(kp, "=", 1); + if (xs_list_len(kpl) == 2) { + xs *k2 = xs_strip_i(xs_dup(xs_list_get(kpl, 0))); + xs *v2 = xs_strip_i(xs_dup(xs_list_get(kpl, 1))); + + md = xs_dict_set(md, k2, v2); + } + } + + snac.config = xs_dict_set(snac.config, "metadata", md); + } /* uploads */ const char *uploads[] = { "avatar", "header", NULL };