summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--activitypub.c14
-rw-r--r--data.c15
-rw-r--r--main.c4
-rw-r--r--snac.h1
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)
1058 xs *now = xs_str_utctime(0, ISO_DATE_SPEC); 1058 xs *now = xs_str_utctime(0, ISO_DATE_SPEC);
1059 1059
1060 /* it's now greater than the endTime? */ 1060 /* it's now greater than the endTime? */
1061 if (strcmp(now, end_time) > 0) 1061 if (strcmp(now, end_time) > 0) {
1062 msg = xs_dict_set(msg, "closed", end_time); 1062 xs *et = xs_dup(end_time);
1063 msg = xs_dict_set(msg, "closed", et);
1064 }
1063 } 1065 }
1064 1066
1065 /* update the count of voters */ 1067 /* update the count of voters */
@@ -1541,6 +1543,14 @@ void process_user_queue_item(snac *snac, xs_dict *q_item)
1541 } 1543 }
1542 } 1544 }
1543 else 1545 else
1546 if (strcmp(type, "close_question") == 0) {
1547 /* the time for this question has ended */
1548 const char *id = xs_dict_get(q_item, "message");
1549
1550 if (!xs_is_null(id))
1551 update_question(snac, id);
1552 }
1553 else
1544 snac_log(snac, xs_fmt("unexpected q_item type '%s'", type)); 1554 snac_log(snac, xs_fmt("unexpected q_item type '%s'", type));
1545} 1555}
1546 1556
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)
1920} 1920}
1921 1921
1922 1922
1923void enqueue_close_question(snac *user, const char *id, int end_secs)
1924/* enqueues the closing of a question */
1925{
1926 xs *qmsg = _new_qmsg("close_question", id, 0);
1927 xs *ntid = tid(end_secs);
1928 xs *fn = xs_fmt("%s/queue/%s.json", user->basedir, ntid);
1929
1930 qmsg = xs_dict_set(qmsg, "ntid", ntid);
1931
1932 qmsg = _enqueue_put(fn, qmsg);
1933
1934 snac_debug(user, 0, xs_fmt("enqueue_close_question %s", id));
1935}
1936
1937
1923xs_list *user_queue(snac *snac) 1938xs_list *user_queue(snac *snac)
1924/* returns a list with filenames that can be dequeued */ 1939/* returns a list with filenames that can be dequeued */
1925{ 1940{
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[])
253 } 253 }
254 254
255 if (strcmp(cmd, "question") == 0) { /** **/ 255 if (strcmp(cmd, "question") == 0) { /** **/
256 int end_secs = 5 * 60;
256 xs *opts = xs_split(url, ";"); 257 xs *opts = xs_split(url, ";");
257 258
258 xs *msg = msg_question(&snac, "Poll", opts, 0, 5 * 60); 259 xs *msg = msg_question(&snac, "Poll", opts, 0, end_secs);
259 xs *c_msg = msg_create(&snac, msg); 260 xs *c_msg = msg_create(&snac, msg);
260 261
261 if (dbglevel) { 262 if (dbglevel) {
@@ -264,6 +265,7 @@ int main(int argc, char *argv[])
264 } 265 }
265 266
266 enqueue_message(&snac, c_msg); 267 enqueue_message(&snac, c_msg);
268 enqueue_close_question(&snac, xs_dict_get(msg, "id"), end_secs);
267 269
268 timeline_add(&snac, xs_dict_get(msg, "id"), msg); 270 timeline_add(&snac, xs_dict_get(msg, "id"), msg);
269 271
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
165void enqueue_email(xs_str *msg, int retries); 165void enqueue_email(xs_str *msg, int retries);
166void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id); 166void enqueue_telegram(const xs_str *msg, const char *bot, const char *chat_id);
167void enqueue_message(snac *snac, char *msg); 167void enqueue_message(snac *snac, char *msg);
168void enqueue_close_question(snac *user, const char *id, int end_secs);
168 169
169xs_list *user_queue(snac *snac); 170xs_list *user_queue(snac *snac);
170xs_list *queue(void); 171xs_list *queue(void);