From 830ddb21b599da848e111ce0428edb855275cfa6 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Fri, 27 Feb 2015 19:03:53 -0500 Subject: [PATCH] add support for group persistence --- src/global_commands.c | 6 +++--- src/groupchat.c | 6 +++++- src/groupchat.h | 2 +- src/toxic.c | 13 +++++++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/global_commands.c b/src/global_commands.c index f7299a1..6a43e85 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -355,7 +355,7 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg return; } - if (init_groupchat_win(prompt, m, groupnum, name, len) == -1) { + if (init_groupchat_win(m, groupnum, name, len) == -1) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize."); tox_group_delete(m, groupnum, NULL, 0); return; @@ -372,7 +372,7 @@ static void join_invite(ToxWindow *self, Tox *m) return; } - if (init_groupchat_win(prompt, m, groupnumber, NULL, 0) == -1) { + if (init_groupchat_win(m, groupnumber, NULL, 0) == -1) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize."); tox_group_delete(m, groupnumber, NULL, 0); return; @@ -430,7 +430,7 @@ void cmd_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MA return; } - if (init_groupchat_win(prompt, m, groupnum, NULL, 0) == -1) { + if (init_groupchat_win(m, groupnum, NULL, 0) == -1) { line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize."); tox_group_delete(m, groupnum, NULL, 0); return; diff --git a/src/groupchat.c b/src/groupchat.c index 05c202b..1a638b2 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -112,7 +112,7 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = { ToxWindow new_group_chat(Tox *m, int groupnum, const char *groupname, int length); -int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, const char *groupname, int length) +int init_groupchat_win(Tox *m, int groupnum, const char *groupname, int length) { if (groupnum > MAX_GROUPCHAT_NUM) return -1; @@ -137,6 +137,7 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, const char *grou if (i == max_groupchat_index) ++max_groupchat_index; + store_data(m, DATA_FILE); return 0; } } @@ -159,6 +160,9 @@ static void kill_groupchat_window(ToxWindow *self) del_window(self); } +/* Closes groupchat window and cleans up. + * If delete_group is true the group will be permanently deleted. + */ void close_groupchat(ToxWindow *self, Tox *m, int groupnum, const char *partmessage, int length) { tox_group_delete(m, groupnum, (const uint8_t *) partmessage, (uint16_t) length); diff --git a/src/groupchat.h b/src/groupchat.h index 2af61d6..98d2e09 100644 --- a/src/groupchat.h +++ b/src/groupchat.h @@ -73,7 +73,7 @@ typedef struct { } GroupChat; void close_groupchat(ToxWindow *self, Tox *m, int groupnum, const char *partmessage, int length); -int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, const char *groupname, int length); +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); int group_get_nick_peernumber(int groupnum, const char *nick); diff --git a/src/toxic.c b/src/toxic.c index 5f3dbeb..0318958 100644 --- a/src/toxic.c +++ b/src/toxic.c @@ -47,6 +47,7 @@ #include "toxic.h" #include "windows.h" #include "friendlist.h" +#include "groupchat.h" #include "prompt.h" #include "misc_tools.h" #include "file_senders.h" @@ -481,6 +482,17 @@ static void load_friendlist(Tox *m) sort_friendlist_index(); } +static void load_groups(Tox *m) +{ + uint32_t i; + uint32_t numgroups = tox_group_count_groups(m); + + for (i = 0; i < numgroups; ++i) { + if (init_groupchat_win(m, i, NULL, 0) == -1) + tox_group_delete(m, i, NULL, 0); + } +} + /* return length of password on success, 0 on failure */ static int password_prompt(char *buf, int size) { @@ -1109,6 +1121,7 @@ int main(int argc, char *argv[]) if (settings_err == -1) queue_init_message("Failed to load user settings"); + load_groups(m); print_init_messages(prompt); cleanup_init_messages();