From 765936244888f8d5f1644b0178cc6dc70597166b Mon Sep 17 00:00:00 2001 From: default Date: Mon, 29 May 2023 11:07:38 +0200 Subject: [PATCH] Enqueue a close_question user q_item. --- activitypub.c | 14 ++++++++++++-- data.c | 15 +++++++++++++++ main.c | 4 +++- snac.h | 1 + 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/activitypub.c b/activitypub.c index 27f9c7c..15937c3 100644 --- a/activitypub.c +++ b/activitypub.c @@ -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)); } diff --git a/data.c b/data.c index 303b534..d7b0ff6 100644 --- a/data.c +++ b/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 */ { diff --git a/main.c b/main.c index 32952f7..d378598 100644 --- a/main.c +++ b/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); diff --git a/snac.h b/snac.h index bf8948b..60b31c0 100644 --- a/snac.h +++ b/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);