commit 29010d6
default
·
2023-11-25 09:02:32 +0000 UTC
parent c71047c
html_entry_controls() is now pure xs_html.
1 files changed,
+64,
-55
M
html.c
M
html.c
+64,
-55
1@@ -1018,82 +1018,98 @@ xs_str *build_mentions(snac *snac, const xs_dict *msg)
2 }
3
4
5-xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const char *md5)
6+xs_html *html_entry_controls(snac *snac, const xs_dict *msg, const char *md5)
7 {
8- const char *id = xs_dict_get(msg, "id");
9- const char *actor = xs_dict_get(msg, "attributedTo");
10- const char *group = xs_dict_get(msg, "audience");
11+ char *id = xs_dict_get(msg, "id");
12+ char *actor = xs_dict_get(msg, "attributedTo");
13+ char *group = xs_dict_get(msg, "audience");
14
15 xs *likes = object_likes(id);
16 xs *boosts = object_announces(id);
17
18- xs *s = xs_str_new(NULL);
19-
20- s = xs_str_cat(s, "<div class=\"snac-controls\">\n");
21-
22- {
23- xs *s1 = xs_fmt(
24- "<form autocomplete=\"off\" method=\"post\" action=\"%s/admin/action\">\n"
25- "<input type=\"hidden\" name=\"id\" value=\"%s\">\n"
26- "<input type=\"hidden\" name=\"actor\" value=\"%s\">\n"
27- "<input type=\"hidden\" name=\"group\" value=\"%s\">\n"
28- "<input type=\"hidden\" name=\"redir\" value=\"%s_entry\">\n"
29- "\n",
30-
31- snac->actor, id, actor, group ? group : "", md5
32- );
33+ xs *action = xs_fmt("%s/admin/action", snac->actor);
34+ xs *redir = xs_fmt("%s_entry", md5);
35
36- s = xs_str_cat(s, s1);
37- }
38+ xs_html *form;
39+ xs_html *controls = xs_html_tag("div",
40+ xs_html_attr("class", "snac-controls"),
41+ form = xs_html_tag("form",
42+ xs_html_attr("autocomplete", "off"),
43+ xs_html_attr("method", "post"),
44+ xs_html_attr("action", action),
45+ xs_html_sctag("input",
46+ xs_html_attr("type", "hidden"),
47+ xs_html_attr("name", "id"),
48+ xs_html_attr("value", id)),
49+ xs_html_sctag("input",
50+ xs_html_attr("type", "hidden"),
51+ xs_html_attr("name", "actor"),
52+ xs_html_attr("value", actor)),
53+ xs_html_sctag("input",
54+ xs_html_attr("type", "hidden"),
55+ xs_html_attr("name", "group"),
56+ xs_html_attr("value", xs_is_null(group) ? "" : group)),
57+ xs_html_sctag("input",
58+ xs_html_attr("type", "hidden"),
59+ xs_html_attr("name", "redir"),
60+ xs_html_attr("value", redir))));
61
62 if (!xs_startswith(id, snac->actor)) {
63 if (xs_list_in(likes, snac->md5) == -1) {
64 /* not already liked; add button */
65- s = html_button(s, "like", L("Like"), L("Say you like this post"));
66+ xs_html_add(form,
67+ html_button_2("like", L("Like"), L("Say you like this post")));
68 }
69 }
70 else {
71 if (is_pinned(snac, id))
72- s = html_button(s, "unpin", L("Unpin"), L("Unpin this post from your timeline"));
73+ xs_html_add(form,
74+ html_button_2("unpin", L("Unpin"), L("Unpin this post from your timeline")));
75 else
76- s = html_button(s, "pin", L("Pin"), L("Pin this post to the top of your timeline"));
77+ xs_html_add(form,
78+ html_button_2("pin", L("Pin"), L("Pin this post to the top of your timeline")));
79 }
80
81 if (is_msg_public(msg)) {
82 if (strcmp(actor, snac->actor) == 0 || xs_list_in(boosts, snac->md5) == -1) {
83 /* not already boosted or us; add button */
84- s = html_button(s, "boost", L("Boost"), L("Announce this post to your followers"));
85+ xs_html_add(form,
86+ html_button_2("boost", L("Boost"), L("Announce this post to your followers")));
87 }
88 }
89
90 if (strcmp(actor, snac->actor) != 0) {
91 /* controls for other actors than this one */
92 if (following_check(snac, actor)) {
93- s = html_button(s, "unfollow", L("Unfollow"), L("Stop following this user's activity"));
94+ xs_html_add(form,
95+ html_button_2("unfollow", L("Unfollow"), L("Stop following this user's activity")));
96 }
97 else {
98- s = html_button(s, "follow", L("Follow"), L("Start following this user's activity"));
99+ xs_html_add(form,
100+ html_button_2("follow", L("Follow"), L("Start following this user's activity")));
101 }
102
103 if (!xs_is_null(group)) {
104 if (following_check(snac, group)) {
105- s = html_button(s, "unfollow", L("Unfollow Group"),
106- L("Stop following this group or channel"));
107+ xs_html_add(form,
108+ html_button_2("unfollow", L("Unfollow Group"),
109+ L("Stop following this group or channel")));
110 }
111 else {
112- s = html_button(s, "follow", L("Follow Group"),
113- L("Start following this group or channel"));
114+ xs_html_add(form,
115+ html_button_2("follow", L("Follow Group"),
116+ L("Start following this group or channel")));
117 }
118 }
119
120- s = html_button(s, "mute", L("MUTE"),
121- L("Block any activity from this user forever"));
122+ xs_html_add(form,
123+ html_button_2("mute", L("MUTE"),
124+ L("Block any activity from this user forever")));
125 }
126
127- s = html_button(s, "delete", L("Delete"), L("Delete this post"));
128- s = html_button(s, "hide", L("Hide"), L("Hide this post and its children"));
129-
130- s = xs_str_cat(s, "</form>\n");
131+ xs_html_add(form,
132+ html_button_2("delete", L("Delete"), L("Delete this post")),
133+ html_button_2("hide", L("Hide"), L("Hide this post and its children")));
134
135 char *prev_src = xs_dict_get(msg, "sourceContent");
136
137@@ -1103,18 +1119,14 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
138 xs *form_id = xs_fmt("%s_edit_form", md5);
139 xs *redir = xs_fmt("%s_entry", md5);
140
141- xs_html *h = xs_html_tag("p",
142+ xs_html_add(controls, xs_html_tag("p",
143 html_note(snac, L("Edit..."),
144 div_id, form_id,
145 "", prev_src,
146- (char *)id, NULL,
147+ id, NULL,
148 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
149 xs_stock_false, redir,
150- NULL, 0));
151-
152- xs *s1 = xs_html_render(h);
153-
154- s = xs_str_cat(s, s1);
155+ NULL, 0)));
156 }
157
158 { /** reply **/
159@@ -1124,23 +1136,17 @@ xs_str *html_entry_controls(snac *snac, xs_str *os, const xs_dict *msg, const ch
160 xs *form_id = xs_fmt("%s_reply_form", md5);
161 xs *redir = xs_fmt("%s_entry", md5);
162
163- xs_html *h = xs_html_tag("p",
164+ xs_html_add(controls, xs_html_tag("p",
165 html_note(snac, L("Reply..."),
166 div_id, form_id,
167 "", ct,
168 NULL, NULL,
169 xs_dict_get(msg, "sensitive"), xs_dict_get(msg, "summary"),
170 xs_stock_false, redir,
171- (char *)id, 0));
172-
173- xs *s1 = xs_html_render(h);
174-
175- s = xs_str_cat(s, s1);
176+ id, 0)));
177 }
178
179- s = xs_str_cat(s, "</div>\n");
180-
181- return xs_str_cat(os, s);
182+ return controls;
183 }
184
185
186@@ -1604,8 +1610,11 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local,
187
188 /** controls **/
189
190- if (!local && user)
191- s = html_entry_controls(user, s, msg, md5);
192+ if (!local && user) {
193+ xs_html *h = html_entry_controls(user, msg, md5);
194+ xs *s1 = xs_html_render(h);
195+ s = xs_str_cat(s, s1);
196+ }
197
198 /** children **/
199 if (!hide_children) {