From 6cc8fdf2150a0acab14b281c23e6a9ac1bc7f3e4 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Thu, 19 Mar 2015 17:39:11 -0400 Subject: [PATCH] don't delete groups on client exit --- src/groupchat.c | 12 ++++++++---- src/groupchat.h | 2 +- src/windows.c | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/groupchat.c b/src/groupchat.c index fe23739..f5b5ae3 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -167,10 +167,8 @@ static void kill_groupchat_window(ToxWindow *self) } /* Closes groupchat window and cleans up. */ -void close_groupchat(ToxWindow *self, Tox *m, int groupnum, const char *partmessage, int length) +void close_groupchat(ToxWindow *self, Tox *m, int groupnum) { - tox_group_delete(m, groupnum, (uint8_t *) partmessage, (uint16_t) length); - free(groupchats[groupnum].peer_names); free(groupchats[groupnum].peer_name_lengths); memset(&groupchats[groupnum], 0, sizeof(GroupChat)); @@ -186,6 +184,12 @@ void close_groupchat(ToxWindow *self, Tox *m, int groupnum, const char *partmess kill_groupchat_window(self); } +static void exit_groupchat(ToxWindow *self, Tox *m, int groupnum, const char *partmessage, int length) +{ + tox_group_delete(m, groupnum, (uint8_t *) partmessage, (uint16_t) length); + close_groupchat(self, m, groupnum); +} + /* Note: the arguments to these functions are validated in the caller functions */ void set_nick_all_groups(Tox *m, const char *nick, uint16_t length) { @@ -744,7 +748,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) if (line[offset] != '\0') ++offset; - close_groupchat(self, m, self->num, line + offset, ctx->len - offset); + exit_groupchat(self, m, self->num, line + offset, ctx->len - offset); return; } else if (strncmp(line, "/me ", 4) == 0) { send_group_action(self, m, self->num, line + 4); diff --git a/src/groupchat.h b/src/groupchat.h index 98d2e09..faafbeb 100644 --- a/src/groupchat.h +++ b/src/groupchat.h @@ -72,7 +72,7 @@ typedef struct { #endif } GroupChat; -void close_groupchat(ToxWindow *self, Tox *m, int groupnum, const char *partmessage, int length); +void close_groupchat(ToxWindow *self, Tox *m, int groupnum); int init_groupchat_win(Tox *m, int groupnum, const char *groupname, int length); void set_nick_all_groups(Tox *m, const char *nick, uint16_t length); void set_status_all_groups(Tox *m, uint8_t status); diff --git a/src/windows.c b/src/windows.c index 4b58cad..4f03e75 100644 --- a/src/windows.c +++ b/src/windows.c @@ -661,7 +661,7 @@ void kill_all_windows(Tox *m) if (windows[i].is_chat) kill_chat_window(&windows[i], m); else if (windows[i].is_groupchat) - close_groupchat(&windows[i], m, windows[i].num, "Quit", 4); + close_groupchat(&windows[i], m, windows[i].num); } kill_prompt_window(prompt);