Minor refactoring to mastoapi_poll().

This commit is contained in:
default 2023-06-01 08:13:58 +02:00
parent 91ed98df0d
commit 182ba33c76

View file

@ -590,10 +590,7 @@ xs_dict *mastoapi_account(const xs_dict *actor)
xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
/* creates a mastoapi Poll object */
{
xs_dict *poll = NULL;
/* is it a poll? */
if (strcmp(xs_dict_get(msg, "type"), "Question") == 0) {
xs_dict *poll = xs_dict_new();
xs *mid = mastoapi_id(msg);
xs *f = xs_val_new(XSTYPE_FALSE);
xs *t = xs_val_new(XSTYPE_TRUE);
@ -602,8 +599,6 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
int num_votes = 0;
xs *options = xs_list_new();
poll = xs_dict_new();
poll = xs_dict_append(poll, "id", mid);
poll = xs_dict_append(poll, "expires_at", xs_dict_get(msg, "endTime"));
poll = xs_dict_append(poll, "expired", xs_dict_get(msg, "closed") != NULL ? t : f);
@ -639,7 +634,6 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
poll = xs_dict_append(poll, "voted",
was_question_voted(snac, xs_dict_get(msg, "id")) ? t : f);
}
return poll;
}
@ -655,6 +649,9 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
if (actor == NULL)
return NULL;
const char *type = xs_dict_get(msg, "type");
const char *id = xs_dict_get(msg, "id");
xs *acct = mastoapi_account(actor);
xs *f = xs_val_new(XSTYPE_FALSE);
@ -662,9 +659,7 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
xs *n = xs_val_new(XSTYPE_NULL);
xs *idx = NULL;
xs *ixc = NULL;
char *tmp;
char *id = xs_dict_get(msg, "id");
xs *mid = mastoapi_id(msg);
xs_dict *st = xs_dict_new();
@ -861,11 +856,10 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
st = xs_dict_append(st, "edited_at", tmp);
/* build the poll object, if applicable */
if (strcmp(type, "Question") == 0) {
xs *poll = mastoapi_poll(snac, msg);
if (poll)
st = xs_dict_append(st, "poll", poll);
}
return st;
}