mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-15 00:03:02 +01:00
add support for group persistence
This commit is contained in:
parent
b31bd93e7d
commit
830ddb21b5
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
13
src/toxic.c
13
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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user