html_entry_controls() is now pure xs_html.

This commit is contained in:
default 2023-11-25 10:02:32 +01:00
parent c71047ca02
commit 29010d6fbc

119
html.c
View file

@ -1018,82 +1018,98 @@ xs_str *build_mentions(snac *snac, const xs_dict *msg)
} }
xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const char *md5) xs_html *html_entry_controls(snac *snac, const xs_dict *msg, const char *md5)
{ {
const char *id = xs_dict_get(msg, "id"); char *id = xs_dict_get(msg, "id");
const char *actor = xs_dict_get(msg, "attributedTo"); char *actor = xs_dict_get(msg, "attributedTo");
const char *group = xs_dict_get(msg, "audience"); char *group = xs_dict_get(msg, "audience");
xs *likes = object_likes(id); xs *likes = object_likes(id);
xs *boosts = object_announces(id); xs *boosts = object_announces(id);
xs *s = xs_str_new(NULL); xs *action = xs_fmt("%s/admin/action", snac->actor);
xs *redir = xs_fmt("%s_entry", md5);
s = xs_str_cat(s, "<div class=\"snac-controls\">\n"); xs_html *form;
xs_html *controls = xs_html_tag("div",
{ xs_html_attr("class", "snac-controls"),
xs *s1 = xs_fmt( form = xs_html_tag("form",
"<form autocomplete=\"off\" method=\"post\" action=\"%s/admin/action\">\n" xs_html_attr("autocomplete", "off"),
"<input type=\"hidden\" name=\"id\" value=\"%s\">\n" xs_html_attr("method", "post"),
"<input type=\"hidden\" name=\"actor\" value=\"%s\">\n" xs_html_attr("action", action),
"<input type=\"hidden\" name=\"group\" value=\"%s\">\n" xs_html_sctag("input",
"<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n" xs_html_attr("type", "hidden"),
"\n", xs_html_attr("name", "id"),
xs_html_attr("value", id)),
snac->actor, id, actor, group ? group : "", md5 xs_html_sctag("input",
); xs_html_attr("type", "hidden"),
xs_html_attr("name", "actor"),
s = xs_str_cat(s, s1); xs_html_attr("value", actor)),
} xs_html_sctag("input",
xs_html_attr("type", "hidden"),
xs_html_attr("name", "group"),
xs_html_attr("value", xs_is_null(group) ? "" : group)),
xs_html_sctag("input",
xs_html_attr("type", "hidden"),
xs_html_attr("name", "redir"),
xs_html_attr("value", redir))));
if (!xs_startswith(id, snac->actor)) { if (!xs_startswith(id, snac->actor)) {
if (xs_list_in(likes, snac->md5) == -1) { if (xs_list_in(likes, snac->md5) == -1) {
/* not already liked; add button */ /* not already liked; add button */
s = html_button(s, "like", L("Like"), L("Say you like this post")); xs_html_add(form,
html_button_2("like", L("Like"), L("Say you like this post")));
} }
} }
else { else {
if (is_pinned(snac, id)) if (is_pinned(snac, id))
s = html_button(s, "unpin", L("Unpin"), L("Unpin this post from your timeline")); xs_html_add(form,
html_button_2("unpin", L("Unpin"), L("Unpin this post from your timeline")));
else else
s = html_button(s, "pin", L("Pin"), L("Pin this post to the top of your timeline")); xs_html_add(form,
html_button_2("pin", L("Pin"), L("Pin this post to the top of your timeline")));
} }
if (is_msg_public(msg)) { if (is_msg_public(msg)) {
if (strcmp(actor, snac->actor) == 0 || xs_list_in(boosts, snac->md5) == -1) { if (strcmp(actor, snac->actor) == 0 || xs_list_in(boosts, snac->md5) == -1) {
/* not already boosted or us; add button */ /* not already boosted or us; add button */
s = html_button(s, "boost", L("Boost"), L("Announce this post to your followers")); xs_html_add(form,
html_button_2("boost", L("Boost"), L("Announce this post to your followers")));
} }
} }
if (strcmp(actor, snac->actor) != 0) { if (strcmp(actor, snac->actor) != 0) {
/* controls for other actors than this one */ /* controls for other actors than this one */
if (following_check(snac, actor)) { if (following_check(snac, actor)) {
s = html_button(s, "unfollow", L("Unfollow"), L("Stop following this user's activity")); xs_html_add(form,
html_button_2("unfollow", L("Unfollow"), L("Stop following this user's activity")));
} }
else { else {
s = html_button(s, "follow", L("Follow"), L("Start following this user's activity")); xs_html_add(form,
html_button_2("follow", L("Follow"), L("Start following this user's activity")));
} }
if (!xs_is_null(group)) { if (!xs_is_null(group)) {
if (following_check(snac, group)) { if (following_check(snac, group)) {
s = html_button(s, "unfollow", L("Unfollow Group"), xs_html_add(form,
L("Stop following this group or channel")); html_button_2("unfollow", L("Unfollow Group"),
L("Stop following this group or channel")));
} }
else { else {
s = html_button(s, "follow", L("Follow Group"), xs_html_add(form,
L("Start following this group or channel")); html_button_2("follow", L("Follow Group"),
L("Start following this group or channel")));
} }
} }
s = html_button(s, "mute", L("MUTE"), xs_html_add(form,
L("Block any activity from this user forever")); html_button_2("mute", L("MUTE"),
L("Block any activity from this user forever")));
} }
s = html_button(s, "delete", L("Delete"), L("Delete this post")); xs_html_add(form,
s = html_button(s, "hide", L("Hide"), L("Hide this post and its children")); html_button_2("delete", L("Delete"), L("Delete this post")),
html_button_2("hide", L("Hide"), L("Hide this post and its children")));
s = xs_str_cat(s, "</form>\n");
char *prev_src = xs_dict_get(msg, "sourceContent"); char *prev_src = xs_dict_get(msg, "sourceContent");
@ -1103,18 +1119,14 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
xs *form_id = xs_fmt("%s_edit_form", md5); xs *form_id = xs_fmt("%s_edit_form", md5);
xs *redir = xs_fmt("%s_entry", md5); xs *redir = xs_fmt("%s_entry", md5);
xs_html *h = xs_html_tag("p", xs_html_add(controls, xs_html_tag("p",
html_note(snac, L("Edit..."), html_note(snac, L("Edit..."),
div_id, form_id, div_id, form_id,
"", prev_src, "", prev_src,
(char *)id, NULL, id, NULL,
xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"), xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
xs_stock_false, redir, xs_stock_false, redir,
NULL, 0)); NULL, 0)));
xs *s1 = xs_html_render(h);
s = xs_str_cat(s, s1);
} }
{ /** reply **/ { /** reply **/
@ -1124,23 +1136,17 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
xs *form_id = xs_fmt("%s_reply_form", md5); xs *form_id = xs_fmt("%s_reply_form", md5);
xs *redir = xs_fmt("%s_entry", md5); xs *redir = xs_fmt("%s_entry", md5);
xs_html *h = xs_html_tag("p", xs_html_add(controls, xs_html_tag("p",
html_note(snac, L("Reply..."), html_note(snac, L("Reply..."),
div_id, form_id, div_id, form_id,
"", ct, "", ct,
NULL, NULL, NULL, NULL,
xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"), xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
xs_stock_false, redir, xs_stock_false, redir,
(char *)id, 0)); id, 0)));
xs *s1 = xs_html_render(h);
s = xs_str_cat(s, s1);
} }
s = xs_str_cat(s, "</div>\n"); return controls;
return xs_str_cat(os, s);
} }
@ -1604,8 +1610,11 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local,
/** controls **/ /** controls **/
if (!local && user) if (!local && user) {
s = html_entry_controls(user, s, msg, md5); xs_html *h = html_entry_controls(user, msg, md5);
xs *s1 = xs_html_render(h);
s = xs_str_cat(s, s1);
}
/** children **/ /** children **/
if (!hide_children) { if (!hide_children) {