summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
authorGravatar default2023-05-29 10:20:45 +0200
committerGravatar default2023-05-29 10:20:45 +0200
commit05ac2a062dc3f01837c511a2d7e2051cda15e44a (patch)
tree1ad080c5fc862d39ea2262b54edd6b918b3c4251 /activitypub.c
parentupdate_question() also updates the count of voters. (diff)
downloadsnac2-05ac2a062dc3f01837c511a2d7e2051cda15e44a.tar.gz
snac2-05ac2a062dc3f01837c511a2d7e2051cda15e44a.tar.xz
snac2-05ac2a062dc3f01837c511a2d7e2051cda15e44a.zip
Keep the original question order after updates.
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/activitypub.c b/activitypub.c
index c80069b..27f9c7c 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -973,11 +973,10 @@ int update_question(snac *user, const char *id)
973 xs *msg = NULL; 973 xs *msg = NULL;
974 xs *rcnt = xs_dict_new(); 974 xs *rcnt = xs_dict_new();
975 xs *z = xs_number_new(0); 975 xs *z = xs_number_new(0);
976 xs *chld = NULL;
977 xs *rcpts = xs_list_new(); 976 xs *rcpts = xs_list_new();
977 xs *lopts = xs_list_new();
978 xs_list *opts; 978 xs_list *opts;
979 xs_val *p; 979 xs_list *p;
980 xs_str *k;
981 xs_val *v; 980 xs_val *v;
982 981
983 /* get the object */ 982 /* get the object */
@@ -997,12 +996,14 @@ int update_question(snac *user, const char *id)
997 p = opts; 996 p = opts;
998 while (xs_list_iter(&p, &v)) { 997 while (xs_list_iter(&p, &v)) {
999 const char *name = xs_dict_get(v, "name"); 998 const char *name = xs_dict_get(v, "name");
1000 if (name) 999 if (name) {
1001 rcnt = xs_dict_set(rcnt, name, z); 1000 lopts = xs_list_append(lopts, name);
1001 rcnt = xs_dict_set(rcnt, name, z);
1002 }
1002 } 1003 }
1003 1004
1004 /* iterate now the children (the votes) */ 1005 /* iterate now the children (the votes) */
1005 chld = object_children(id); 1006 xs *chld = object_children(id);
1006 p = chld; 1007 p = chld;
1007 while (xs_list_iter(&p, &v)) { 1008 while (xs_list_iter(&p, &v)) {
1008 xs *obj = NULL; 1009 xs *obj = NULL;
@@ -1029,19 +1030,23 @@ int update_question(snac *user, const char *id)
1029 1030
1030 /* create a new list of options with their new counts */ 1031 /* create a new list of options with their new counts */
1031 xs *nopts = xs_list_new(); 1032 xs *nopts = xs_list_new();
1032 p = rcnt; 1033 p = lopts;
1033 while (xs_dict_iter(&p, &k, &v)) { 1034 while (xs_list_iter(&p, &v)) {
1034 xs *d1 = xs_dict_new(); 1035 const xs_number *cnt = xs_dict_get(rcnt, v);
1035 xs *d2 = xs_dict_new();
1036 1036
1037 d2 = xs_dict_append(d2, "type", "Collection"); 1037 if (xs_type(cnt) == XSTYPE_NUMBER) {
1038 d2 = xs_dict_append(d2, "totalItems", v); 1038 xs *d1 = xs_dict_new();
1039 xs *d2 = xs_dict_new();
1039 1040
1040 d1 = xs_dict_append(d1, "type", "Note"); 1041 d2 = xs_dict_append(d2, "type", "Collection");
1041 d1 = xs_dict_append(d1, "name", k); 1042 d2 = xs_dict_append(d2, "totalItems", cnt);
1042 d1 = xs_dict_append(d1, "replies", d2);
1043 1043
1044 nopts = xs_list_append(nopts, d1); 1044 d1 = xs_dict_append(d1, "type", "Note");
1045 d1 = xs_dict_append(d1, "name", v);
1046 d1 = xs_dict_append(d1, "replies", d2);
1047
1048 nopts = xs_list_append(nopts, d1);
1049 }
1045 } 1050 }
1046 1051
1047 /* update the list */ 1052 /* update the list */