1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 16:13:02 +01:00

Load conference titles on startup for saved conferences (#43)

This commit is contained in:
JFreegman 2019-06-30 14:51:13 -04:00 committed by GitHub
parent 12b9cd2386
commit bb2257973e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 6 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
@ -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;

View File

@ -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);

View File

@ -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 */

View File

@ -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;
}