diff options
author | default <nobody@localhost> | 2023-06-01 08:40:08 +0200 |
---|---|---|
committer | default <nobody@localhost> | 2023-06-01 08:40:08 +0200 |
commit | 513d81c694e6310900edb8ac05a7424acc3b2db6 (patch) | |
tree | 2a47abc465c427192e9c025bf2157ae02ea6f448 | |
parent | 182ba33c76f34ecd092978246aa58be48742a61b (diff) |
Now you can vote from the mastoapi.
-rw-r--r-- | mastoapi.c | 30 |
1 files changed, 28 insertions, 2 deletions
@@ -2133,13 +2133,39 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, mid = MID_TO_MD5(mid); if (valid_status(timeline_get_by_md5(&snac, mid, &msg))) { + const char *id = xs_dict_get(msg, "id"); + const char *atto = xs_dict_get(msg, "attributedTo"); + + xs_list *opts = xs_dict_get(msg, "oneOf"); + if (opts == NULL) + opts = xs_dict_get(msg, "anyOf"); + if (op == NULL) { } else if (strcmp(op, "votes") == 0) { - const char *opts = xs_dict_get(args, "choices[]"); + xs_list *choices = xs_dict_get(args, "choices[]"); + + if (xs_type(choices) == XSTYPE_LIST) { + xs_str *v; + + while (xs_list_iter(&choices, &v)) { + int io = atoi(v); + const xs_dict *o = xs_list_get(opts, io); + + if (o) { + const char *name = xs_dict_get(o, "name"); + + xs *msg = msg_note(&snac, "", atto, (char *)id, NULL, 1); + msg = xs_dict_append(msg, "name", name); + + xs *c_msg = msg_create(&snac, msg); + enqueue_message(&snac, c_msg); + timeline_add(&snac, xs_dict_get(msg, "id"), msg); + } + } - if (xs_type(opts) == XSTYPE_LIST) { + out = mastoapi_poll(&snac, msg); } } } |