summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
authorGravatar default2023-11-28 20:50:49 +0100
committerGravatar default2023-11-28 20:50:49 +0100
commit89b796f941e2f219d4f73aad439e480762d0f5a8 (patch)
tree803e1107ca3db9d9bfae30bd2d72fbf4295088ae /html.c
parentxs_html() doesn't filter the top string, just returns the generated string. (diff)
downloadsnac2-89b796f941e2f219d4f73aad439e480762d0f5a8.tar.gz
snac2-89b796f941e2f219d4f73aad439e480762d0f5a8.tar.xz
snac2-89b796f941e2f219d4f73aad439e480762d0f5a8.zip
Blah blah blah html_entry() blah blah blah.
Diffstat (limited to 'html.c')
-rw-r--r--html.c107
1 files changed, 51 insertions, 56 deletions
diff --git a/html.c b/html.c
index 37dc5c7..e26b9cb 100644
--- a/html.c
+++ b/html.c
@@ -1436,7 +1436,6 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
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");
1438 char *actor; 1438 char *actor;
1439 int sensitive = 0;
1440 char *v; 1439 char *v;
1441 xs *boosts = NULL; 1440 xs *boosts = NULL;
1442 1441
@@ -1486,18 +1485,21 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
1486 && !valid_status(actor_get(actor, NULL))) 1485 && !valid_status(actor_get(actor, NULL)))
1487 return NULL; 1486 return NULL;
1488 1487
1489 xs_str *s = xs_str_new("<div>\n"); 1488 /** html_entry top tag **/
1489 xs_html *entry_top = xs_html_tag("div", NULL);
1490 1490
1491 { 1491 {
1492 xs *s1 = xs_fmt("<a name=\"%s_entry\"></a>\n", md5); 1492 xs *s1 = xs_fmt("%s_entry", md5);
1493 1493 xs_html_add(entry_top,
1494 s = xs_str_cat(s, s1); 1494 xs_html_tag("a",
1495 xs_html_attr("name", s1)));
1495 } 1496 }
1496 1497
1497 if (level == 0) 1498 xs_html *entry = xs_html_tag("div",
1498 s = xs_str_cat(s, "<div class=\"snac-post\">\n"); /** **/ 1499 xs_html_attr("class", level == 0 ? "snac-post" : "snac-child"));
1499 else 1500
1500 s = xs_str_cat(s, "<div class=\"snac-child\">\n"); /** **/ 1501 xs_html_add(entry_top,
1502 entry);
1501 1503
1502 /** post header **/ 1504 /** post header **/
1503 1505
@@ -1507,6 +1509,9 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
1507 score = xs_html_tag("div", 1509 score = xs_html_tag("div",
1508 xs_html_attr("class", "snac-score"))); 1510 xs_html_attr("class", "snac-score")));
1509 1511
1512 xs_html_add(entry,
1513 post_header);
1514
1510 if (user && is_pinned(user, id)) { 1515 if (user && is_pinned(user, id)) {
1511 /* add a pin emoji */ 1516 /* add a pin emoji */
1512 xs_html_add(score, 1517 xs_html_add(score,
@@ -1600,46 +1605,47 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
1600 xs_html_add(post_header, 1605 xs_html_add(post_header,
1601 html_msg_icon(msg)); 1606 html_msg_icon(msg));
1602 1607
1603 {
1604 xs *s1 = xs_html_render(post_header);
1605 s = xs_str_cat(s, s1);
1606 }
1607
1608 /** post content **/ 1608 /** post content **/
1609 1609
1610 s = xs_str_cat(s, "\n<div class=\"e-content snac-content\">\n"); /** **/ 1610 xs_html *snac_content_wrap = xs_html_tag("div",
1611 xs_html_attr("class", "e-content snac-content"));
1612
1613 xs_html_add(entry,
1614 snac_content_wrap);
1611 1615
1612 if (!xs_is_null(v = xs_dict_get(msg, "name"))) { 1616 if (!xs_is_null(v = xs_dict_get(msg, "name"))) {
1613 xs *es1 = encode_html(v); 1617 xs_html_add(snac_content_wrap,
1614 xs *s1 = xs_fmt("<h3 class=\"snac-entry-title\">%s</h3>\n", es1); 1618 xs_html_tag("h3",
1615 s = xs_str_cat(s, s1); 1619 xs_html_attr("class", "snac-entry-title"),
1620 xs_html_text(v)));
1616 } 1621 }
1617 1622
1623 xs_html *snac_content = NULL;
1624
1618 /* is it sensitive? */ 1625 /* is it sensitive? */
1619 if (user && xs_type(xs_dict_get(msg, "sensitive")) == XSTYPE_TRUE) { 1626 if (user && xs_type(xs_dict_get(msg, "sensitive")) == XSTYPE_TRUE) {
1620 if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0') 1627 if (xs_is_null(v = xs_dict_get(msg, "summary")) || *v == '\0')
1621 v = "..."; 1628 v = "...";
1629
1622 /* only show it when not in the public timeline and the config setting is "open" */ 1630 /* only show it when not in the public timeline and the config setting is "open" */
1623 char *cw = xs_dict_get(user->config, "cw"); 1631 char *cw = xs_dict_get(user->config, "cw");
1624 if (xs_is_null(cw) || local) 1632 if (xs_is_null(cw) || local)
1625 cw = ""; 1633 cw = "";
1626 xs *es1 = encode_html(v);
1627 xs *s1 = xs_fmt("<details %s><summary>%s [%s]</summary>\n", cw, es1, L("SENSITIVE CONTENT"));
1628 s = xs_str_cat(s, s1);
1629 sensitive = 1;
1630 }
1631 1634
1632#if 0 1635 snac_content = xs_html_tag("details",
1633 { 1636 xs_html_attr(cw, NULL),
1634 xs *md5 = xs_md5_hex(id, strlen(id)); 1637 xs_html_tag("summary",
1635 xs *s1 = xs_fmt("<p><code>%s</code></p>\n", md5); 1638 xs_html_text(v),
1636 s = xs_str_cat(s, s1); 1639 xs_html_text(L("[SENSITIVE CONTENT]"))));
1637 } 1640 }
1638#endif 1641 else
1642 snac_content = xs_html_tag("div", NULL);
1643
1644 xs_html_add(snac_content_wrap,
1645 snac_content);
1639 1646
1640 { 1647 {
1641 /** build the content string **/ 1648 /** build the content string **/
1642
1643 char *content = xs_dict_get(msg, "content"); 1649 char *content = xs_dict_get(msg, "content");
1644 1650
1645 xs *c = sanitize(xs_is_null(content) ? "" : content); 1651 xs *c = sanitize(xs_is_null(content) ? "" : content);
@@ -1695,7 +1701,8 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
1695 } 1701 }
1696 1702
1697 /* c contains sanitized HTML */ 1703 /* c contains sanitized HTML */
1698 s = xs_str_cat(s, c); 1704 xs_html_add(snac_content,
1705 xs_html_raw(c));
1699 } 1706 }
1700 1707
1701 if (strcmp(type, "Question") == 0) { /** question content **/ 1708 if (strcmp(type, "Question") == 0) { /** question content **/
@@ -1825,12 +1832,10 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
1825 } 1832 }
1826 } 1833 }
1827 1834
1828 xs *s1 = xs_html_render(poll); 1835 xs_html_add(snac_content_wrap,
1829 s = xs_str_cat(s, s1); 1836 poll);
1830 } 1837 }
1831 1838
1832 s = xs_str_cat(s, "\n");
1833
1834 /* add the attachments */ 1839 /* add the attachments */
1835 v = xs_dict_get(msg, "attachment"); 1840 v = xs_dict_get(msg, "attachment");
1836 1841
@@ -1858,6 +1863,9 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
1858 xs_html *content_attachments = xs_html_tag("div", 1863 xs_html *content_attachments = xs_html_tag("div",
1859 xs_html_attr("class", "snac-content-attachments")); 1864 xs_html_attr("class", "snac-content-attachments"));
1860 1865
1866 xs_html_add(snac_content_wrap,
1867 content_attachments);
1868
1861 xs_list *p = attach; 1869 xs_list *p = attach;
1862 1870
1863 while (xs_list_iter(&p, &v)) { 1871 while (xs_list_iter(&p, &v)) {
@@ -1946,11 +1954,6 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
1946 xs_html_text(url)))); 1954 xs_html_text(url))));
1947 } 1955 }
1948 } 1956 }
1949
1950 {
1951 xs *s1 = xs_html_render(content_attachments);
1952 s = xs_str_cat(s, s1);
1953 }
1954 } 1957 }
1955 1958
1956 /* has this message an audience (i.e., comes from a channel or community)? */ 1959 /* has this message an audience (i.e., comes from a channel or community)? */
@@ -1964,21 +1967,15 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
1964 xs_html_text(audience)), 1967 xs_html_text(audience)),
1965 xs_html_text(")")); 1968 xs_html_text(")"));
1966 1969
1967 xs *s1 = xs_html_render(au_tag); 1970 xs_html_add(snac_content_wrap,
1968 s = xs_str_cat(s, s1); 1971 au_tag);
1969 } 1972 }
1970 1973
1971 if (sensitive)
1972 s = xs_str_cat(s, "</details><p>\n");
1973
1974 s = xs_str_cat(s, "</div>\n");
1975
1976 /** controls **/ 1974 /** controls **/
1977 1975
1978 if (!local && user) { 1976 if (!local && user) {
1979 xs_html *h = html_entry_controls(user, msg, md5); 1977 xs_html_add(entry,
1980 xs *s1 = xs_html_render(h); 1978 html_entry_controls(user, msg, md5));
1981 s = xs_str_cat(s, s1);
1982 } 1979 }
1983 1980
1984 /** children **/ 1981 /** children **/
@@ -1992,6 +1989,9 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
1992 xs_html_tag("summary", 1989 xs_html_tag("summary",
1993 xs_html_text("..."))); 1990 xs_html_text("...")));
1994 1991
1992 xs_html_add(entry,
1993 ch_details);
1994
1995 xs_html *ch_container = xs_html_tag("div", 1995 xs_html *ch_container = xs_html_tag("div",
1996 xs_html_attr("class", level < 4 ? "snac-children" : "snac-children-too-deep")); 1996 xs_html_attr("class", level < 4 ? "snac-children" : "snac-children-too-deep"));
1997 1997
@@ -2033,15 +2033,10 @@ xs_str *html_entry(snac *user, xs_dict *msg, int local,
2033 2033
2034 left--; 2034 left--;
2035 } 2035 }
2036
2037 xs *s1 = xs_html_render(ch_details);
2038 s = xs_str_cat(s, s1);
2039 } 2036 }
2040 } 2037 }
2041 2038
2042 s = xs_str_cat(s, "</div>\n</div>\n"); 2039 return xs_html_render(entry_top);
2043
2044 return s;
2045} 2040}
2046 2041
2047 2042