mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-09 19:50:26 +03:00
New function was_question_voted().
This commit is contained in:
parent
796a111de8
commit
3b72b0f0ac
24
data.c
24
data.c
@ -1935,6 +1935,30 @@ void enqueue_close_question(snac *user, const char *id, int end_secs)
|
||||
}
|
||||
|
||||
|
||||
int was_question_voted(snac *user, const char *id)
|
||||
/* returns true if the user voted in this poll */
|
||||
{
|
||||
xs *children = object_children(id);
|
||||
int voted = 0;
|
||||
xs_list *p;
|
||||
xs_str *md5;
|
||||
|
||||
p = children;
|
||||
while (xs_list_iter(&p, &md5)) {
|
||||
xs *obj = NULL;
|
||||
|
||||
if (valid_status(object_get_by_md5(md5, &obj))) {
|
||||
if (strcmp(xs_dict_get(obj, "attributedTo"), user->actor) == 0) {
|
||||
voted = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return voted;
|
||||
}
|
||||
|
||||
|
||||
xs_list *user_queue(snac *snac)
|
||||
/* returns a list with filenames that can be dequeued */
|
||||
{
|
||||
|
18
mastoapi.c
18
mastoapi.c
@ -598,7 +598,6 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
|
||||
xs *f = xs_val_new(XSTYPE_FALSE);
|
||||
xs *t = xs_val_new(XSTYPE_TRUE);
|
||||
xs_list *opts = NULL;
|
||||
xs_list *p;
|
||||
xs_val *v;
|
||||
int num_votes = 0;
|
||||
xs *options = xs_list_new();
|
||||
@ -638,21 +637,8 @@ xs_dict *mastoapi_poll(snac *snac, const xs_dict *msg)
|
||||
xs *vc = xs_number_new(num_votes);
|
||||
poll = xs_dict_append(poll, "votes_count", vc);
|
||||
|
||||
xs *children = object_children(xs_dict_get(msg, "id"));
|
||||
int voted = 0;
|
||||
p = children;
|
||||
while (xs_list_iter(&p, &v)) {
|
||||
xs *obj = NULL;
|
||||
|
||||
if (valid_status(object_get_by_md5(v, &obj))) {
|
||||
if (strcmp(xs_dict_get(obj, "attributedTo"), snac->actor) == 0) {
|
||||
voted = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
poll = xs_dict_append(poll, "voted", voted ? t : f);
|
||||
poll = xs_dict_append(poll, "voted",
|
||||
was_question_voted(snac, xs_dict_get(msg, "id")) ? t : f);
|
||||
}
|
||||
|
||||
return poll;
|
||||
|
1
snac.h
1
snac.h
@ -166,6 +166,7 @@ void enqueue_email(xs_str *msg, int retries);
|
||||
void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id);
|
||||
void enqueue_message(snac *snac, char *msg);
|
||||
void enqueue_close_question(snac *user, const char *id, int end_secs);
|
||||
int was_question_voted(snac *user, const char *id);
|
||||
|
||||
xs_list *user_queue(snac *snac);
|
||||
xs_list *queue(void);
|
||||
|
Loading…
Reference in New Issue
Block a user