From 53b1a297d22982ccda32ed06352ef28d062bd8a4 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Tue, 26 Nov 2013 22:15:48 -0500 Subject: [PATCH] move pointer inits and bug fix --- src/chat_commands.c | 6 ++++++ src/groupchat.c | 12 ++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/chat_commands.c b/src/chat_commands.c index 78a8e56..7926831 100644 --- a/src/chat_commands.c +++ b/src/chat_commands.c @@ -13,6 +13,7 @@ #include "misc_tools.h" extern ToxWindow *prompt; +extern int num_groupchats; void cmd_chat_help(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { @@ -65,6 +66,11 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) { + if (num_groupchats >= MAX_GROUPCHAT_NUM) { + wprintw(window, "\nMaximum number of group chats has been reached.\n"); + return; + } + uint8_t *groupkey = friends[self->num].pending_groupchat; if (groupkey[0] == '\0') { diff --git a/src/groupchat.c b/src/groupchat.c index 0658f38..7e1dfec 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -33,7 +33,12 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum) groupchats[i].chatwin = add_window(m, new_group_chat(m, groupnum)); groupchats[i].active = true; groupchats[i].num_peers = 0; - set_active_window(groupchats[i].chatwin); + groupchats[i].peer_names = malloc(sizeof(uint8_t *) * TOX_MAX_NAME_LENGTH); + groupchats[i].oldpeer_names = malloc(sizeof(uint8_t *) * TOX_MAX_NAME_LENGTH); + memset(groupchats[i].peer_names, 0, sizeof(groupchats[i].peer_names)); + memset(groupchats[i].oldpeer_names, 0, sizeof(groupchats[i].oldpeer_names)); + + //set_active_window(groupchats[i].chatwin); if (i == max_groupchat_index) ++max_groupchat_index; @@ -328,11 +333,6 @@ static void groupchat_onInit(ToxWindow *self, Tox *m) print_groupchat_help(ctx); wmove(self->window, y-CURS_Y_OFFSET, 0); - - groupchats[self->num].peer_names = malloc(sizeof(uint8_t *) * TOX_MAX_NAME_LENGTH); - groupchats[self->num].oldpeer_names = malloc(sizeof(uint8_t *) * TOX_MAX_NAME_LENGTH); - memset(groupchats[self->num].peer_names, 0, sizeof(groupchats[self->num].peer_names)); - memset(groupchats[self->num].oldpeer_names, 0, sizeof(groupchats[self->num].oldpeer_names)); } ToxWindow new_group_chat(Tox *m, int groupnum)