mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
Enqueue a close_question user q_item.
This commit is contained in:
parent
05ac2a062d
commit
7659362448
4 changed files with 31 additions and 3 deletions
|
@ -1058,8 +1058,10 @@ int update_question(snac *user, const char *id)
|
|||
xs *now = xs_str_utctime(0, ISO_DATE_SPEC);
|
||||
|
||||
/* it's now greater than the endTime? */
|
||||
if (strcmp(now, end_time) > 0)
|
||||
msg = xs_dict_set(msg, "closed", end_time);
|
||||
if (strcmp(now, end_time) > 0) {
|
||||
xs *et = xs_dup(end_time);
|
||||
msg = xs_dict_set(msg, "closed", et);
|
||||
}
|
||||
}
|
||||
|
||||
/* update the count of voters */
|
||||
|
@ -1540,6 +1542,14 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (strcmp(type, "close_question") == 0) {
|
||||
/* the time for this question has ended */
|
||||
const char *id = xs_dict_get(q_item, "message");
|
||||
|
||||
if (!xs_is_null(id))
|
||||
update_question(snac, id);
|
||||
}
|
||||
else
|
||||
snac_log(snac, xs_fmt("unexpected q_item type '%s'", type));
|
||||
}
|
||||
|
|
15
data.c
15
data.c
|
@ -1920,6 +1920,21 @@ void enqueue_message(snac *snac, xs_dict *msg)
|
|||
}
|
||||
|
||||
|
||||
void enqueue_close_question(snac *user, const char *id, int end_secs)
|
||||
/* enqueues the closing of a question */
|
||||
{
|
||||
xs *qmsg = _new_qmsg("close_question", id, 0);
|
||||
xs *ntid = tid(end_secs);
|
||||
xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid);
|
||||
|
||||
qmsg = xs_dict_set(qmsg, "ntid", ntid);
|
||||
|
||||
qmsg = _enqueue_put(fn, qmsg);
|
||||
|
||||
snac_debug(user, 0, xs_fmt("enqueue_close_question %s", id));
|
||||
}
|
||||
|
||||
|
||||
xs_list *user_queue(snac *snac)
|
||||
/* returns a list with filenames that can be dequeued */
|
||||
{
|
||||
|
|
4
main.c
4
main.c
|
@ -253,9 +253,10 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
if (strcmp(cmd, "question") == 0) { /** **/
|
||||
int end_secs = 5 * 60;
|
||||
xs *opts = xs_split(url, ";");
|
||||
|
||||
xs *msg = msg_question(&snac, "Poll", opts, 0, 5 * 60);
|
||||
xs *msg = msg_question(&snac, "Poll", opts, 0, end_secs);
|
||||
xs *c_msg = msg_create(&snac, msg);
|
||||
|
||||
if (dbglevel) {
|
||||
|
@ -264,6 +265,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
enqueue_message(&snac, c_msg);
|
||||
enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs);
|
||||
|
||||
timeline_add(&snac, xs_dict_get(msg, "id"), msg);
|
||||
|
||||
|
|
1
snac.h
1
snac.h
|
@ -165,6 +165,7 @@ void enqueue_output_by_actor(snac *snac, xs_dict *msg, const xs_str *actor, int
|
|||
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);
|
||||
|
||||
xs_list *user_queue(snac *snac);
|
||||
xs_list *queue(void);
|
||||
|
|
Loading…
Reference in a new issue