commit 513d81c

default  ·  2023-06-01 06:40:08 +0000 UTC
parent 182ba33
Now you can vote from the mastoapi.
1 files changed,  +28, -2
+28, -2
 1@@ -2133,13 +2133,39 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
 2                 mid = MID_TO_MD5(mid);
 3 
 4                 if (valid_status(timeline_get_by_md5(&snac, mid, &msg))) {
 5+                    const char *id   = xs_dict_get(msg, "id");
 6+                    const char *atto = xs_dict_get(msg, "attributedTo");
 7+
 8+                    xs_list *opts = xs_dict_get(msg, "oneOf");
 9+                    if (opts == NULL)
10+                        opts = xs_dict_get(msg, "anyOf");
11+
12                     if (op == NULL) {
13                     }
14                     else
15                     if (strcmp(op, "votes") == 0) {
16-                        const char *opts = xs_dict_get(args, "choices[]");
17+                        xs_list *choices = xs_dict_get(args, "choices[]");
18+
19+                        if (xs_type(choices) == XSTYPE_LIST) {
20+                            xs_str *v;
21+
22+                            while (xs_list_iter(&choices, &v)) {
23+                                int io           = atoi(v);
24+                                const xs_dict *o = xs_list_get(opts, io);
25+
26+                                if (o) {
27+                                    const char *name = xs_dict_get(o, "name");
28+
29+                                    xs *msg = msg_note(&snac, "", atto, (char *)id, NULL, 1);
30+                                    msg = xs_dict_append(msg, "name", name);
31+
32+                                    xs *c_msg = msg_create(&snac, msg);
33+                                    enqueue_message(&snac, c_msg);
34+                                    timeline_add(&snac, xs_dict_get(msg, "id"), msg);
35+                                }
36+                            }
37 
38-                        if (xs_type(opts) == XSTYPE_LIST) {
39+                            out = mastoapi_poll(&snac, msg);
40                         }
41                     }
42                 }