commit 34eb717

default  ·  2023-05-24 11:46:06 +0000 UTC
parent 9cdb53d
Fixed multiple choice polls.
1 files changed,  +23, -8
M html.c
M html.c
+23, -8
 1@@ -948,9 +948,9 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
 2                     const char *name = xs_dict_get(v, "name");
 3 
 4                     if (name) {
 5-                        /* FIXME: process anyOf (checkbox) correctly */
 6-                        xs *opt = xs_fmt("<input type=\"radio\""
 7+                        xs *opt = xs_fmt("<input type=\"%s\""
 8                                     " id=\"%s\" value=\"%s\" name=\"question\"> %s<br>\n",
 9+                                    !xs_is_null(oo) ? "radio" : "checkbox",
10                                     name, name, name);
11 
12                         s1 = xs_str_cat(s1, opt);
13@@ -1981,16 +1981,31 @@ int html_post_handler(const xs_dict *req, const char *q_path,
14         const char *opt   = xs_dict_get(p_vars, "question");
15         const char *actor = xs_dict_get(p_vars, "actor");
16 
17-        xs *msg = msg_note(&snac, "", actor, irt, NULL, 1);
18+        xs *ls = NULL;
19 
20-        /* set the option */
21-        msg = xs_dict_append(msg, "name", opt);
22+        /* multiple choices? */
23+        if (xs_type(opt) == XSTYPE_LIST)
24+            ls = xs_dup(opt);
25+        else {
26+            ls = xs_list_new();
27+            ls = xs_list_append(ls, opt);
28+        }
29 
30-        xs *c_msg = msg_create(&snac, msg);
31+        xs_list *p = ls;
32+        xs_str *v;
33+
34+        while (xs_list_iter(&p, &v)) {
35+            xs *msg = msg_note(&snac, "", actor, irt, NULL, 1);
36 
37-        enqueue_message(&snac, c_msg);
38+            /* set the option */
39+            msg = xs_dict_append(msg, "name", v);
40 
41-        timeline_add(&snac, xs_dict_get(msg, "id"), msg);
42+            xs *c_msg = msg_create(&snac, msg);
43+
44+            enqueue_message(&snac, c_msg);
45+
46+            timeline_add(&snac, xs_dict_get(msg, "id"), msg);
47+        }
48 
49         status = 303;
50     }