commit a4a1990
byte
·
2025-10-25 14:21:42 +0000 UTC
parent 2dbd522
rendering visibility conditionally, with lesser reach if needed
1 files changed,
+32,
-40
M
html.c
M
html.c
+32,
-40
1@@ -398,6 +398,37 @@ xs_html *html_msg_icon(snac *user, const char *actor_id, const xs_dict *msg,
2 return actor_icon;
3 }
4
5+void html_note_render_visibility(snac* user, xs_html *form, const int scope)
6+{
7+ // scopes aren't sorted by value unfortunately, so simple math won't work to limit them. using map-like thing here
8+ static const int public_scopes[5] = {SCOPE_PUBLIC, SCOPE_UNLISTED, SCOPE_FOLLOWERS, SCOPE_MENTIONED, -1};
9+ static const int unlisted_scopes[4] = {SCOPE_UNLISTED, SCOPE_FOLLOWERS, SCOPE_MENTIONED, -1};
10+ static const int followers_scopes[3] = {SCOPE_FOLLOWERS, SCOPE_MENTIONED, -1};
11+ static const int mentioned_scopes[2] = {SCOPE_MENTIONED, -1};
12+ static const int * const scopes[4] = { public_scopes, mentioned_scopes, unlisted_scopes, followers_scopes};
13+ static const char * const scopes_tags[4] = { "public", "mentioned", "unlisted", "followers"};
14+ static const char * const scopes_names[4] = { "Public", "Direct Message", "Unlisted", "Followers-only"};
15+
16+ xs_html *paragraph = xs_html_tag("p", xs_html_text(L("Visibility: ")));
17+ const int* to_render = scopes[scope];
18+ for( int i = 0; to_render[i] != -1; i++ ){
19+ const int scope_i = to_render[i];
20+ const char* value = scopes_tags[scope_i];
21+ const char* name = scopes_names[scope_i];
22+ xs_html_add(paragraph,
23+ xs_html_tag("label",
24+ xs_html_sctag("input",
25+ xs_html_attr("type", "radio"),
26+ xs_html_attr("name", "visibility"),
27+ xs_html_attr("value", value),
28+ xs_html_attr(scope == scope_i ? "checked" : "", NULL)),
29+ xs_html_text(" "),
30+ xs_html_text(L(name)),
31+ xs_html_text(" "))
32+ );
33+ }
34+ xs_html_add(form, paragraph);
35+}
36
37 xs_html *html_note(snac *user, const char *summary,
38 const char *div_id, const char *form_id,
39@@ -455,46 +486,7 @@ xs_html *html_note(snac *user, const char *summary,
40 xs_html_attr("type", "hidden"),
41 xs_html_attr("name", "to"),
42 xs_html_attr("value", actor_id)));
43- else {
44- xs_html_add(form,
45- xs_html_tag("p",
46- xs_html_text(L("Visibility: ")),
47- xs_html_tag("label",
48- xs_html_sctag("input",
49- xs_html_attr("type", "radio"),
50- xs_html_attr("name", "visibility"),
51- xs_html_attr("value", "public"),
52- xs_html_attr(scope == SCOPE_PUBLIC ? "checked" : "", NULL)),
53- xs_html_text(" "),
54- xs_html_text(L("Public"))),
55- xs_html_text(" "),
56- xs_html_tag("label",
57- xs_html_sctag("input",
58- xs_html_attr("type", "radio"),
59- xs_html_attr("name", "visibility"),
60- xs_html_attr("value", "unlisted"),
61- xs_html_attr(scope == SCOPE_UNLISTED ? "checked" : "", NULL)),
62- xs_html_text(" "),
63- xs_html_text(L("Unlisted"))),
64- xs_html_text(" "),
65- xs_html_tag("label",
66- xs_html_sctag("input",
67- xs_html_attr("type", "radio"),
68- xs_html_attr("name", "visibility"),
69- xs_html_attr("value", "followers"),
70- xs_html_attr(scope == SCOPE_FOLLOWERS ? "checked" : "", NULL)),
71- xs_html_text(" "),
72- xs_html_text(L("Followers-only"))),
73- xs_html_text(" "),
74- xs_html_tag("label",
75- xs_html_sctag("input",
76- xs_html_attr("type", "radio"),
77- xs_html_attr("name", "visibility"),
78- xs_html_attr("value", "mentioned"),
79- xs_html_attr(scope == SCOPE_MENTIONED ? "checked" : "", NULL)),
80- xs_html_text(" "),
81- xs_html_text(L("Direct Message")))));
82- }
83+ html_note_render_visibility(user, form, scope);
84
85 if (redir)
86 xs_html_add(form,