commit 497fccd
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
1 files changed,
+89,
-1
M
html.c
M
html.c
+89,
-1
1@@ -3355,10 +3355,11 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c
2
3 /* content (user bio) */
4 const char *c = xs_dict_get(actor, "summary");
5+ const xs_val *tag = xs_dict_get(actor, "tag");
6
7 if (!xs_is_null(c)) {
8 xs *sc = sanitize(c);
9- sc = replace_shortnames(sc, xs_dict_get(actor, "tag"), 2, proxy);
10+ sc = replace_shortnames(sc, tag, 2, proxy);
11
12 xs_html *snac_content = xs_html_tag("div",
13 xs_html_attr("class", "snac-content"));
14@@ -3374,6 +3375,93 @@ xs_html *html_people_list(snac *user, xs_list *list, const char *header, const c
15 xs_html_add(snac_post, snac_content);
16 }
17
18+ /* add user metadata */
19+ xs_html *snac_metadata = xs_html_tag("div",
20+ xs_html_attr("class", "snac-metadata"));
21+
22+ int count = 0;
23+ const xs_val *address = xs_dict_get(actor, "vcard:Address");
24+ if (xs_is_string(address)) {
25+ xs_html_add(snac_metadata,
26+ xs_html_tag("span",
27+ xs_html_attr("class", "snac-property-name"),
28+ xs_html_raw("📍 Location")),
29+ xs_html_text(":"),
30+ xs_html_raw(" "),
31+ xs_html_tag("span",
32+ xs_html_attr("class", "snac-property-value p-adr"),
33+ xs_html_text(address)),
34+ xs_html_sctag("br", NULL));
35+
36+ count++;
37+ }
38+
39+ const xs_val *birthday = xs_dict_get(actor, "vcard:bday");
40+ if (xs_is_string(birthday)) {
41+ xs_html_add(snac_metadata,
42+ xs_html_tag("span",
43+ xs_html_attr("class", "snac-property-name"),
44+ xs_html_raw("🎂 Birthday")),
45+ xs_html_text(":"),
46+ xs_html_raw(" "),
47+ xs_html_tag("time",
48+ xs_html_attr("class", "snac-property-value dt-bday"),
49+ xs_html_text(birthday)),
50+ xs_html_sctag("br", NULL));
51+
52+ count++;
53+ }
54+
55+ const xs_list *attachment = xs_dict_get(actor, "attachment");
56+ if (count > 0 && xs_list_len(attachment) > 0) {
57+ xs_html_add(snac_metadata,
58+ xs_html_sctag("hr",
59+ xs_html_attr("class", "snac-property-divider")));
60+ }
61+
62+ const xs_val *v;
63+ xs_list_foreach(attachment, v) {
64+ const char *type = xs_dict_get(v, "type");
65+ const char *name = xs_dict_get(v, "name");
66+ const char *value = xs_dict_get(v, "value");
67+
68+ if (!xs_is_null(type) && !xs_is_null(name) &&
69+ !xs_is_null(value) && strcmp(type, "PropertyValue") == 0) {
70+ /* both the name and the value can contain emoji */
71+ xs *nam = sanitize(name);
72+ nam = replace_shortnames(nam, tag, 1, proxy);
73+
74+ /* todo: sometimes the value is transmitted as markdown and not html ._. */
75+ xs *val = sanitize(value);
76+ val = replace_shortnames(val, tag, 1, proxy);
77+
78+ /* delete <p> tags, because some software sends them */
79+ val = xs_replace_i(val, "<p>", "");
80+ val = xs_replace_i(val, "</p>", "");
81+
82+ xs_html_add(snac_metadata,
83+ xs_html_tag("span",
84+ xs_html_attr("class", "snac-property-name"),
85+ xs_html_raw(nam)),
86+ xs_html_text(":"),
87+ xs_html_raw(" "),
88+ xs_html_tag("span",
89+ xs_html_attr("class", "snac-property-value"),
90+ xs_html_raw(val)),
91+ xs_html_sctag("br", NULL));
92+
93+ count++;
94+ }
95+ }
96+
97+ if (count > 0) {
98+ xs_html_add(snac_post, snac_metadata);
99+ }
100+ else {
101+ /* free the html, by rendering it... */
102+ xs_free(xs_html_render(snac_metadata));
103+ }
104+
105 /* buttons */
106 xs *btn_form_action = xs_fmt("%s/admin/action", user->actor);
107