mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 13:25:04 +00:00
Minor refactoring to mastoapi_poll().
This commit is contained in:
parent
91ed98df0d
commit
182ba33c76
1 changed files with 41 additions and 47 deletions
18
mastoapi.c
18
mastoapi.c
|
@ -590,10 +590,7 @@ xs_dict *mastoapi_account(const xs_dict *actor)
|
||||||
xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
|
xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
|
||||||
/* creates a mastoapi Poll object */
|
/* creates a mastoapi Poll object */
|
||||||
{
|
{
|
||||||
xs_dict *poll = NULL;
|
xs_dict *poll = xs_dict_new();
|
||||||
|
|
||||||
/* is it a poll? */
|
|
||||||
if (strcmp(xs_dict_get(msg, "type"), "Question") == 0) {
|
|
||||||
xs *mid = mastoapi_id(msg);
|
xs *mid = mastoapi_id(msg);
|
||||||
xs *f = xs_val_new(XSTYPE_FALSE);
|
xs *f = xs_val_new(XSTYPE_FALSE);
|
||||||
xs *t = xs_val_new(XSTYPE_TRUE);
|
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;
|
int num_votes = 0;
|
||||||
xs *options = xs_list_new();
|
xs *options = xs_list_new();
|
||||||
|
|
||||||
poll = xs_dict_new();
|
|
||||||
|
|
||||||
poll = xs_dict_append(poll, "id", mid);
|
poll = xs_dict_append(poll, "id", mid);
|
||||||
poll = xs_dict_append(poll, "expires_at", xs_dict_get(msg, "endTime"));
|
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);
|
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",
|
poll = xs_dict_append(poll, "voted",
|
||||||
was_question_voted(snac, xs_dict_get(msg, "id")) ? t : f);
|
was_question_voted(snac, xs_dict_get(msg, "id")) ? t : f);
|
||||||
}
|
|
||||||
|
|
||||||
return poll;
|
return poll;
|
||||||
}
|
}
|
||||||
|
@ -655,6 +649,9 @@ xs_dict *mastoapi_status(snac *snac, const xs_dict *msg)
|
||||||
if (actor == NULL)
|
if (actor == NULL)
|
||||||
return 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 *acct = mastoapi_account(actor);
|
||||||
|
|
||||||
xs *f = xs_val_new(XSTYPE_FALSE);
|
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 *n = xs_val_new(XSTYPE_NULL);
|
||||||
xs *idx = NULL;
|
xs *idx = NULL;
|
||||||
xs *ixc = NULL;
|
xs *ixc = NULL;
|
||||||
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
char *id = xs_dict_get(msg, "id");
|
|
||||||
xs *mid = mastoapi_id(msg);
|
xs *mid = mastoapi_id(msg);
|
||||||
|
|
||||||
xs_dict *st = xs_dict_new();
|
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);
|
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);
|
xs *poll = mastoapi_poll(snac, msg);
|
||||||
|
|
||||||
if (poll)
|
|
||||||
st = xs_dict_append(st, "poll", poll);
|
st = xs_dict_append(st, "poll", poll);
|
||||||
|
}
|
||||||
|
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue