/* Create a new empty groupchat connection. * * return -1 on failure. * return groupnumber on success. */ static int create_group_chat(Group_Chats *g_c) { uint32_t i; for (i = 0; i < g_c->num_chats; ++i) { if (g_c->chats[i].status == GROUPCHAT_STATUS_NONE) return i; } int id = -1; if (realloc_groupchats(g_c, g_c->num_chats + 1) == 0) { id = g_c->num_chats; ++g_c->num_chats; memset(&(g_c->chats[id]), 0, sizeof(Group_c)); } return id; }
/* Wipe a groupchat. * * return -1 on failure. * return 0 on success. */ static int wipe_group_chat(Group_Chats *g_c, int groupnumber) { if (groupnumber_not_valid(g_c, groupnumber)) return -1; uint32_t i; memset(&(g_c->chats[groupnumber]), 0 , sizeof(Group_c)); for (i = g_c->num_chats; i != 0; --i) { if (g_c->chats[i - 1].status != GROUPCHAT_STATUS_NONE) break; } if (g_c->num_chats != i) { g_c->num_chats = i; realloc_groupchats(g_c, g_c->num_chats); } return 0; }
static void exit_groupchats(Tox *m, uint32_t numchats) { memset(Tox_Bot.g_chats, 0, Tox_Bot.chats_idx * sizeof(struct Group_Chat)); realloc_groupchats(0); int32_t *groupchat_list = malloc(numchats * sizeof(int32_t)); if (groupchat_list == NULL) return; if (tox_get_chatlist(m, groupchat_list, numchats) == 0) { free(groupchat_list); return; } uint32_t i; for (i = 0; i < numchats; ++i) tox_del_groupchat(m, groupchat_list[i]); free(groupchat_list); }