summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mastoapi.c46
1 files changed, 37 insertions, 9 deletions
diff --git a/mastoapi.c b/mastoapi.c
index dd80abc..eb5ea02 100644
--- a/mastoapi.c
+++ b/mastoapi.c
@@ -3258,12 +3258,16 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
3258 if (strcmp(cmd, "/v1/statuses") == 0) { /** **/ 3258 if (strcmp(cmd, "/v1/statuses") == 0) { /** **/
3259 if (logged_in) { 3259 if (logged_in) {
3260 /* post a new Note */ 3260 /* post a new Note */
3261 const char *content = xs_dict_get(args, "status"); 3261 const char *content = xs_dict_get(args, "status");
3262 const char *mid = xs_dict_get(args, "in_reply_to_id"); 3262 const char *mid = xs_dict_get(args, "in_reply_to_id");
3263 const char *visibility = xs_dict_get(args, "visibility"); 3263 const char *visibility = xs_dict_get(args, "visibility");
3264 const char *summary = xs_dict_get(args, "spoiler_text"); 3264 const char *summary = xs_dict_get(args, "spoiler_text");
3265 const char *media_ids = xs_dict_get(args, "media_ids"); 3265 const char *poll_opts = xs_dict_get(args, "poll[options][]");
3266 const char *language = xs_dict_get(args, "language"); 3266 const char *poll_end_secs = xs_dict_get(args, "poll[expires_in]");
3267 const char *poll_multiple = xs_dict_get(args, "poll[multiple]");
3268 // const char *poll_hide_totals = xs_dict_get(args, "poll[hide_totals]");
3269 const char *media_ids = xs_dict_get(args, "media_ids");
3270 const char *language = xs_dict_get(args, "language");
3267 3271
3268 if (xs_is_null(media_ids)) 3272 if (xs_is_null(media_ids))
3269 media_ids = xs_dict_get(args, "media_ids[]"); 3273 media_ids = xs_dict_get(args, "media_ids[]");
@@ -3286,8 +3290,8 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
3286 irt = xs_dup(xs_dict_get(r_msg, "id")); 3290 irt = xs_dup(xs_dict_get(r_msg, "id"));
3287 } 3291 }
3288 3292
3289 /* does it have attachments? */ 3293 /* does it have attachments (and no poll)? */
3290 if (!xs_is_null(media_ids)) { 3294 if (!xs_is_null(media_ids) && xs_is_null(poll_end_secs) && xs_is_null(poll_opts)) {
3291 xs *mi = NULL; 3295 xs *mi = NULL;
3292 3296
3293 if (xs_type(media_ids) == XSTYPE_LIST) 3297 if (xs_type(media_ids) == XSTYPE_LIST)
@@ -3313,6 +3317,8 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
3313 } 3317 }
3314 3318
3315 /* prepare the message */ 3319 /* prepare the message */
3320 xs *msg = NULL;
3321
3316 int scope = SCOPE_MENTIONED; 3322 int scope = SCOPE_MENTIONED;
3317 if (strcmp(visibility, "unlisted") == 0) 3323 if (strcmp(visibility, "unlisted") == 0)
3318 scope = SCOPE_UNLISTED; 3324 scope = SCOPE_UNLISTED;
@@ -3323,7 +3329,29 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
3323 if (strcmp(visibility, "private") == 0) 3329 if (strcmp(visibility, "private") == 0)
3324 scope = SCOPE_FOLLOWERS; 3330 scope = SCOPE_FOLLOWERS;
3325 3331
3326 xs *msg = msg_note(&snac, content, NULL, irt, attach_list, scope, language, NULL); 3332 /* does it have a poll? */
3333 if (!xs_is_null(poll_opts) && !xs_is_null(poll_end_secs)) {
3334 xs *po = NULL;
3335 int end_secs = atoi(poll_end_secs);
3336 int multiple = 0;
3337
3338 if (xs_type(poll_opts) == XSTYPE_LIST)
3339 po = xs_dup(poll_opts);
3340 else {
3341 po = xs_list_new();
3342 po = xs_list_append(po, poll_opts);
3343 }
3344
3345 if (!xs_is_null(poll_multiple) && strcmp(poll_multiple, "true") == 0)
3346 multiple = 1;
3347
3348 msg = msg_question(&snac, content, attach_list,
3349 poll_opts, multiple, end_secs);
3350
3351 enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs);
3352 }
3353 else
3354 msg = msg_note(&snac, content, NULL, irt, attach_list, scope, language, NULL);
3327 3355
3328 if (!xs_is_null(summary) && *summary) { 3356 if (!xs_is_null(summary) && *summary) {
3329 msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE)); 3357 msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE));