commit 7659362
default
·
2023-05-29 09:07:38 +0000 UTC
parent 05ac2a0
Enqueue a close_question user q_item.
4 files changed,
+31,
-3
+12,
-2
1@@ -1058,8 +1058,10 @@ int update_question(snac *user, const char *id)
2 xs *now = xs_str_utctime(0, ISO_DATE_SPEC);
3
4 /* it's now greater than the endTime? */
5- if (strcmp(now, end_time) > 0)
6- msg = xs_dict_set(msg, "closed", end_time);
7+ if (strcmp(now, end_time) > 0) {
8+ xs *et = xs_dup(end_time);
9+ msg = xs_dict_set(msg, "closed", et);
10+ }
11 }
12
13 /* update the count of voters */
14@@ -1540,6 +1542,14 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
15 }
16 }
17 }
18+ else
19+ if (strcmp(type, "close_question") == 0) {
20+ /* the time for this question has ended */
21+ const char *id = xs_dict_get(q_item, "message");
22+
23+ if (!xs_is_null(id))
24+ update_question(snac, id);
25+ }
26 else
27 snac_log(snac, xs_fmt("unexpected q_item type '%s'", type));
28 }
M
data.c
+15,
-0
1@@ -1920,6 +1920,21 @@ void enqueue_message(snac *snac, xs_dict *msg)
2 }
3
4
5+void enqueue_close_question(snac *user, const char *id, int end_secs)
6+/* enqueues the closing of a question */
7+{
8+ xs *qmsg = _new_qmsg("close_question", id, 0);
9+ xs *ntid = tid(end_secs);
10+ xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid);
11+
12+ qmsg = xs_dict_set(qmsg, "ntid", ntid);
13+
14+ qmsg = _enqueue_put(fn, qmsg);
15+
16+ snac_debug(user, 0, xs_fmt("enqueue_close_question %s", id));
17+}
18+
19+
20 xs_list *user_queue(snac *snac)
21 /* returns a list with filenames that can be dequeued */
22 {
M
main.c
+3,
-1
1@@ -253,9 +253,10 @@ int main(int argc, char *argv[])
2 }
3
4 if (strcmp(cmd, "question") == 0) { /** **/
5+ int end_secs = 5 * 60;
6 xs *opts = xs_split(url, ";");
7
8- xs *msg = msg_question(&snac, "Poll", opts, 0, 5 * 60);
9+ xs *msg = msg_question(&snac, "Poll", opts, 0, end_secs);
10 xs *c_msg = msg_create(&snac, msg);
11
12 if (dbglevel) {
13@@ -264,6 +265,7 @@ int main(int argc, char *argv[])
14 }
15
16 enqueue_message(&snac, c_msg);
17+ enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs);
18
19 timeline_add(&snac, xs_dict_get(msg, "id"), msg);
20
M
snac.h
+1,
-0
1@@ -165,6 +165,7 @@ void enqueue_output_by_actor(snac *snac, xs_dict *msg, const xs_str *actor, int
2 void enqueue_email(xs_str *msg, int retries);
3 void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id);
4 void enqueue_message(snac *snac, char *msg);
5+void enqueue_close_question(snac *user, const char *id, int end_secs);
6
7 xs_list *user_queue(snac *snac);
8 xs_list *queue(void);