commit d30472f

grunfink  ·  2026-01-25 09:20:35 +0000 UTC
parents 27ca160, a14cf4a
Merge pull request 'Configurable limits for polls' (#534) from dandelions/snac2:poll-limits into master

Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/534
3 files changed,  +29, -5
M html.c
+12, -3
 1@@ -17,6 +17,7 @@
 2 
 3 #include "snac.h"
 4 
 5+#include <stddef.h>
 6 #include <sys/wait.h>
 7 
 8 const char * const public_address = "https:/" "/www.w3.org/ns/activitystreams#Public";
 9@@ -2321,9 +2322,17 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
10 /* creates a Question message */
11 {
12     xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0, NULL, NULL);
13-    int max      = 8;
14+    const xs_number *max_options = xs_dict_get(srv_config, "max_poll_options");
15+    const xs_number *max_length = xs_dict_get(srv_config, "max_poll_option_length");
16     xs_set seen;
17 
18+    size_t max_line = 60;
19+    int max = 8;
20+    if (xs_type(max_options) == XSTYPE_NUMBER)
21+        max = xs_number_get(max_options);
22+    if (xs_type(max_length) == XSTYPE_NUMBER)
23+        max_line = xs_number_get(max_length);
24+
25     msg = xs_dict_set(msg, "type", "Question");
26 
27     /* make it non-editable */
28@@ -2341,8 +2350,8 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
29             xs *v2 = xs_dup(v);
30             xs *d  = xs_dict_new();
31 
32-            if (strlen(v2) > 60) {
33-                v2[60] = '\0';
34+            if (strlen(v2) > max_line) {
35+                v2[max_line] = '\0';
36                 v2 = xs_str_cat(v2, "...");
37             }
38 
+4, -0
 1@@ -269,6 +269,10 @@ The maximum number of entries (posts) to be returned in user RSS feeds and outbo
 2 (default: 20).
 3 .It Ic max_attachments
 4 The maximum number of attachments per post (default: 4).
 5+.It Ic max_poll_options
 6+The maximum number of poll options in a poll (default: 8).
 7+.It Ic max_poll_option_length
 8+The maximum length of a single poll option (default: 60).
 9 .It Ic enable_svg
10 Since version 2.73, SVG image attachments are hidden by default; you can enable
11 them by setting this value to true.
M html.c
+13, -2
 1@@ -778,13 +778,18 @@ xs_html *html_note(snac *user, const char *summary,
 2 
 3     /* add poll controls */
 4     if (poll) {
 5+        const xs_number *max_options = xs_dict_get(srv_config, "max_poll_options");
 6+        xs *poll_limit_str = xs_dup(L("Poll options (one per line, up to 8):"));
 7+        if (max_options != NULL)
 8+            poll_limit_str = xs_replace_i(poll_limit_str, "8", xs_number_str(max_options));
 9+
10         xs_html_add(form,
11             xs_html_tag("p", NULL),
12             xs_html_tag("details",
13                 xs_html_tag("summary",
14                     xs_html_text(L("Poll..."))),
15                 xs_html_tag("p",
16-                    xs_html_text(L("Poll options (one per line, up to 8):")),
17+                    xs_html_text(poll_limit_str),
18                     xs_html_sctag("br", NULL),
19                     xs_html_tag("textarea",
20                         xs_html_attr("class",    "snac-textarea"),
21@@ -812,7 +817,13 @@ xs_html *html_note(snac *user, const char *summary,
22                         xs_html_text(L("End in 1 hour"))),
23                     xs_html_tag("option",
24                         xs_html_attr("value", "86400"),
25-                        xs_html_text(L("End in 1 day"))))));
26+                        xs_html_text(L("End in 1 day"))),
27+                    xs_html_tag("option",
28+                        xs_html_attr("value", "259200"),
29+                        xs_html_text(L("End in 3 days"))),
30+                    xs_html_tag("option",
31+                        xs_html_attr("value", "31536000"),
32+                        xs_html_text(L("End in 1 year"))))));
33     }
34 
35     xs_html_add(form,