Sfoglia il codice sorgente

Merge pull request 'Configurable limits for polls' (#534) from dandelions/snac2:poll-limits into master

Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/534
grunfink 6 mesi fa
parent
commit
d30472f0d9
3 ha cambiato i file con 29 aggiunte e 5 eliminazioni
  1. 12 3
      activitypub.c
  2. 4 0
      doc/snac.8
  3. 13 2
      html.c

+ 12 - 3
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, "...");
             }
 

+ 4 - 0
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.

+ 13 - 2
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,