From 42918d44a0931ddf58eff863c9e21e93f051f229 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 30 May 2023 10:34:46 +0200 Subject: [PATCH] Create polls from the web interface. --- html.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/html.c b/html.c index 8c5aac7..38cdfe6 100644 --- a/html.c +++ b/html.c @@ -1769,8 +1769,31 @@ int html_post_handler(const xs_dict *req, const char *q_path, xs *msg = NULL; xs *c_msg = NULL; xs *content_2 = xs_replace(content, "\r", ""); + xs *poll_opts = NULL; - msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv); + /* is there a valid set of poll options? */ + const char *v = xs_dict_get(p_vars, "poll_options"); + if (!xs_is_null(v) && *v) { + xs *v2 = xs_strip_i(xs_replace(v, "\r", "")); + + poll_opts = xs_split(v2, "\n"); + } + + if (!xs_is_null(poll_opts) && xs_list_len(poll_opts)) { + /* get the rest of poll configuration */ + const char *p_multiple = xs_dict_get(p_vars, "poll_multiple"); + const char *p_end_secs = xs_dict_get(p_vars, "poll_end_secs"); + + int end_secs = atoi(!xs_is_null(p_end_secs) ? p_end_secs : "60"); + int multiple = !xs_is_null(p_multiple); + + msg = msg_question(&snac, content_2, attach_list, + poll_opts, multiple, end_secs); + + enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs); + } + else + msg = msg_note(&snac, content_2, to, in_reply_to, attach_list, priv); if (sensitive != NULL) { xs *t = xs_val_new(XSTYPE_TRUE);