aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrunfink <grunfink@noreply.codeberg.org>2026-01-25 10:20:35 +0100
committergrunfink <grunfink@noreply.codeberg.org>2026-01-25 10:20:35 +0100
commitd30472f0d96bc9e2659db1cfe55ecf439796b989 (patch)
treeabef499186bdd8d84741f5979fb6964ff31cfc02
parent27ca16011e4945ddc0d3e113840ace1a589011e1 (diff)
parenta14cf4a7dbbf6ee90ef8ff4974e7fe9a023d6e48 (diff)
Merge pull request 'Configurable limits for polls' (#534) from dandelions/snac2:poll-limits into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/534
-rw-r--r--activitypub.c15
-rw-r--r--doc/snac.84
-rw-r--r--html.c15
3 files changed, 29 insertions, 5 deletions
diff --git a/activitypub.c b/activitypub.c
index c34e510..8eb7844 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -17,6 +17,7 @@
#include "snac.h"
+#include <stddef.h>
#include <sys/wait.h>
const char * const public_address = "https:/" "/www.w3.org/ns/activitystreams#Public";
@@ -2321,9 +2322,17 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
/* creates a Question message */
{
xs_dict *msg = msg_note(user, content, NULL, NULL, attach, 0, NULL, NULL);
- int max = 8;
+ const xs_number *max_options = xs_dict_get(srv_config, "max_poll_options");
+ const xs_number *max_length = xs_dict_get(srv_config, "max_poll_option_length");
xs_set seen;
+ size_t max_line = 60;
+ int max = 8;
+ if (xs_type(max_options) == XSTYPE_NUMBER)
+ max = xs_number_get(max_options);
+ if (xs_type(max_length) == XSTYPE_NUMBER)
+ max_line = xs_number_get(max_length);
+
msg = xs_dict_set(msg, "type", "Question");
/* make it non-editable */
@@ -2341,8 +2350,8 @@ xs_dict *msg_question(snac *user, const char *content, xs_list *attach,
xs *v2 = xs_dup(v);
xs *d = xs_dict_new();
- if (strlen(v2) > 60) {
- v2[60] = '\0';
+ if (strlen(v2) > max_line) {
+ v2[max_line] = '\0';
v2 = xs_str_cat(v2, "...");
}
diff --git a/doc/snac.8 b/doc/snac.8
index d961ed2..b5ec33c 100644
--- a/doc/snac.8
+++ b/doc/snac.8
@@ -269,6 +269,10 @@ The maximum number of entries (posts) to be returned in user RSS feeds and outbo
(default: 20).
.It Ic max_attachments
The maximum number of attachments per post (default: 4).
+.It Ic max_poll_options
+The maximum number of poll options in a poll (default: 8).
+.It Ic max_poll_option_length
+The maximum length of a single poll option (default: 60).
.It Ic enable_svg
Since version 2.73, SVG image attachments are hidden by default; you can enable
them by setting this value to true.
diff --git a/html.c b/html.c
index 93dba0a..436995b 100644
--- a/html.c
+++ b/html.c
@@ -778,13 +778,18 @@ xs_html *html_note(snac *user, const char *summary,
/* add poll controls */
if (poll) {
+ const xs_number *max_options = xs_dict_get(srv_config, "max_poll_options");
+ xs *poll_limit_str = xs_dup(L("Poll options (one per line, up to 8):"));
+ if (max_options != NULL)
+ poll_limit_str = xs_replace_i(poll_limit_str, "8", xs_number_str(max_options));
+
xs_html_add(form,
xs_html_tag("p", NULL),
xs_html_tag("details",
xs_html_tag("summary",
xs_html_text(L("Poll..."))),
xs_html_tag("p",
- xs_html_text(L("Poll options (one per line, up to 8):")),
+ xs_html_text(poll_limit_str),
xs_html_sctag("br", NULL),
xs_html_tag("textarea",
xs_html_attr("class", "snac-textarea"),
@@ -812,7 +817,13 @@ xs_html *html_note(snac *user, const char *summary,
xs_html_text(L("End in 1 hour"))),
xs_html_tag("option",
xs_html_attr("value", "86400"),
- xs_html_text(L("End in 1 day"))))));
+ xs_html_text(L("End in 1 day"))),
+ xs_html_tag("option",
+ xs_html_attr("value", "259200"),
+ xs_html_text(L("End in 3 days"))),
+ xs_html_tag("option",
+ xs_html_attr("value", "31536000"),
+ xs_html_text(L("End in 1 year"))))));
}
xs_html_add(form,