commit 13ab8c7

default  ·  2023-06-02 09:48:43 +0000 UTC
parent 84152d6
More notify tweaks (I'm getting sick of this).
1 files changed,  +21, -6
+21, -6
 1@@ -522,12 +522,21 @@ void notify(snac *snac, const char *type, const char *utype, const char *actor,
 2 
 3     /* updated poll? */
 4     if (strcmp(type, "Update") == 0 && strcmp(utype, "Question") == 0) {
 5+        const xs_dict *poll;
 6+        const char *poll_id;
 7+
 8+        if ((poll = xs_dict_get(msg, "object")) == NULL)
 9+            return;
10+
11         /* if it's not closed, discard */
12-        if (xs_is_null(xs_dict_get(msg, "closed")))
13+        if (xs_is_null(xs_dict_get(poll, "closed")))
14+            return;
15+
16+        if ((poll_id = xs_dict_get(poll, "id")) == NULL)
17             return;
18 
19         /* if it's not ours and we didn't vote, discard */
20-        if (!xs_startswith(id, snac->actor) && !was_question_voted(snac, id))
21+        if (!xs_startswith(poll_id, snac->actor) && !was_question_voted(snac, poll_id))
22             return;
23     }
24 
25@@ -1193,16 +1202,17 @@ int update_question(snac *user, const char *id)
26     msg = xs_dict_set(msg, xs_dict_get(msg, "oneOf") != NULL ? "oneOf" : "anyOf", nopts);
27 
28     /* due date? */
29+    int closed = 0;
30     const char *end_time = xs_dict_get(msg, "endTime");
31     if (!xs_is_null(end_time)) {
32         xs *now = xs_str_utctime(0, ISO_DATE_SPEC);
33 
34-        /* it's now greater than the endTime? */
35+        /* is now greater than the endTime? */
36         if (strcmp(now, end_time) >= 0) {
37-            xs *et = xs_dup(end_time);
38-            msg    = xs_dict_set(msg, "closed", et);
39+            xs *et    = xs_dup(end_time);
40+            msg       = xs_dict_set(msg, "closed", et);
41 
42-            notify(user, "Update", "Question", user->actor, msg);
43+            closed = 1;
44         }
45     }
46 
47@@ -1222,6 +1232,11 @@ int update_question(snac *user, const char *id)
48 
49     enqueue_message(user, u_msg);
50 
51+    if (closed) {
52+        xs *c_msg = msg_update(user, msg);
53+        notify(user, "Update", "Question", user->actor, c_msg);
54+    }
55+
56     return 0;
57 }
58