summaryrefslogtreecommitdiff
path: root/activitypub.c
diff options
context:
space:
mode:
authorGravatar default2023-05-29 09:03:00 +0200
committerGravatar default2023-05-29 09:03:00 +0200
commite913d03f02e7472a7db4da66341153ecdc4c7fdb (patch)
treebb79dceff6665a1b3add4d987acf5d58610351f2 /activitypub.c
parentNew function update_question(). (diff)
downloadsnac2-e913d03f02e7472a7db4da66341153ecdc4c7fdb.tar.gz
snac2-e913d03f02e7472a7db4da66341153ecdc4c7fdb.tar.xz
snac2-e913d03f02e7472a7db4da66341153ecdc4c7fdb.zip
Fixed some bugs in update_question().
Diffstat (limited to 'activitypub.c')
-rw-r--r--activitypub.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/activitypub.c b/activitypub.c
index 1af6d63..7f642b9 100644
--- a/activitypub.c
+++ b/activitypub.c
@@ -1000,15 +1000,20 @@ int update_question(snac *user, const char *id)
1000 chld = object_children(id); 1000 chld = object_children(id);
1001 p = chld; 1001 p = chld;
1002 while (xs_list_iter(&p, &v)) { 1002 while (xs_list_iter(&p, &v)) {
1003 const char *name = xs_dict_get(v, "name"); 1003 xs *obj = NULL;
1004
1005 if (!valid_status(object_get_by_md5(v, &obj)))
1006 continue;
1007
1008 const char *name = xs_dict_get(obj, "name");
1004 if (name) { 1009 if (name) {
1005 /* get the current count */ 1010 /* get the current count */
1006 const xs_number *cnt = xs_dict_get(rcnt, "name"); 1011 const xs_number *cnt = xs_dict_get(rcnt, name);
1007 1012
1008 if (xs_type(cnt) == XSTYPE_NUMBER) { 1013 if (xs_type(cnt) == XSTYPE_NUMBER) {
1009 /* if it exists, increment */ 1014 /* if it exists, increment */
1010 xs *ucnt = xs_number_new(xs_number_get(cnt) + 1); 1015 xs *ucnt = xs_number_new(xs_number_get(cnt) + 1);
1011 rcnt = xs_dict_set(rcnt, "name", ucnt); 1016 rcnt = xs_dict_set(rcnt, name, ucnt);
1012 } 1017 }
1013 } 1018 }
1014 } 1019 }
@@ -1156,7 +1161,11 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
1156 int a_status; 1161 int a_status;
1157 int do_notify = 0; 1162 int do_notify = 0;
1158 1163
1159 if (xs_is_null(actor) || xs_is_null(type)) { 1164 /* question votes may not have a type */
1165 if (xs_is_null(type))
1166 type = "Note";
1167
1168 if (xs_is_null(actor)) {
1160 snac_debug(snac, 0, xs_fmt("malformed message")); 1169 snac_debug(snac, 0, xs_fmt("malformed message"));
1161 return 1; 1170 return 1;
1162 } 1171 }
@@ -1268,6 +1277,12 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req)
1268 snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id)); 1277 snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id));
1269 do_notify = 1; 1278 do_notify = 1;
1270 } 1279 }
1280
1281 /* if it has a "name" field, it may be a vote for a question */
1282 const char *name = xs_dict_get(object, "name");
1283
1284 if (!xs_is_null(name) && *name && !xs_is_null(in_reply_to) && *in_reply_to)
1285 update_question(snac, in_reply_to);
1271 } 1286 }
1272 else 1287 else
1273 if (strcmp(utype, "Question") == 0) { 1288 if (strcmp(utype, "Question") == 0) {