diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-02-27 13:21:23 +0100 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-02-27 13:21:23 +0100 |
commit | b4a8c6e6368ba1d23c083d445d89707c10be8828 (patch) | |
tree | 55e0be3ad28a974c93ffc4da50190b56adccd7a5 /src/api.c | |
parent | netestirano, se prevede (diff) | |
download | discord.c-b4a8c6e6368ba1d23c083d445d89707c10be8828.tar discord.c-b4a8c6e6368ba1d23c083d445d89707c10be8828.tar.gz discord.c-b4a8c6e6368ba1d23c083d445d89707c10be8828.tar.bz2 discord.c-b4a8c6e6368ba1d23c083d445d89707c10be8828.tar.lz discord.c-b4a8c6e6368ba1d23c083d445d89707c10be8828.tar.xz discord.c-b4a8c6e6368ba1d23c083d445d89707c10be8828.tar.zst discord.c-b4a8c6e6368ba1d23c083d445d89707c10be8828.zip |
Diffstat (limited to '')
-rw-r--r-- | src/api.c | 28 |
1 files changed, 17 insertions, 11 deletions
@@ -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); |