From 20f8972a188fd16180aa201313a95423a49f5fc2 Mon Sep 17 00:00:00 2001 From: green Date: Mon, 12 May 2025 13:54:06 +0200 Subject: metadata for remote users in people page --- html.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'html.c') diff --git a/html.c b/html.c index 2146c93..a96d21a 100644 --- a/html.c +++ b/html.c @@ -3357,6 +3357,46 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c xs_html_add(snac_post, snac_content); } + /* add user metadata */ + xs_html *snac_metadata = xs_html_tag("div", + xs_html_attr("class", "snac-metadata")); + + int count = 0; + const xs_val *v; + const xs_list *attachment = xs_dict_get(actor, "attachment"); + xs_list_foreach(attachment, v) { + const char *type = xs_dict_get(v, "type"); + const char *name = xs_dict_get(v, "name"); + const char *value = xs_dict_get(v, "value"); + + if (!xs_is_null(type) && !xs_is_null(name) && + !xs_is_null(value) && strcmp(type, "PropertyValue") == 0) { + xs *val = sanitize(value); + val = replace_shortnames(val, xs_dict_get(actor, "tag"), 1, proxy); + + xs_html_add(snac_metadata, + xs_html_tag("span", + xs_html_attr("class", "snac-property-name"), + xs_html_text(name)), + xs_html_text(":"), + xs_html_raw(" "), + xs_html_tag("span", + xs_html_attr("class", "snac-property-value"), + xs_html_raw(val)), + xs_html_sctag("br", NULL)); + + count++; + } + } + + if (count > 0) { + xs_html_add(snac_post, snac_metadata); + } + else { + /* free the html, by rendering it... */ + xs_free(xs_html_render(snac_metadata)); + } + /* buttons */ xs *btn_form_action = xs_fmt("%s/admin/action", user->actor); -- cgit v1.2.3 From cda6bc96a57b0829425af96bba28368f70c184e4 Mon Sep 17 00:00:00 2001 From: green Date: Mon, 12 May 2025 19:08:03 +0200 Subject: metadata: quick fix for
tags --- html.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index a96d21a..1c0530f 100644 --- a/html.c +++ b/html.c @@ -3338,10 +3338,11 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c /* content (user bio) */ const char *c = xs_dict_get(actor, "summary"); + const xs_val *tag = xs_dict_get(actor, "tag"); if (!xs_is_null(c)) { xs *sc = sanitize(c); - sc = replace_shortnames(sc, xs_dict_get(actor, "tag"), 2, proxy); + sc = replace_shortnames(sc, tag, 2, proxy); xs_html *snac_content = xs_html_tag("div", xs_html_attr("class", "snac-content")); @@ -3371,13 +3372,22 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c if (!xs_is_null(type) && !xs_is_null(name) && !xs_is_null(value) && strcmp(type, "PropertyValue") == 0) { + /* both the name and the value can contain emoji */ + xs *nam = sanitize(name); + nam = replace_shortnames(nam, tag, 1, proxy); + + /* todo: sometimes the value is transmitted as markdown and not html ._. */ xs *val = sanitize(value); - val = replace_shortnames(val, xs_dict_get(actor, "tag"), 1, proxy); + val = replace_shortnames(val, tag, 1, proxy); + + /* delete
tags, because some software sends them */ + val = xs_replace_i(val, "
", ""); + val = xs_replace_i(val, "
", ""); xs_html_add(snac_metadata, xs_html_tag("span", xs_html_attr("class", "snac-property-name"), - xs_html_text(name)), + xs_html_raw(nam)), xs_html_text(":"), xs_html_raw(" "), xs_html_tag("span", -- cgit v1.2.3 From 380e5b397ef070061cd4393d529bd6d0f0d3eb0b Mon Sep 17 00:00:00 2001 From: green Date: Mon, 16 Jun 2025 19:41:14 +0200 Subject: metadata: location and bday properties --- html.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'html.c') diff --git a/html.c b/html.c index 1c0530f..f8e34f2 100644 --- a/html.c +++ b/html.c @@ -3363,6 +3363,44 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c xs_html_attr("class", "snac-metadata")); int count = 0; + const xs_val *address = xs_dict_get(actor, "vcard:Address"); + if (xs_is_string(address)) { + xs_html_add(snac_metadata, + xs_html_tag("span", + xs_html_attr("class", "snac-property-name"), + xs_html_raw("📍 Location")), + xs_html_text(":"), + xs_html_raw(" "), + xs_html_tag("span", + xs_html_attr("class", "snac-property-value p-adr"), + xs_html_text(address)), + xs_html_sctag("br", NULL)); + + count++; + } + + const xs_val *birthday = xs_dict_get(actor, "vcard:bday"); + if (xs_is_string(birthday)) { + xs_html_add(snac_metadata, + xs_html_tag("span", + xs_html_attr("class", "snac-property-name"), + xs_html_raw("🎂 Birthday")), + xs_html_text(":"), + xs_html_raw(" "), + xs_html_tag("time", + xs_html_attr("class", "snac-property-value dt-bday"), + xs_html_text(birthday)), + xs_html_sctag("br", NULL)); + + count++; + } + + if (count > 0) { + xs_html_add(snac_metadata, + xs_html_sctag("hr", + xs_html_attr("class", "snac-property-divider"))); + } + const xs_val *v; const xs_list *attachment = xs_dict_get(actor, "attachment"); xs_list_foreach(attachment, v) { -- cgit v1.2.3 From fd326d139b06d4a8c9b85b5ab267d34190d48def Mon Sep 17 00:00:00 2001 From: green Date: Mon, 16 Jun 2025 21:07:11 +0200 Subject: metadata: hide the divider when user has no normal fields --- html.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index f8e34f2..454c8be 100644 --- a/html.c +++ b/html.c @@ -3395,14 +3395,14 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c count++; } - if (count > 0) { + const xs_list *attachment = xs_dict_get(actor, "attachment"); + if (count > 0 && xs_list_len(attachment) > 0) { xs_html_add(snac_metadata, xs_html_sctag("hr", xs_html_attr("class", "snac-property-divider"))); } const xs_val *v; - const xs_list *attachment = xs_dict_get(actor, "attachment"); xs_list_foreach(attachment, v) { const char *type = xs_dict_get(v, "type"); const char *name = xs_dict_get(v, "name"); -- cgit v1.2.3