summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar grunfink2025-11-18 06:06:36 +0100
committerGravatar grunfink2025-11-18 06:06:36 +0100
commit497fccd285e9460e19664b0af361171c4efbe960 (patch)
treee11e7f2721dcfc58c463f63df9375f680085cd23
parentSome implementations set quoted posts with 'quoteUrl', so look at that as well. (diff)
parentmetadata: hide the divider when user has no normal fields (diff)
downloadsnac2-497fccd285e9460e19664b0af361171c4efbe960.tar.gz
snac2-497fccd285e9460e19664b0af361171c4efbe960.tar.xz
snac2-497fccd285e9460e19664b0af361171c4efbe960.zip
Merge pull request 'Add metadata to remote users' (#499) from dandelions/snac2:metadata-pr into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/499
-rw-r--r--html.c90
1 files changed, 89 insertions, 1 deletions
diff --git a/html.c b/html.c
index df16038..18038ff 100644
--- a/html.c
+++ b/html.c
@@ -3355,10 +3355,11 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c
3355 3355
3356 /* content (user bio) */ 3356 /* content (user bio) */
3357 const char *c = xs_dict_get(actor, "summary"); 3357 const char *c = xs_dict_get(actor, "summary");
3358 const xs_val *tag = xs_dict_get(actor, "tag");
3358 3359
3359 if (!xs_is_null(c)) { 3360 if (!xs_is_null(c)) {
3360 xs *sc = sanitize(c); 3361 xs *sc = sanitize(c);
3361 sc = replace_shortnames(sc, xs_dict_get(actor, "tag"), 2, proxy); 3362 sc = replace_shortnames(sc, tag, 2, proxy);
3362 3363
3363 xs_html *snac_content = xs_html_tag("div", 3364 xs_html *snac_content = xs_html_tag("div",
3364 xs_html_attr("class", "snac-content")); 3365 xs_html_attr("class", "snac-content"));
@@ -3374,6 +3375,93 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c
3374 xs_html_add(snac_post, snac_content); 3375 xs_html_add(snac_post, snac_content);
3375 } 3376 }
3376 3377
3378 /* add user metadata */
3379 xs_html *snac_metadata = xs_html_tag("div",
3380 xs_html_attr("class", "snac-metadata"));
3381
3382 int count = 0;
3383 const xs_val *address = xs_dict_get(actor, "vcard:Address");
3384 if (xs_is_string(address)) {
3385 xs_html_add(snac_metadata,
3386 xs_html_tag("span",
3387 xs_html_attr("class", "snac-property-name"),
3388 xs_html_raw("📍 Location")),
3389 xs_html_text(":"),
3390 xs_html_raw(" "),
3391 xs_html_tag("span",
3392 xs_html_attr("class", "snac-property-value p-adr"),
3393 xs_html_text(address)),
3394 xs_html_sctag("br", NULL));
3395
3396 count++;
3397 }
3398
3399 const xs_val *birthday = xs_dict_get(actor, "vcard:bday");
3400 if (xs_is_string(birthday)) {
3401 xs_html_add(snac_metadata,
3402 xs_html_tag("span",
3403 xs_html_attr("class", "snac-property-name"),
3404 xs_html_raw("🎂 Birthday")),
3405 xs_html_text(":"),
3406 xs_html_raw(" "),
3407 xs_html_tag("time",
3408 xs_html_attr("class", "snac-property-value dt-bday"),
3409 xs_html_text(birthday)),
3410 xs_html_sctag("br", NULL));
3411
3412 count++;
3413 }
3414
3415 const xs_list *attachment = xs_dict_get(actor, "attachment");
3416 if (count > 0 && xs_list_len(attachment) > 0) {
3417 xs_html_add(snac_metadata,
3418 xs_html_sctag("hr",
3419 xs_html_attr("class", "snac-property-divider")));
3420 }
3421
3422 const xs_val *v;
3423 xs_list_foreach(attachment, v) {
3424 const char *type = xs_dict_get(v, "type");
3425 const char *name = xs_dict_get(v, "name");
3426 const char *value = xs_dict_get(v, "value");
3427
3428 if (!xs_is_null(type) && !xs_is_null(name) &&
3429 !xs_is_null(value) && strcmp(type, "PropertyValue") == 0) {
3430 /* both the name and the value can contain emoji */
3431 xs *nam = sanitize(name);
3432 nam = replace_shortnames(nam, tag, 1, proxy);
3433
3434 /* todo: sometimes the value is transmitted as markdown and not html ._. */
3435 xs *val = sanitize(value);
3436 val = replace_shortnames(val, tag, 1, proxy);
3437
3438 /* delete <p> tags, because some software sends them */
3439 val = xs_replace_i(val, "<p>", "");
3440 val = xs_replace_i(val, "</p>", "");
3441
3442 xs_html_add(snac_metadata,
3443 xs_html_tag("span",
3444 xs_html_attr("class", "snac-property-name"),
3445 xs_html_raw(nam)),
3446 xs_html_text(":"),
3447 xs_html_raw("&nbsp;"),
3448 xs_html_tag("span",
3449 xs_html_attr("class", "snac-property-value"),
3450 xs_html_raw(val)),
3451 xs_html_sctag("br", NULL));
3452
3453 count++;
3454 }
3455 }
3456
3457 if (count > 0) {
3458 xs_html_add(snac_post, snac_metadata);
3459 }
3460 else {
3461 /* free the html, by rendering it... */
3462 xs_free(xs_html_render(snac_metadata));
3463 }
3464
3377 /* buttons */ 3465 /* buttons */
3378 xs *btn_form_action = xs_fmt("%s/admin/action", user->actor); 3466 xs *btn_form_action = xs_fmt("%s/admin/action", user->actor);
3379 3467