summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-06-01 08:40:08 +0200
committerGravatar default2023-06-01 08:40:08 +0200
commit513d81c694e6310900edb8ac05a7424acc3b2db6 (patch)
tree2a47abc465c427192e9c025bf2157ae02ea6f448
parentMinor refactoring to mastoapi_poll(). (diff)
downloadsnac2-513d81c694e6310900edb8ac05a7424acc3b2db6.tar.gz
snac2-513d81c694e6310900edb8ac05a7424acc3b2db6.tar.xz
snac2-513d81c694e6310900edb8ac05a7424acc3b2db6.zip
Now you can vote from the mastoapi.
-rw-r--r--mastoapi.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/mastoapi.c b/mastoapi.c
index 4985162..f30971e 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -2133,13 +2133,39 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
2133 mid = MID_TO_MD5(mid); 2133 mid = MID_TO_MD5(mid);
2134 2134
2135 if (valid_status(timeline_get_by_md5(&snac, mid, &msg))) { 2135 if (valid_status(timeline_get_by_md5(&snac, mid, &msg))) {
2136 const char *id = xs_dict_get(msg, "id");
2137 const char *atto = xs_dict_get(msg, "attributedTo");
2138
2139 xs_list *opts = xs_dict_get(msg, "oneOf");
2140 if (opts == NULL)
2141 opts = xs_dict_get(msg, "anyOf");
2142
2136 if (op == NULL) { 2143 if (op == NULL) {
2137 } 2144 }
2138 else 2145 else
2139 if (strcmp(op, "votes") == 0) { 2146 if (strcmp(op, "votes") == 0) {
2140 const char *opts = xs_dict_get(args, "choices[]"); 2147 xs_list *choices = xs_dict_get(args, "choices[]");
2148
2149 if (xs_type(choices) == XSTYPE_LIST) {
2150 xs_str *v;
2151
2152 while (xs_list_iter(&choices, &v)) {
2153 int io = atoi(v);
2154 const xs_dict *o = xs_list_get(opts, io);
2155
2156 if (o) {
2157 const char *name = xs_dict_get(o, "name");
2158
2159 xs *msg = msg_note(&snac, "", atto, (char *)id, NULL, 1);
2160 msg = xs_dict_append(msg, "name", name);
2161
2162 xs *c_msg = msg_create(&snac, msg);
2163 enqueue_message(&snac, c_msg);
2164 timeline_add(&snac, xs_dict_get(msg, "id"), msg);
2165 }
2166 }
2141 2167
2142 if (xs_type(opts) == XSTYPE_LIST) { 2168 out = mastoapi_poll(&snac, msg);
2143 } 2169 }
2144 } 2170 }
2145 } 2171 }