diff options
| author | 2023-11-28 20:04:49 +0100 | |
|---|---|---|
| committer | 2023-11-28 20:04:49 +0100 | |
| commit | bd2540e23fd81dcd24237c4a89f8f6eb20819efa (patch) | |
| tree | a282cdd855828843d71487fe620fa84770b8eb70 | |
| parent | Children in html_entry() is (almost) xs_html. (diff) | |
| download | snac2-bd2540e23fd81dcd24237c4a89f8f6eb20819efa.tar.gz snac2-bd2540e23fd81dcd24237c4a89f8f6eb20819efa.tar.xz snac2-bd2540e23fd81dcd24237c4a89f8f6eb20819efa.zip | |
xs_html() doesn't filter the top string, just returns the generated string.
| -rw-r--r-- | html.c | 54 |
1 files changed, 29 insertions, 25 deletions
| @@ -1430,8 +1430,8 @@ xs_html *html_entry_controls(snac *snac, const xs_dict *msg, const char *md5) | |||
| 1430 | } | 1430 | } |
| 1431 | 1431 | ||
| 1432 | 1432 | ||
| 1433 | xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | 1433 | xs_str *html_entry(snac *user, xs_dict *msg, int local, |
| 1434 | int level, const char *md5, int hide_children) | 1434 | int level, char *md5, int hide_children) |
| 1435 | { | 1435 | { |
| 1436 | char *id = xs_dict_get(msg, "id"); | 1436 | char *id = xs_dict_get(msg, "id"); |
| 1437 | char *type = xs_dict_get(msg, "type"); | 1437 | char *type = xs_dict_get(msg, "type"); |
| @@ -1442,15 +1442,15 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | |||
| 1442 | 1442 | ||
| 1443 | /* do not show non-public messages in the public timeline */ | 1443 | /* do not show non-public messages in the public timeline */ |
| 1444 | if ((local || !user) && !is_msg_public(msg)) | 1444 | if ((local || !user) && !is_msg_public(msg)) |
| 1445 | return os; | 1445 | return NULL; |
| 1446 | 1446 | ||
| 1447 | /* hidden? do nothing more for this conversation */ | 1447 | /* hidden? do nothing more for this conversation */ |
| 1448 | if (user && is_hidden(user, id)) | 1448 | if (user && is_hidden(user, id)) |
| 1449 | return os; | 1449 | return NULL; |
| 1450 | 1450 | ||
| 1451 | /* avoid too deep nesting, as it may be a loop */ | 1451 | /* avoid too deep nesting, as it may be a loop */ |
| 1452 | if (level >= 256) | 1452 | if (level >= 256) |
| 1453 | return os; | 1453 | return NULL; |
| 1454 | 1454 | ||
| 1455 | if (strcmp(type, "Follow") == 0) { | 1455 | if (strcmp(type, "Follow") == 0) { |
| 1456 | xs_html *h = xs_html_tag("div", | 1456 | xs_html *h = xs_html_tag("div", |
| @@ -1462,32 +1462,31 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | |||
| 1462 | xs_html_text(L("follows you"))), | 1462 | xs_html_text(L("follows you"))), |
| 1463 | html_msg_icon(msg))); | 1463 | html_msg_icon(msg))); |
| 1464 | 1464 | ||
| 1465 | xs *s1 = xs_html_render(h); | 1465 | return xs_html_render(h); |
| 1466 | return xs_str_cat(os, s1); | ||
| 1467 | } | 1466 | } |
| 1468 | else | 1467 | else |
| 1469 | if (!xs_match(type, "Note|Question|Page|Article")) { | 1468 | if (!xs_match(type, "Note|Question|Page|Article")) { |
| 1470 | /* skip oddities */ | 1469 | /* skip oddities */ |
| 1471 | return os; | 1470 | return NULL; |
| 1472 | } | 1471 | } |
| 1473 | 1472 | ||
| 1474 | /* ignore notes with "name", as they are votes to Questions */ | 1473 | /* ignore notes with "name", as they are votes to Questions */ |
| 1475 | if (strcmp(type, "Note") == 0 && !xs_is_null(xs_dict_get(msg, "name"))) | 1474 | if (strcmp(type, "Note") == 0 && !xs_is_null(xs_dict_get(msg, "name"))) |
| 1476 | return os; | 1475 | return NULL; |
| 1477 | 1476 | ||
| 1478 | /* bring the main actor */ | 1477 | /* bring the main actor */ |
| 1479 | if ((actor = xs_dict_get(msg, "attributedTo")) == NULL) | 1478 | if ((actor = xs_dict_get(msg, "attributedTo")) == NULL) |
| 1480 | return os; | 1479 | return NULL; |
| 1481 | 1480 | ||
| 1482 | /* ignore muted morons immediately */ | 1481 | /* ignore muted morons immediately */ |
| 1483 | if (user && is_muted(user, actor)) | 1482 | if (user && is_muted(user, actor)) |
| 1484 | return os; | 1483 | return NULL; |
| 1485 | 1484 | ||
| 1486 | if ((user == NULL || strcmp(actor, user->actor) != 0) | 1485 | if ((user == NULL || strcmp(actor, user->actor) != 0) |
| 1487 | && !valid_status(actor_get(actor, NULL))) | 1486 | && !valid_status(actor_get(actor, NULL))) |
| 1488 | return os; | 1487 | return NULL; |
| 1489 | 1488 | ||
| 1490 | xs *s = xs_str_new("<div>\n"); | 1489 | xs_str *s = xs_str_new("<div>\n"); |
| 1491 | 1490 | ||
| 1492 | { | 1491 | { |
| 1493 | xs *s1 = xs_fmt("<a name=\"%s_entry\"></a>\n", md5); | 1492 | xs *s1 = xs_fmt("<a name=\"%s_entry\"></a>\n", md5); |
| @@ -2018,15 +2017,16 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | |||
| 2018 | object_get_by_md5(cmd5, &chd); | 2017 | object_get_by_md5(cmd5, &chd); |
| 2019 | 2018 | ||
| 2020 | if (chd != NULL && xs_is_null(xs_dict_get(chd, "name"))) { | 2019 | if (chd != NULL && xs_is_null(xs_dict_get(chd, "name"))) { |
| 2021 | xs *s1 = xs_str_new(NULL); | 2020 | xs *s1 = html_entry(user, chd, local, level + 1, cmd5, hide_children); |
| 2022 | s1 = html_entry(user, s1, chd, local, level + 1, cmd5, hide_children); | 2021 | |
| 2023 | 2022 | if (s1 != NULL) { | |
| 2024 | if (left > 3) | 2023 | if (left > 3) |
| 2025 | xs_html_add(ch_older, | 2024 | xs_html_add(ch_older, |
| 2026 | xs_html_raw(s1)); | 2025 | xs_html_raw(s1)); |
| 2027 | else | 2026 | else |
| 2028 | xs_html_add(ch_container, | 2027 | xs_html_add(ch_container, |
| 2029 | xs_html_raw(s1)); | 2028 | xs_html_raw(s1)); |
| 2029 | } | ||
| 2030 | } | 2030 | } |
| 2031 | else | 2031 | else |
| 2032 | srv_debug(2, xs_fmt("cannot read child %s", cmd5)); | 2032 | srv_debug(2, xs_fmt("cannot read child %s", cmd5)); |
| @@ -2041,7 +2041,7 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | |||
| 2041 | 2041 | ||
| 2042 | s = xs_str_cat(s, "</div>\n</div>\n"); | 2042 | s = xs_str_cat(s, "</div>\n</div>\n"); |
| 2043 | 2043 | ||
| 2044 | return xs_str_cat(os, s); | 2044 | return s; |
| 2045 | } | 2045 | } |
| 2046 | 2046 | ||
| 2047 | 2047 | ||
| @@ -2116,7 +2116,8 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local, | |||
| 2116 | continue; | 2116 | continue; |
| 2117 | } | 2117 | } |
| 2118 | 2118 | ||
| 2119 | s = html_entry(user, s, msg, local, 0, v, user ? 0 : 1); | 2119 | xs *s1 = html_entry(user, msg, local, 0, v, user ? 0 : 1); |
| 2120 | s = xs_str_cat(s, s1); | ||
| 2120 | } | 2121 | } |
| 2121 | 2122 | ||
| 2122 | s = xs_str_cat(s, "</div>\n"); | 2123 | s = xs_str_cat(s, "</div>\n"); |
| @@ -2439,7 +2440,10 @@ xs_str *html_notifications(snac *snac) | |||
| 2439 | else { | 2440 | else { |
| 2440 | xs *md5 = xs_md5_hex(id, strlen(id)); | 2441 | xs *md5 = xs_md5_hex(id, strlen(id)); |
| 2441 | 2442 | ||
| 2442 | s = html_entry(snac, s, obj, 0, 0, md5, 1); | 2443 | xs *s1 = html_entry(snac, obj, 0, 0, md5, 1); |
| 2444 | |||
| 2445 | if (s1 != NULL) | ||
| 2446 | s = xs_str_cat(s, s1); | ||
| 2443 | } | 2447 | } |
| 2444 | 2448 | ||
| 2445 | s = xs_str_cat(s, "</div>\n"); | 2449 | s = xs_str_cat(s, "</div>\n"); |