diff options
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 64 |
1 files changed, 40 insertions, 24 deletions
| @@ -3693,41 +3693,57 @@ int mastoapi_post_handler(const xs_dict *req, const char *q_path, | |||
| 3693 | if (found) { | 3693 | if (found) { |
| 3694 | const char *id = xs_dict_get(msg, "id"); | 3694 | const char *id = xs_dict_get(msg, "id"); |
| 3695 | const char *atto = get_atto(msg); | 3695 | const char *atto = get_atto(msg); |
| 3696 | int closed = 0; | ||
| 3697 | const char *f_closed = NULL; | ||
| 3696 | 3698 | ||
| 3697 | const xs_list *opts = xs_dict_get(msg, "oneOf"); | 3699 | if ((f_closed = xs_dict_get(msg, "closed")) != NULL) { |
| 3698 | if (opts == NULL) | 3700 | /* it has a closed date... but is it in the past? */ |
| 3699 | opts = xs_dict_get(msg, "anyOf"); | 3701 | time_t t0 = time(NULL); |
| 3702 | time_t t1 = xs_parse_iso_date(f_closed, 0); | ||
| 3700 | 3703 | ||
| 3701 | if (op == NULL) { | 3704 | if (t1 < t0) |
| 3705 | closed = 1; | ||
| 3702 | } | 3706 | } |
| 3703 | else | ||
| 3704 | if (strcmp(op, "votes") == 0) { | ||
| 3705 | const xs_list *choices = xs_dict_get(args, "choices[]"); | ||
| 3706 | 3707 | ||
| 3707 | if (xs_is_null(choices)) | 3708 | if (closed || was_question_voted(&snac, id)) |
| 3708 | choices = xs_dict_get(args, "choices"); | 3709 | status = HTTP_STATUS_UNPROCESSABLE_CONTENT; |
| 3710 | else { | ||
| 3711 | const xs_list *opts = xs_dict_get(msg, "oneOf"); | ||
| 3712 | if (opts == NULL) | ||
| 3713 | opts = xs_dict_get(msg, "anyOf"); | ||
| 3714 | |||
| 3715 | if (op == NULL) { | ||
| 3716 | } | ||
| 3717 | else { | ||
| 3718 | if (strcmp(op, "votes") == 0) { | ||
| 3719 | const xs_list *choices = xs_dict_get(args, "choices[]"); | ||
| 3709 | 3720 | ||
| 3710 | if (xs_type(choices) == XSTYPE_LIST) { | 3721 | if (xs_is_null(choices)) |
| 3711 | const xs_str *v; | 3722 | choices = xs_dict_get(args, "choices"); |
| 3712 | 3723 | ||
| 3713 | int c = 0; | 3724 | if (xs_type(choices) == XSTYPE_LIST) { |
| 3714 | while (xs_list_next(choices, &v, &c)) { | 3725 | const xs_str *v; |
| 3715 | int io = atoi(v); | ||
| 3716 | const xs_dict *o = xs_list_get(opts, io); | ||
| 3717 | 3726 | ||
| 3718 | if (o) { | 3727 | int c = 0; |
| 3719 | const char *name = xs_dict_get(o, "name"); | 3728 | while (xs_list_next(choices, &v, &c)) { |
| 3729 | int io = atoi(v); | ||
| 3730 | const xs_dict *o = xs_list_get(opts, io); | ||
| 3720 | 3731 | ||
| 3721 | xs *msg = msg_note(&snac, "", atto, (char *)id, NULL, 1, NULL, NULL); | 3732 | if (o) { |
| 3722 | msg = xs_dict_append(msg, "name", name); | 3733 | const char *name = xs_dict_get(o, "name"); |
| 3723 | 3734 | ||
| 3724 | xs *c_msg = msg_create(&snac, msg); | 3735 | xs *msg = msg_note(&snac, "", atto, (char *)id, NULL, 1, NULL, NULL); |
| 3725 | enqueue_message(&snac, c_msg); | 3736 | msg = xs_dict_append(msg, "name", name); |
| 3726 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); | 3737 | |
| 3738 | xs *c_msg = msg_create(&snac, msg); | ||
| 3739 | enqueue_message(&snac, c_msg); | ||
| 3740 | timeline_add(&snac, xs_dict_get(msg, "id"), msg); | ||
| 3741 | } | ||
| 3742 | } | ||
| 3743 | |||
| 3744 | out = mastoapi_poll(&snac, msg); | ||
| 3727 | } | 3745 | } |
| 3728 | } | 3746 | } |
| 3729 | |||
| 3730 | out = mastoapi_poll(&snac, msg); | ||
| 3731 | } | 3747 | } |
| 3732 | } | 3748 | } |
| 3733 | } | 3749 | } |