aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgrunfink <grunfink@noreply.codeberg.org>2026-02-07 17:02:16 +0100
committergrunfink <grunfink@noreply.codeberg.org>2026-02-07 17:02:16 +0100
commit655dd95177055682d7beb655af25575b69777cb1 (patch)
tree37a999197dee17a8ef61cbcbcdb7442af700c2af
parent313b72d3ace21627b7ddc9602004d5859b18d2ba (diff)
parent140247f1fd17b717c3b40afe6664c00931b981cf (diff)
Merge pull request 'Add poll creation to mastoapi' (#551) from davidrv00/snac2-fork:poll-mastoapi into master
Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/551
-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,
if (strcmp(cmd, "/v1/statuses") == 0) { /** **/
if (logged_in) {
/* post a new Note */
- const char *content = xs_dict_get(args, "status");
- const char *mid = xs_dict_get(args, "in_reply_to_id");
- const char *visibility = xs_dict_get(args, "visibility");
- const char *summary = xs_dict_get(args, "spoiler_text");
- const char *media_ids = xs_dict_get(args, "media_ids");
- const char *language = xs_dict_get(args, "language");
+ const char *content = xs_dict_get(args, "status");
+ const char *mid = xs_dict_get(args, "in_reply_to_id");
+ const char *visibility = xs_dict_get(args, "visibility");
+ const char *summary = xs_dict_get(args, "spoiler_text");
+ const char *poll_opts = xs_dict_get(args, "poll[options][]");
+ const char *poll_end_secs = xs_dict_get(args, "poll[expires_in]");
+ const char *poll_multiple = xs_dict_get(args, "poll[multiple]");
+ // const char *poll_hide_totals = xs_dict_get(args, "poll[hide_totals]");
+ const char *media_ids = xs_dict_get(args, "media_ids");
+ const char *language = xs_dict_get(args, "language");
if (xs_is_null(media_ids))
media_ids = xs_dict_get(args, "media_ids[]");
@@ -3286,8 +3290,8 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
irt = xs_dup(xs_dict_get(r_msg, "id"));
}
- /* does it have attachments? */
- if (!xs_is_null(media_ids)) {
+ /* does it have attachments (and no poll)? */
+ if (!xs_is_null(media_ids) && xs_is_null(poll_end_secs) && xs_is_null(poll_opts)) {
xs *mi = NULL;
if (xs_type(media_ids) == XSTYPE_LIST)
@@ -3313,6 +3317,8 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
}
/* prepare the message */
+ xs *msg = NULL;
+
int scope = SCOPE_MENTIONED;
if (strcmp(visibility, "unlisted") == 0)
scope = SCOPE_UNLISTED;
@@ -3323,7 +3329,29 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path,
if (strcmp(visibility, "private") == 0)
scope = SCOPE_FOLLOWERS;
- xs *msg = msg_note(&snac, content, NULL, irt, attach_list, scope, language, NULL);
+ /* does it have a poll? */
+ if (!xs_is_null(poll_opts) && !xs_is_null(poll_end_secs)) {
+ xs *po = NULL;
+ int end_secs = atoi(poll_end_secs);
+ int multiple = 0;
+
+ if (xs_type(poll_opts) == XSTYPE_LIST)
+ po = xs_dup(poll_opts);
+ else {
+ po = xs_list_new();
+ po = xs_list_append(po, poll_opts);
+ }
+
+ if (!xs_is_null(poll_multiple) && strcmp(poll_multiple, "true") == 0)
+ multiple = 1;
+
+ msg = msg_question(&snac, content, attach_list,
+ poll_opts, multiple, end_secs);
+
+ enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs);
+ }
+ else
+ msg = msg_note(&snac, content, NULL, irt, attach_list, scope, language, NULL);
if (!xs_is_null(summary) && *summary) {
msg = xs_dict_set(msg, "sensitive", xs_stock(XSTYPE_TRUE));