commit e913d03
default
·
2023-05-29 07:03:00 +0000 UTC
parent 8551c69
Fixed some bugs in update_question().
1 files changed,
+19,
-4
+19,
-4
1@@ -1000,15 +1000,20 @@ int update_question(snac *user, const char *id)
2 chld = object_children(id);
3 p = chld;
4 while (xs_list_iter(&p, &v)) {
5- const char *name = xs_dict_get(v, "name");
6+ xs *obj = NULL;
7+
8+ if (!valid_status(object_get_by_md5(v, &obj)))
9+ continue;
10+
11+ const char *name = xs_dict_get(obj, "name");
12 if (name) {
13 /* get the current count */
14- const xs_number *cnt = xs_dict_get(rcnt, "name");
15+ const xs_number *cnt = xs_dict_get(rcnt, name);
16
17 if (xs_type(cnt) == XSTYPE_NUMBER) {
18 /* if it exists, increment */
19 xs *ucnt = xs_number_new(xs_number_get(cnt) + 1);
20- rcnt = xs_dict_set(rcnt, "name", ucnt);
21+ rcnt = xs_dict_set(rcnt, name, ucnt);
22 }
23 }
24 }
25@@ -1156,7 +1161,11 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
26 int a_status;
27 int do_notify = 0;
28
29- if (xs_is_null(actor) || xs_is_null(type)) {
30+ /* question votes may not have a type */
31+ if (xs_is_null(type))
32+ type = "Note";
33+
34+ if (xs_is_null(actor)) {
35 snac_debug(snac, 0, xs_fmt("malformed message"));
36 return 1;
37 }
38@@ -1268,6 +1277,12 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
39 snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id));
40 do_notify = 1;
41 }
42+
43+ /* if it has a "name" field, it may be a vote for a question */
44+ const char *name = xs_dict_get(object, "name");
45+
46+ if (!xs_is_null(name) && *name && !xs_is_null(in_reply_to) && *in_reply_to)
47+ update_question(snac, in_reply_to);
48 }
49 else
50 if (strcmp(utype, "Question") == 0) {