From b4a8c6e6368ba1d23c083d445d89707c10be8828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sun, 27 Feb 2022 13:21:23 +0100 Subject: nekaj malega, grem domov --- src/api.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/api.c') diff --git a/src/api.c b/src/api.c index 32a2058..c5fb0b3 100644 --- a/src/api.c +++ b/src/api.c @@ -227,7 +227,7 @@ static int dc_lws_cb (struct lws * wsi, enum lws_callback_reasons rs, void * us, fprintf(stdout, "%.*s", len, (const unsigned char *) in); char * serialized = dc_json(pass->json, in, len); while (serialized) { - cJSON * obj, * obje, * json = cJSON_Parse(serialized); + cJSON * ob, * obj, * obje, * json = cJSON_Parse(serialized); char * st; if (getenv("DC_J")) { st = cJSON_Print(json); @@ -291,8 +291,10 @@ static int dc_lws_cb (struct lws * wsi, enum lws_callback_reasons rs, void * us, ch->type = cJSON_GNV(cJSON_GOI(obj, "type")); ch->id = strtoull(cJSON_GSV(cJSON_GOI(obj, "id")), NULL, 10); cJSON_AFE(obje, cJSON_GOI(obj, "recipient_ids")) { + if (!(st = cJSON_GSV(obje))) + continue; struct dc_user * part = dc_user_init(); - part->username = strdup("Private channel recipient"); + part->id = strtoull(st, NULL, 10); part = dc_add_user( DC_ISAE(pass->api_io.program->users), /* no replace here. stored user can be better. */ part, DC_MAY_FREE); @@ -304,23 +306,27 @@ static int dc_lws_cb (struct lws * wsi, enum lws_callback_reasons rs, void * us, /* replace here. ours is better - fresher. */ DC_MAY_FREE | DC_REPLACE | DC_INCOMPLETE); ch->guild = pass->api_io.client->guilds[0]; } - cJSON_AFE(obj, cJSON_GOI2(json, "d", "merged_members")) + cJSON_AFE(ob, cJSON_GOI2(json, "d", "merged_members")) { + obj = cJSON_GetArrayItem(ob, 0); + if (!cJSON_GAS(cJSON_GOI(obj, "roles"))) + continue; + struct dc_user * user = dc_user_init(); + user->id = strtoull(cJSON_GSV(cJSON_GOI(obj, "user_id")), + NULL, 10); + user = dc_addr_user( + DC_ISAE(pass->api_io.program->users), user, + /* again, no replace here, only ID */ DC_MAY_FREE); cJSON_AFE(obje, cJSON_GOI(obj, "roles")) { if (!(st = cJSON_GSV(obje))) continue; struct dc_role * role = dc_role_init(); role->id = strtoull(st, NULL, 10); - role = dc_add_role( + role = dc_addr_role( DC_ISAE(pass->api_io.program->roles), role, DC_MAY_FREE); - struct dc_user * user = dc_user_init(); - user->id = strtoull(cJSON_GSV(cJSON_GOI( - obj, "user_id")), NULL, 10); - user = dc_add_user( - DC_ISAE(pass->api_io.program->users), - /* again, no replace here, because we only have ID */ user, DC_MAY_FREE); - /* role may have users */ dc_add_user(DC_ISAE(role->users), user, DC_UNSET); + /* role may have users. NO FREE! */ dc_add_user(DC_ISAE(role->users), user, DC_UNSET); } + } cJSON_Delete(json); json = NULL; serialized = dc_json(pass->json, NULL, 0); -- cgit v1.2.3