Skip to content

Commit

Permalink
Load conference titles on startup for saved conferences
Browse files Browse the repository at this point in the history
  • Loading branch information
JFreegman committed Jun 26, 2019
1 parent 12b9cd2 commit fe515f9
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/chat_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
return;
}

if (init_groupchat_win(prompt, m, groupnum, type) == -1) {
if (init_groupchat_win(prompt, m, groupnum, type, NULL, 0) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
tox_conference_delete(m, groupnum, NULL);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/global_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
return;
}

if (init_groupchat_win(prompt, m, groupnum, type) == -1) {
if (init_groupchat_win(prompt, m, groupnum, type, NULL, 0) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
tox_conference_delete(m, groupnum, NULL);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/group_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void cmd_set_title(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
if (argc < 1) {
size_t tlen = tox_conference_get_title_size(m, self->num, &err);

if (err != TOX_ERR_CONFERENCE_TITLE_OK) {
if (err != TOX_ERR_CONFERENCE_TITLE_OK || tlen >= sizeof(title)) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Title is not set");
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/groupchat.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static void kill_groupchat_window(ToxWindow *self)
del_window(self);
}

int init_groupchat_win(ToxWindow *prompt, Tox *m, uint32_t groupnum, uint8_t type)
int init_groupchat_win(ToxWindow *prompt, Tox *m, uint32_t groupnum, uint8_t type, const char *title, size_t title_length)
{
if (groupnum > MAX_GROUPCHAT_NUM) {
return -1;
Expand All @@ -146,6 +146,7 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, uint32_t groupnum, uint8_t typ
groupchats[i].start_time = get_unix_time();

set_active_window_index(groupchats[i].chatwin);
set_window_title(self, title, title_length);

if (i == max_groupchat_index) {
++max_groupchat_index;
Expand Down
2 changes: 1 addition & 1 deletion src/groupchat.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ typedef struct {
/* Frees all Toxic associated data structures for a groupchat (does not call tox_conference_delete() ) */
void free_groupchat(ToxWindow *self, Tox *m, uint32_t groupnum);

int init_groupchat_win(ToxWindow *prompt, Tox *m, uint32_t groupnum, uint8_t type);
int init_groupchat_win(ToxWindow *prompt, Tox *m, uint32_t groupnum, uint8_t type, const char *title, size_t title_length);

/* destroys and re-creates groupchat window with or without the peerlist */
void redraw_groupchat_win(ToxWindow *self);
Expand Down
4 changes: 4 additions & 0 deletions src/misc_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ int check_file_signature(const char *signature, size_t size, FILE *fp)
/* sets window title in tab bar. */
void set_window_title(ToxWindow *self, const char *title, int len)
{
if (len <= 0 || !title) {
return;
}

char cpy[TOXIC_MAX_NAME_LENGTH + 1];

if (self->is_groupchat) { /* keep groupnumber in title */
Expand Down
18 changes: 17 additions & 1 deletion src/toxic.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,23 @@ static void load_groups(ToxWindow *prompt, Tox *m)
continue;
}

if (init_groupchat_win(prompt, m, groupnum, type) == -1) {
Tox_Err_Conference_Title t_err;
size_t length = tox_conference_get_title_size(m, groupnum, &t_err);
uint8_t title[MAX_STR_SIZE];

if (t_err != TOX_ERR_CONFERENCE_TITLE_OK || length >= sizeof(title)) {
length = 0;
} else {
tox_conference_get_title(m, groupnum, title, &t_err);

if (t_err != TOX_ERR_CONFERENCE_TITLE_OK) {
length = 0;
}
}

title[length] = 0;

if (init_groupchat_win(prompt, m, groupnum, type, (const char *) title, length) == -1) {
tox_conference_delete(m, groupnum, NULL);
continue;
}
Expand Down

0 comments on commit fe515f9

Please sign in to comment.