commit 42918d4

default  ·  2023-05-30 08:34:46 +0000 UTC
parent 142b4d6
Create polls from the web interface.
1 files changed,  +24, -1
M html.c
M html.c
+24, -1
 1@@ -1769,8 +1769,31 @@ int html_post_handler(const xs_dict *req, const char *q_path,
 2             xs *msg       = NULL;
 3             xs *c_msg     = NULL;
 4             xs *content_2 = xs_replace(content, "\r", "");
 5+            xs *poll_opts = NULL;
 6 
 7-            msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv);
 8+            /* is there a valid set of poll options? */
 9+            const char *v = xs_dict_get(p_vars, "poll_options");
10+            if (!xs_is_null(v) && *v) {
11+                xs *v2 = xs_strip_i(xs_replace(v, "\r", ""));
12+
13+                poll_opts = xs_split(v2, "\n");
14+            }
15+
16+            if (!xs_is_null(poll_opts) && xs_list_len(poll_opts)) {
17+                /* get the rest of poll configuration */
18+                const char *p_multiple = xs_dict_get(p_vars, "poll_multiple");
19+                const char *p_end_secs = xs_dict_get(p_vars, "poll_end_secs");
20+
21+                int end_secs = atoi(!xs_is_null(p_end_secs) ? p_end_secs : "60");
22+                int multiple = !xs_is_null(p_multiple);
23+
24+                msg = msg_question(&snac, content_2, attach_list,
25+                                   poll_opts, multiple, end_secs);
26+
27+                enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs);
28+            }
29+            else
30+                msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv);
31 
32             if (sensitive != NULL) {
33                 xs *t = xs_val_new(XSTYPE_TRUE);