From e913d03f02e7472a7db4da66341153ecdc4c7fdb Mon Sep 17 00:00:00 2001 From: default Date: Mon, 29 May 2023 09:03:00 +0200 Subject: [PATCH] Fixed some bugs in update_question(). --- activitypub.c | 23 +++++++++++++++++++---- 1 file 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) chld = object_children(id); p = chld; while (xs_list_iter(&p, &v)) { - const char *name = xs_dict_get(v, "name"); + xs *obj = NULL; + + if (!valid_status(object_get_by_md5(v, &obj))) + continue; + + const char *name = xs_dict_get(obj, "name"); if (name) { /* get the current count */ - const xs_number *cnt = xs_dict_get(rcnt, "name"); + const xs_number *cnt = xs_dict_get(rcnt, name); if (xs_type(cnt) == XSTYPE_NUMBER) { /* if it exists, increment */ xs *ucnt = xs_number_new(xs_number_get(cnt) + 1); - rcnt = xs_dict_set(rcnt, "name", ucnt); + rcnt = xs_dict_set(rcnt, name, ucnt); } } } @@ -1156,7 +1161,11 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) int a_status; int do_notify = 0; - if (xs_is_null(actor) || xs_is_null(type)) { + /* question votes may not have a type */ + if (xs_is_null(type)) + type = "Note"; + + if (xs_is_null(actor)) { snac_debug(snac, 0, xs_fmt("malformed message")); return 1; } @@ -1268,6 +1277,12 @@ int process_input_message(snac *snac, xs_dict *msg, xs_dict *req) snac_log(snac, xs_fmt("new 'Note' %s %s", actor, id)); do_notify = 1; } + + /* if it has a "name" field, it may be a vote for a question */ + const char *name = xs_dict_get(object, "name"); + + if (!xs_is_null(name) && *name && !xs_is_null(in_reply_to) && *in_reply_to) + update_question(snac, in_reply_to); } else if (strcmp(utype, "Question") == 0) {