commit 05ac2a0
default
·
2023-05-29 08:20:45 +0000 UTC
parent d7b7457
Keep the original question order after updates.
1 files changed,
+21,
-16
+21,
-16
1@@ -973,11 +973,10 @@ int update_question(snac *user, const char *id)
2 xs *msg = NULL;
3 xs *rcnt = xs_dict_new();
4 xs *z = xs_number_new(0);
5- xs *chld = NULL;
6 xs *rcpts = xs_list_new();
7+ xs *lopts = xs_list_new();
8 xs_list *opts;
9- xs_val *p;
10- xs_str *k;
11+ xs_list *p;
12 xs_val *v;
13
14 /* get the object */
15@@ -997,12 +996,14 @@ int update_question(snac *user, const char *id)
16 p = opts;
17 while (xs_list_iter(&p, &v)) {
18 const char *name = xs_dict_get(v, "name");
19- if (name)
20- rcnt = xs_dict_set(rcnt, name, z);
21+ if (name) {
22+ lopts = xs_list_append(lopts, name);
23+ rcnt = xs_dict_set(rcnt, name, z);
24+ }
25 }
26
27 /* iterate now the children (the votes) */
28- chld = object_children(id);
29+ xs *chld = object_children(id);
30 p = chld;
31 while (xs_list_iter(&p, &v)) {
32 xs *obj = NULL;
33@@ -1029,19 +1030,23 @@ int update_question(snac *user, const char *id)
34
35 /* create a new list of options with their new counts */
36 xs *nopts = xs_list_new();
37- p = rcnt;
38- while (xs_dict_iter(&p, &k, &v)) {
39- xs *d1 = xs_dict_new();
40- xs *d2 = xs_dict_new();
41+ p = lopts;
42+ while (xs_list_iter(&p, &v)) {
43+ const xs_number *cnt = xs_dict_get(rcnt, v);
44
45- d2 = xs_dict_append(d2, "type", "Collection");
46- d2 = xs_dict_append(d2, "totalItems", v);
47+ if (xs_type(cnt) == XSTYPE_NUMBER) {
48+ xs *d1 = xs_dict_new();
49+ xs *d2 = xs_dict_new();
50
51- d1 = xs_dict_append(d1, "type", "Note");
52- d1 = xs_dict_append(d1, "name", k);
53- d1 = xs_dict_append(d1, "replies", d2);
54+ d2 = xs_dict_append(d2, "type", "Collection");
55+ d2 = xs_dict_append(d2, "totalItems", cnt);
56
57- nopts = xs_list_append(nopts, d1);
58+ d1 = xs_dict_append(d1, "type", "Note");
59+ d1 = xs_dict_append(d1, "name", v);
60+ d1 = xs_dict_append(d1, "replies", d2);
61+
62+ nopts = xs_list_append(nopts, d1);
63+ }
64 }
65
66 /* update the list */