1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-15 06:33:01 +01:00

implement new groupchats

This commit is contained in:
Jfreegman 2015-01-04 01:56:37 -05:00
parent ff0fbbc379
commit 26dda8dbf9
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
21 changed files with 563 additions and 516 deletions

View File

@ -64,9 +64,9 @@ static void kill_infobox(ToxWindow *self);
#endif /* AUDIO */ #endif /* AUDIO */
#ifdef AUDIO #ifdef AUDIO
#define AC_NUM_CHAT_COMMANDS 27 #define AC_NUM_CHAT_COMMANDS 26
#else #else
#define AC_NUM_CHAT_COMMANDS 20 #define AC_NUM_CHAT_COMMANDS 19
#endif /* AUDIO */ #endif /* AUDIO */
/* Array of chat command names used for tab completion. */ /* Array of chat command names used for tab completion. */
@ -81,7 +81,6 @@ static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/exit" }, { "/exit" },
{ "/group" }, { "/group" },
{ "/help" }, { "/help" },
{ "/invite" },
{ "/join" }, { "/join" },
{ "/log" }, { "/log" },
{ "/myid" }, { "/myid" },
@ -561,40 +560,6 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int32_t num, uint8_t filenu
Friends.list[num].file_receiver[filenum].bytes_recv += length; Friends.list[num].file_receiver[filenum].bytes_recv += length;
} }
static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, uint8_t type, const char *group_pub_key,
uint16_t length)
{
if (self->num != friendnumber)
return;
if (Friends.list[friendnumber].group_invite.key != NULL)
free(Friends.list[friendnumber].group_invite.key);
char *k = malloc(length);
if (k == NULL)
exit_toxic_err("Failed in chat_onGroupInvite", FATALERR_MEMORY);
memcpy(k, group_pub_key, length);
Friends.list[friendnumber].group_invite.key = k;
Friends.list[friendnumber].group_invite.pending = true;
Friends.list[friendnumber].group_invite.length = length;
Friends.list[friendnumber].group_invite.type = type;
sound_notify(self, generic_message, NT_WNDALERT_2, NULL);
char name[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, name, friendnumber);
if (self->active_box != -1)
box_silent_notify2(self, NT_WNDALERT_2 | NT_NOFOCUS, self->active_box, "invites you to join group chat");
else
box_silent_notify(self, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name, "invites you to join group chat");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s has invited you to a group chat.", name);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type \"/join\" to join the chat.");
}
/* Av Stuff */ /* Av Stuff */
#ifdef AUDIO #ifdef AUDIO
@ -1140,7 +1105,6 @@ ToxWindow new_chat(Tox *m, int32_t friendnum)
ret.onMessage = &chat_onMessage; ret.onMessage = &chat_onMessage;
ret.onConnectionChange = &chat_onConnectionChange; ret.onConnectionChange = &chat_onConnectionChange;
ret.onTypingChange = & chat_onTypingChange; ret.onTypingChange = & chat_onTypingChange;
ret.onGroupInvite = &chat_onGroupInvite;
ret.onNickChange = &chat_onNickChange; ret.onNickChange = &chat_onNickChange;
ret.onStatusChange = &chat_onStatusChange; ret.onStatusChange = &chat_onStatusChange;
ret.onStatusMessageChange = &chat_onStatusMessageChange; ret.onStatusMessageChange = &chat_onStatusMessageChange;

View File

@ -94,67 +94,6 @@ void cmd_cancelfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
} }
} }
void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group number required.");
return;
}
int groupnum = atoi(argv[1]);
if (groupnum == 0 && strcmp(argv[1], "0")) { /* atoi returns 0 value on invalid input */
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid group number.");
return;
}
if (tox_invite_friend(m, self->num, groupnum) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to invite contact to group.");
return;
}
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invited contact to Group %d.", groupnum);
}
void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Warning: Too many windows are open.");
return;
}
const char *groupkey = Friends.list[self->num].group_invite.key;
uint16_t length = Friends.list[self->num].group_invite.length;
uint8_t type = Friends.list[self->num].group_invite.type;
if (!Friends.list[self->num].group_invite.pending) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending group chat invite.");
return;
}
int groupnum = -1;
if (type == TOX_GROUPCHAT_TYPE_TEXT)
groupnum = tox_join_groupchat(m, self->num, (uint8_t *) groupkey, length);
#ifdef AUDIO
else
groupnum = toxav_join_av_groupchat(m, self->num, (uint8_t *) groupkey, length,
write_device_callback_group, NULL);
#endif
if (groupnum == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat instance failed to initialize.");
return;
}
if (init_groupchat_win(prompt, m, groupnum, type) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
tox_del_groupchat(m, groupnum);
return;
}
}
void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_savefile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (argc < 1) { if (argc < 1) {

View File

@ -27,8 +27,6 @@
#include "toxic.h" #include "toxic.h"
void cmd_cancelfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_cancelfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_groupinvite(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_join_group(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_savefile(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_savefile(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_sendfile(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_sendfile(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);

View File

@ -49,6 +49,7 @@ static struct cmd_func global_commands[] = {
{ "/exit", cmd_quit }, { "/exit", cmd_quit },
{ "/group", cmd_groupchat }, { "/group", cmd_groupchat },
{ "/help", cmd_prompt_help }, { "/help", cmd_prompt_help },
{ "/join", cmd_join },
{ "/log", cmd_log }, { "/log", cmd_log },
{ "/myid", cmd_myid }, { "/myid", cmd_myid },
{ "/nick", cmd_nick }, { "/nick", cmd_nick },
@ -66,8 +67,6 @@ static struct cmd_func global_commands[] = {
static struct cmd_func chat_commands[] = { static struct cmd_func chat_commands[] = {
{ "/cancel", cmd_cancelfile }, { "/cancel", cmd_cancelfile },
{ "/invite", cmd_groupinvite },
{ "/join", cmd_join_group },
{ "/savefile", cmd_savefile }, { "/savefile", cmd_savefile },
{ "/sendfile", cmd_sendfile }, { "/sendfile", cmd_sendfile },
#ifdef AUDIO #ifdef AUDIO
@ -82,8 +81,8 @@ static struct cmd_func chat_commands[] = {
}; };
static struct cmd_func group_commands[] = { static struct cmd_func group_commands[] = {
{ "/title", cmd_set_title }, { "/topic", cmd_set_topic },
{ "/chatid", cmd_chatid },
#ifdef AUDIO #ifdef AUDIO
{ "/mute", cmd_mute }, { "/mute", cmd_mute },
{ "/sense", cmd_sense }, { "/sense", cmd_sense },
@ -177,6 +176,7 @@ void execute(WINDOW *w, ToxWindow *self, Tox *m, const char *input, int mode)
case GROUPCHAT_COMMAND_MODE: case GROUPCHAT_COMMAND_MODE:
if (do_command(w, self, m, num_args, group_commands, args) == 0) if (do_command(w, self, m, num_args, group_commands, args) == 0)
return; return;
break; break;
} }

View File

@ -32,7 +32,7 @@ enum {
GLOBAL_COMMAND_MODE, GLOBAL_COMMAND_MODE,
CHAT_COMMAND_MODE, CHAT_COMMAND_MODE,
GROUPCHAT_COMMAND_MODE, GROUPCHAT_COMMAND_MODE,
}; } COMMAND_MODE;
void execute(WINDOW *w, ToxWindow *self, Tox *m, const char *input, int mode); void execute(WINDOW *w, ToxWindow *self, Tox *m, const char *input, int mode);

View File

@ -112,13 +112,6 @@ static void realloc_blocklist(int n)
void kill_friendlist(void) void kill_friendlist(void)
{ {
int i;
for (i = 0; i < Friends.max_idx; ++i) {
if (Friends.list[i].active && Friends.list[i].group_invite.key != NULL)
free(Friends.list[i].group_invite.key);
}
realloc_blocklist(0); realloc_blocklist(0);
realloc_friends(0); realloc_friends(0);
} }
@ -483,25 +476,6 @@ static void friendlist_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, u
} }
} }
static void friendlist_onGroupInvite(ToxWindow *self, Tox *m, int32_t num, uint8_t type, const char *group_pub_key,
uint16_t length)
{
if (num >= Friends.max_idx)
return;
if (Friends.list[num].chatwin == -1) {
if (get_num_active_windows() < MAX_WINDOWS_NUM) {
Friends.list[num].chatwin = add_window(m, new_chat(m, Friends.list[num].num));
} else {
char nick[TOX_MAX_NAME_LENGTH];
get_nick_truncate(m, nick, num);
line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED,
"* Group chat invite from %s failed: too many windows are open.", nick);
sound_notify(prompt, error, NT_WNDALERT_1, NULL);
}
}
}
/* move friendlist/blocklist cursor up and down */ /* move friendlist/blocklist cursor up and down */
static void select_friend(ToxWindow *self, wint_t key, int *selected, int num) static void select_friend(ToxWindow *self, wint_t key, int *selected, int num)
{ {
@ -527,9 +501,6 @@ static void delete_friend(Tox *m, int32_t f_num)
} }
} }
if (Friends.list[f_num].group_invite.key != NULL)
free(Friends.list[f_num].group_invite.key);
tox_del_friend(m, f_num); tox_del_friend(m, f_num);
memset(&Friends.list[f_num], 0, sizeof(ToxicFriend)); memset(&Friends.list[f_num], 0, sizeof(ToxicFriend));
@ -1075,7 +1046,6 @@ ToxWindow new_friendlist(void)
ret.onStatusChange = &friendlist_onStatusChange; ret.onStatusChange = &friendlist_onStatusChange;
ret.onStatusMessageChange = &friendlist_onStatusMessageChange; ret.onStatusMessageChange = &friendlist_onStatusMessageChange;
ret.onFileSendRequest = &friendlist_onFileSendRequest; ret.onFileSendRequest = &friendlist_onFileSendRequest;
ret.onGroupInvite = &friendlist_onGroupInvite;
#ifdef AUDIO #ifdef AUDIO
ret.onInvite = &friendlist_onAv; ret.onInvite = &friendlist_onAv;

View File

@ -48,13 +48,6 @@ struct LastOnline {
char hour_min_str[TIME_STR_SIZE]; /* holds 12/24-hour time string e.g. "10:43 PM" */ char hour_min_str[TIME_STR_SIZE]; /* holds 12/24-hour time string e.g. "10:43 PM" */
}; };
struct GroupChatInvite {
char *key;
uint16_t length;
uint8_t type;
bool pending;
};
typedef struct { typedef struct {
char name[TOXIC_MAX_NAME_LENGTH + 1]; char name[TOXIC_MAX_NAME_LENGTH + 1];
int namelength; int namelength;
@ -70,7 +63,6 @@ typedef struct {
uint8_t status; uint8_t status;
struct LastOnline last_online; struct LastOnline last_online;
struct FileReceiver file_receiver[MAX_FILES]; struct FileReceiver file_receiver[MAX_FILES];
struct GroupChatInvite group_invite;
uint8_t active_file_receivers; uint8_t active_file_receivers;
} ToxicFriend; } ToxicFriend;

View File

@ -179,7 +179,7 @@ void cmd_add(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
} }
cmd_add_helper(self, m, id_bin, msg); cmd_add_helper(self, m, id_bin, msg);
} else { /* assume id is a username@domain address and do DNS lookup */ } else { /* assume id is a username@domain address */
dns3_lookup(self, m, id_bin, id, msg); dns3_lookup(self, m, id_bin, id, msg);
} }
} }
@ -326,42 +326,90 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
} }
if (argc < 1) { if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Please specify group type: text | audio"); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error: Please specify the group name.");
return; return;
} }
uint8_t type; const char *tmp_name = argv[1];
int len = strlen(tmp_name);
if (!strcasecmp(argv[1], "audio")) if (len == 0 || len > TOX_MAX_GROUP_NAME_LENGTH) {
type = TOX_GROUPCHAT_TYPE_AV; line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error: Invalid group name.");
else if (!strcasecmp(argv[1], "text"))
type = TOX_GROUPCHAT_TYPE_TEXT;
else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Valid group types are: text | audio");
return; return;
} }
int groupnum = -1; char name[TOX_MAX_GROUP_NAME_LENGTH];
if (type == TOX_GROUPCHAT_TYPE_TEXT) if (argv[1][0] == '\"') { /* remove opening and closing quotes */
groupnum = tox_add_groupchat(m); snprintf(name, sizeof(name), "%s", &argv[1][1]);
#ifdef AUDIO len -= 2;
else name[len] = '\0';
groupnum = toxav_add_av_groupchat(m, write_device_callback_group, NULL); } else {
#endif snprintf(name, sizeof(name), "%s", argv[1]);
}
int groupnum = tox_group_new(m, (uint8_t *) name, len);
if (groupnum == -1) { if (groupnum == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat instance failed to initialize."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat instance failed to initialize.");
return; return;
} }
if (init_groupchat_win(prompt, m, groupnum, type) == -1) { if (init_groupchat_win(prompt, m, groupnum, name, len) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
tox_del_groupchat(m, groupnum); tox_group_delete(m, groupnum, NULL, 0);
return;
}
}
void cmd_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
if (get_num_active_windows() >= MAX_WINDOWS_NUM) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Warning: Too many windows are open.");
return; return;
} }
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat [%d] created.", groupnum); if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error: Group chat ID is required.");
return;
}
const char *chat_id = argv[1];
if (strlen(chat_id) != TOX_GROUP_CHAT_ID_SIZE * 2) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Error: Invalid chat ID");
return;
}
char id_bin[TOX_GROUP_CHAT_ID_SIZE] = {0};
size_t i;
char xch[3];
uint32_t x;
for (i = 0; i < TOX_GROUP_CHAT_ID_SIZE; ++i) {
xch[0] = chat_id[2 * i];
xch[1] = chat_id[2 * i + 1];
xch[2] = '\0';
if (sscanf(xch, "%02x", &x) != 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid chat ID.");
return;
}
id_bin[i] = x;
}
if (tox_group_new_join(m, (uint8_t *) id_bin) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat instance failed to initialize.");
return;
}
if (init_groupchat_win(prompt, m, self->num, NULL, 0) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
tox_group_delete(m, self->num, NULL, 0);
return;
}
} }
void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])

View File

@ -33,6 +33,7 @@ void cmd_clear(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE
void cmd_connect(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_connect(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_decline(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_decline(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_groupchat(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_groupchat(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_log(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_log(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_myid(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_myid(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_nick(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_nick(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);

View File

@ -28,50 +28,65 @@
#include "misc_tools.h" #include "misc_tools.h"
#include "log.h" #include "log.h"
void cmd_set_title(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
char title[MAX_STR_SIZE]; char topic[MAX_STR_SIZE];
if (argc < 1) { if (argc < 1) {
int tlen = tox_group_get_title(m, self->num, (uint8_t *) title, TOX_MAX_NAME_LENGTH); int tlen = tox_group_get_topic(m, self->num, (uint8_t *) topic);
if (tlen != -1) { if (tlen > 0) {
title[tlen] = '\0'; topic[tlen] = '\0';
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Title is set to: %s", title); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic is set to: %s", topic);
} else { } else {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Title is not set"); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic is not set");
} }
return; return;
} }
if (argv[1][0] != '\"') { if (argv[1][0] != '\"') {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Title must be enclosed in quotes."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Topic must be enclosed in quotes.");
return; return;
} }
/* remove opening and closing quotes */ /* remove opening and closing quotes */
snprintf(title, sizeof(title), "%s", &argv[1][1]); snprintf(topic, sizeof(topic), "%s", &argv[1][1]);
int len = strlen(title) - 1; int len = strlen(topic) - 1;
title[len] = '\0'; topic[len] = '\0';
if (tox_group_set_title(m, self->num, (uint8_t *) title, len) != 0) { if (tox_group_set_topic(m, self->num, (uint8_t *) topic, len) != 0) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set title."); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to set topic.");
return; return;
} }
set_window_title(self, title, len);
char timefrmt[TIME_STR_SIZE]; char timefrmt[TIME_STR_SIZE];
char selfnick[TOX_MAX_NAME_LENGTH]; char selfnick[TOX_MAX_NAME_LENGTH];
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
uint16_t sn_len = tox_get_self_name(m, (uint8_t *) selfnick); int sn_len = tox_group_get_self_name(m, self->num, (uint8_t *) selfnick);
selfnick[sn_len] = '\0'; selfnick[sn_len] = '\0';
line_info_add(self, timefrmt, selfnick, NULL, NAME_CHANGE, 0, 0, " set the group title to: %s", title); line_info_add(self, timefrmt, selfnick, NULL, NAME_CHANGE, 0, 0, " set the group topic to: %s", topic);
char tmp_event[MAX_STR_SIZE]; char tmp_event[MAX_STR_SIZE];
snprintf(tmp_event, sizeof(tmp_event), "set title to %s", title); snprintf(tmp_event, sizeof(tmp_event), "set topic to %s", topic);
write_to_log(tmp_event, selfnick, self->chatwin->log, true); write_to_log(tmp_event, selfnick, self->chatwin->log, true);
} }
void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
char chatid[TOX_GROUP_CHAT_ID_SIZE * 2 + 1] = {0};
char chat_public_key[TOX_GROUP_CHAT_ID_SIZE];
tox_group_get_invite_key(m, self->num, (uint8_t *) chat_public_key);
size_t i;
for (i = 0; i < TOX_GROUP_CHAT_ID_SIZE; ++i) {
char xx[3];
snprintf(xx, sizeof(xx), "%02X", chat_public_key[i] & 0xff);
strcat(chatid, xx);
}
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "%s", chatid);
}

View File

@ -26,6 +26,7 @@
#include "windows.h" #include "windows.h"
#include "toxic.h" #include "toxic.h"
void cmd_set_title(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]); void cmd_set_topic(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_chatid(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]);
#endif /* GROUP_COMMANDS_H */ #endif /* GROUP_COMMANDS_H */

View File

@ -70,16 +70,17 @@ extern struct user_settings *user_settings;
extern struct Winthread Winthread; extern struct Winthread Winthread;
#ifdef AUDIO #ifdef AUDIO
#define AC_NUM_GROUP_COMMANDS 22 #define AC_NUM_GROUP_COMMANDS 24
#else #else
#define AC_NUM_GROUP_COMMANDS 18 #define AC_NUM_GROUP_COMMANDS 20
#endif /* AUDIO */ #endif /* AUDIO */
/* Array of groupchat command names used for tab completion. */ /* groupchat command names used for tab completion. */
static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = { static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/accept" }, { "/accept" },
{ "/add" }, { "/add" },
{ "/avatar" }, { "/avatar" },
{ "/chatid" },
{ "/clear" }, { "/clear" },
{ "/close" }, { "/close" },
{ "/connect" }, { "/connect" },
@ -87,6 +88,7 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/exit" }, { "/exit" },
{ "/group" }, { "/group" },
{ "/help" }, { "/help" },
{ "/join" },
{ "/log" }, { "/log" },
{ "/myid" }, { "/myid" },
{ "/nick" }, { "/nick" },
@ -94,7 +96,7 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
{ "/quit" }, { "/quit" },
{ "/requests" }, { "/requests" },
{ "/status" }, { "/status" },
{ "/title" }, { "/topic" },
#ifdef AUDIO #ifdef AUDIO
@ -106,45 +108,32 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
#endif /* AUDIO */ #endif /* AUDIO */
}; };
ToxWindow new_group_chat(Tox *m, int groupnum, const char *groupname, int length);
#ifdef AUDIO #ifdef AUDIO
static int group_audio_open_out_device(int groupnum); static int group_audio_open_out_device(int groupnum);
static int group_audio_close_out_device(int groupnum); static int group_audio_close_out_device(int groupnum);
#endif /* AUDIO */ #endif /* AUDIO */
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, uint8_t type) int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, const char *groupname, int length)
{ {
if (groupnum > MAX_GROUPCHAT_NUM) if (groupnum > MAX_GROUPCHAT_NUM)
return -1; return -1;
ToxWindow self = new_group_chat(m, groupnum); ToxWindow self = new_group_chat(m, groupnum, groupname, length);
int i; int i;
for (i = 0; i <= max_groupchat_index; ++i) { for (i = 0; i <= max_groupchat_index; ++i) {
if (!groupchats[i].active) { if (!groupchats[i].active) {
groupchats[i].chatwin = add_window(m, self); groupchats[i].chatwin = add_window(m, self);
groupchats[i].active = true; groupchats[i].active = true;
groupchats[i].num_peers = 0;
groupchats[i].type = type;
groupchats[i].start_time = get_unix_time();
groupchats[i].peer_names = malloc(sizeof(uint8_t) * TOX_MAX_NAME_LENGTH); groupchats[i].peer_names = malloc(sizeof(uint8_t) * TOX_MAX_NAME_LENGTH);
groupchats[i].oldpeer_names = malloc(sizeof(uint8_t) * TOX_MAX_NAME_LENGTH); groupchats[i].peer_name_lengths = malloc(sizeof(uint32_t));
groupchats[i].peer_name_lengths = malloc(sizeof(uint16_t));
groupchats[i].oldpeer_name_lengths = malloc(sizeof(uint16_t));
if (groupchats[i].peer_names == NULL || groupchats[i].oldpeer_names == NULL if (groupchats[i].peer_names == NULL || groupchats[i].peer_name_lengths == NULL)
|| groupchats[i].peer_name_lengths == NULL || groupchats[i].oldpeer_name_lengths == NULL)
exit_toxic_err("failed in init_groupchat_win", FATALERR_MEMORY); exit_toxic_err("failed in init_groupchat_win", FATALERR_MEMORY);
memcpy(&groupchats[i].oldpeer_names[0], UNKNOWN_NAME, sizeof(UNKNOWN_NAME));
groupchats[i].oldpeer_name_lengths[0] = (uint16_t) strlen(UNKNOWN_NAME);
#ifdef AUDIO
if (type == TOX_GROUPCHAT_TYPE_AV)
if (group_audio_open_out_device(i) == -1)
fprintf(stderr, "Group Audio failed to init\n");
#endif /* AUDIO */
set_active_window(groupchats[i].chatwin); set_active_window(groupchats[i].chatwin);
if (i == max_groupchat_index) if (i == max_groupchat_index)
@ -172,17 +161,16 @@ static void kill_groupchat_window(ToxWindow *self)
del_window(self); del_window(self);
} }
void close_groupchat(ToxWindow *self, Tox *m, int groupnum) void close_groupchat(ToxWindow *self, Tox *m, int groupnum, const char *partmessage, int length)
{ {
tox_del_groupchat(m, groupnum); tox_group_delete(m, groupnum, (const uint8_t *) partmessage, (uint16_t) length);
#ifdef AUDIO #ifdef AUDIO
group_audio_close_out_device(groupnum); group_audio_close_out_device(groupnum);
#endif #endif
free(groupchats[groupnum].peer_names); free(groupchats[groupnum].peer_names);
free(groupchats[groupnum].oldpeer_names);
free(groupchats[groupnum].peer_name_lengths); free(groupchats[groupnum].peer_name_lengths);
free(groupchats[groupnum].oldpeer_name_lengths);
memset(&groupchats[groupnum], 0, sizeof(GroupChat)); memset(&groupchats[groupnum], 0, sizeof(GroupChat));
int i; int i;
@ -244,10 +232,10 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
get_group_nick_truncate(m, nick, peernum, groupnum); get_group_nick_truncate(m, nick, peernum, groupnum);
char selfnick[TOX_MAX_NAME_LENGTH]; char selfnick[TOX_MAX_NAME_LENGTH];
uint16_t sn_len = tox_get_self_name(m, (uint8_t *) selfnick); uint16_t sn_len = tox_group_get_self_name(m, groupnum, (uint8_t *) selfnick);
selfnick[sn_len] = '\0'; selfnick[sn_len] = '\0';
int nick_clr = strcmp(nick, selfnick) == 0 ? GREEN : CYAN; int nick_clr = CYAN;
/* Only play sound if mentioned by someone else */ /* Only play sound if mentioned by someone else */
if (strcasestr(msg, selfnick) && strcmp(selfnick, nick)) { if (strcasestr(msg, selfnick) && strcmp(selfnick, nick)) {
@ -283,7 +271,7 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
get_group_nick_truncate(m, nick, peernum, groupnum); get_group_nick_truncate(m, nick, peernum, groupnum);
char selfnick[TOX_MAX_NAME_LENGTH]; char selfnick[TOX_MAX_NAME_LENGTH];
uint16_t n_len = tox_get_self_name(m, (uint8_t *) selfnick); uint16_t n_len = tox_group_get_self_name(m, groupnum, (uint8_t *) selfnick);
selfnick[n_len] = '\0'; selfnick[n_len] = '\0';
if (strcasestr(action, selfnick)) { if (strcasestr(action, selfnick)) {
@ -305,52 +293,61 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p
write_to_log(action, nick, ctx->log, true); write_to_log(action, nick, ctx->log, true);
} }
static void groupchat_onGroupTitleChange(ToxWindow *self, Tox *m, int groupnum, int peernum, const char *title, static void groupchat_onGroupPrivateMessage(ToxWindow *self, Tox *m, int groupnum, uint32_t peernum,
uint8_t length) const char *action, uint16_t len)
{
if (self->num != groupnum)
return;
ChatContext *ctx = self->chatwin;
char nick[TOX_MAX_NAME_LENGTH];
get_group_nick_truncate(m, nick, peernum, groupnum);
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, nick, NULL, IN_MSG, 0, RED, "%s", action);
write_to_log(action, nick, ctx->log, false);
sound_notify(self, silent, NT_WNDALERT_1, NULL);
}
static void groupchat_onGroupTopicChange(ToxWindow *self, Tox *m, int groupnum, uint32_t peernum,
const char *topic, uint16_t length)
{ {
ChatContext *ctx = self->chatwin; ChatContext *ctx = self->chatwin;
if (self->num != groupnum) if (self->num != groupnum)
return; return;
set_window_title(self, title, length);
char timefrmt[TIME_STR_SIZE]; char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
/* don't announce title when we join the room */
if (!timed_out(groupchats[self->num].start_time, get_unix_time(), GROUP_EVENT_WAIT))
return;
char nick[TOX_MAX_NAME_LENGTH]; char nick[TOX_MAX_NAME_LENGTH];
get_group_nick_truncate(m, nick, peernum, groupnum); get_group_nick_truncate(m, nick, peernum, groupnum);
line_info_add(self, timefrmt, nick, NULL, NAME_CHANGE, 0, 0, " set the group title to: %s", title); line_info_add(self, timefrmt, nick, NULL, NAME_CHANGE, 0, 0, " set the group topic to: %s", topic);
char tmp_event[MAX_STR_SIZE]; char tmp_event[MAX_STR_SIZE];
snprintf(tmp_event, sizeof(tmp_event), "set title to %s", title); snprintf(tmp_event, sizeof(tmp_event), "set topic to %s", topic);
write_to_log(tmp_event, nick, ctx->log, true); write_to_log(tmp_event, nick, ctx->log, true);
} }
/* Puts two copies of peerlist/lengths in chat instance */ /* Copies peer names/lengths */
static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], uint16_t lengths[], int npeers) static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], uint32_t lengths[], int npeers)
{ {
/* Assumes these are initiated in init_groupchat_win */
free(groupchats[gnum].peer_names); free(groupchats[gnum].peer_names);
free(groupchats[gnum].oldpeer_names);
free(groupchats[gnum].peer_name_lengths); free(groupchats[gnum].peer_name_lengths);
free(groupchats[gnum].oldpeer_name_lengths);
int N = TOX_MAX_NAME_LENGTH; int N = TOX_MAX_NAME_LENGTH;
groupchats[gnum].peer_names = malloc(sizeof(uint8_t) * npeers * N); groupchats[gnum].peer_names = calloc(1, sizeof(uint8_t) * npeers * N);
groupchats[gnum].oldpeer_names = malloc(sizeof(uint8_t) * npeers * N); groupchats[gnum].peer_name_lengths = calloc(1, sizeof(uint32_t) * npeers);
groupchats[gnum].peer_name_lengths = malloc(sizeof(uint16_t) * npeers);
groupchats[gnum].oldpeer_name_lengths = malloc(sizeof(uint16_t) * npeers);
if (groupchats[gnum].peer_names == NULL || groupchats[gnum].oldpeer_names == NULL if (groupchats[gnum].peer_names == NULL || groupchats[gnum].peer_name_lengths == NULL)
|| groupchats[gnum].peer_name_lengths == NULL || groupchats[gnum].oldpeer_name_lengths == NULL) {
exit_toxic_err("failed in copy_peernames", FATALERR_MEMORY); exit_toxic_err("failed in copy_peernames", FATALERR_MEMORY);
}
if (npeers == 0)
return;
uint16_t u_len = strlen(UNKNOWN_NAME); uint16_t u_len = strlen(UNKNOWN_NAME);
int i; int i;
@ -368,182 +365,197 @@ static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], ui
filter_str((char *) &groupchats[gnum].peer_names[i * N], n_len); filter_str((char *) &groupchats[gnum].peer_names[i * N], n_len);
} }
} }
memcpy(groupchats[gnum].oldpeer_names, groupchats[gnum].peer_names, N * npeers);
memcpy(groupchats[gnum].oldpeer_name_lengths, groupchats[gnum].peer_name_lengths, sizeof(uint16_t) * npeers);
} }
struct group_add_thrd { static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnum)
Tox *m;
ToxWindow *self;
int peernum;
int groupnum;
uint64_t timestamp;
pthread_t tid;
pthread_attr_t attr;
};
/* Waits GROUP_EVENT_WAIT seconds for a new peer to set their name before announcing them */
void *group_add_wait(void *data)
{
struct group_add_thrd *thrd = (struct group_add_thrd *) data;
ToxWindow *self = thrd->self;
Tox *m = thrd->m;
char peername[TOX_MAX_NAME_LENGTH];
/* keep polling for a name that differs from the default until we run out of time */
while (true) {
usleep(100000);
pthread_mutex_lock(&Winthread.lock);
get_group_nick_truncate(m, peername, thrd->peernum, thrd->groupnum);
if (strcmp(peername, DEFAULT_TOX_NAME) || timed_out(thrd->timestamp, get_unix_time(), GROUP_EVENT_WAIT)) {
pthread_mutex_unlock(&Winthread.lock);
break;
}
pthread_mutex_unlock(&Winthread.lock);
}
const char *event = "has joined the room";
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
pthread_mutex_lock(&Winthread.lock);
line_info_add(self, timefrmt, (char *) peername, NULL, CONNECTION, 0, GREEN, event);
write_to_log(event, (char *) peername, self->chatwin->log, true);
pthread_mutex_unlock(&Winthread.lock);
pthread_attr_destroy(&thrd->attr);
free(thrd);
pthread_exit(NULL);
}
static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnum, int peernum, uint8_t change)
{ {
if (self->num != groupnum) if (self->num != groupnum)
return; return;
if (groupnum > max_groupchat_index) int num_peers = tox_group_get_number_peers(m, groupnum);
return; groupchats[groupnum].num_peers = num_peers;
groupchats[groupnum].num_peers = tox_group_number_peers(m, groupnum);
int num_peers = groupchats[groupnum].num_peers;
if (peernum > num_peers)
return;
/* get old peer name before updating name list */
uint8_t oldpeername[TOX_MAX_NAME_LENGTH];
if (change != TOX_CHAT_CHANGE_PEER_ADD) {
memcpy(oldpeername, &groupchats[groupnum].oldpeer_names[peernum * TOX_MAX_NAME_LENGTH],
sizeof(oldpeername));
uint16_t old_n_len = groupchats[groupnum].oldpeer_name_lengths[peernum];
oldpeername[old_n_len] = '\0';
}
/* Update name/len lists */
uint8_t tmp_peerlist[num_peers][TOX_MAX_NAME_LENGTH]; uint8_t tmp_peerlist[num_peers][TOX_MAX_NAME_LENGTH];
uint16_t tmp_peerlens[num_peers]; uint32_t tmp_peerlens[num_peers];
if (tox_group_get_names(m, groupnum, tmp_peerlist, tmp_peerlens, num_peers) == -1) { if (tox_group_get_names(m, groupnum, tmp_peerlist, tmp_peerlens, num_peers) == -1)
memset(tmp_peerlist, 0, sizeof(tmp_peerlist)); return;
memset(tmp_peerlens, 0, sizeof(tmp_peerlens));
}
copy_peernames(groupnum, tmp_peerlist, tmp_peerlens, num_peers); copy_peernames(groupnum, tmp_peerlist, tmp_peerlens, num_peers);
}
/* get current peername then sort namelist */ static void groupchat_onGroupPeerJoin(ToxWindow *self, Tox *m, int groupnum, uint32_t peernum)
uint8_t peername[TOX_MAX_NAME_LENGTH]; {
if (groupnum != self->num)
return;
if (change != TOX_CHAT_CHANGE_PEER_DEL) { if (peernum > groupchats[groupnum].num_peers)
uint16_t n_len = groupchats[groupnum].peer_name_lengths[peernum]; return;
memcpy(peername, &groupchats[groupnum].peer_names[peernum * TOX_MAX_NAME_LENGTH], sizeof(peername));
peername[n_len] = '\0';
}
qsort(groupchats[groupnum].peer_names, groupchats[groupnum].num_peers, TOX_MAX_NAME_LENGTH, qsort_strcasecmp_hlpr); char name[TOX_MAX_NAME_LENGTH];
get_group_nick_truncate(m, name, peernum, groupnum);
ChatContext *ctx = self->chatwin;
const char *event;
char timefrmt[TIME_STR_SIZE]; char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
switch (change) { line_info_add(self, timefrmt, name, NULL, CONNECTION, 0, GREEN, "has joined the room");
case TOX_CHAT_CHANGE_PEER_ADD:
if (!timed_out(groupchats[groupnum].start_time, get_unix_time(), GROUP_EVENT_WAIT))
break;
struct group_add_thrd *thrd = malloc(sizeof(struct group_add_thrd)); char log_str[TOXIC_MAX_NAME_LENGTH + 32];
thrd->m = m; snprintf(log_str, sizeof(log_str), "%s has joined the room", name);
thrd->peernum = peernum;
thrd->groupnum = groupnum;
thrd->self = self;
thrd->timestamp = get_unix_time();
if (pthread_attr_init(&thrd->attr) != 0) {
free(thrd);
return;
}
if (pthread_attr_setdetachstate(&thrd->attr, PTHREAD_CREATE_DETACHED) != 0) {
pthread_attr_destroy(&thrd->attr);
free(thrd);
return;
}
if (pthread_create(&thrd->tid, &thrd->attr, group_add_wait, (void *) thrd) != 0) {
pthread_attr_destroy(&thrd->attr);
free(thrd);
return;
}
break;
case TOX_CHAT_CHANGE_PEER_DEL:
event = "has left the room";
line_info_add(self, timefrmt, (char *) oldpeername, NULL, CONNECTION, 0, RED, event);
if (groupchats[self->num].side_pos > 0)
--groupchats[self->num].side_pos;
write_to_log(event, (char *) oldpeername, ctx->log, true);
break;
case TOX_CHAT_CHANGE_PEER_NAME:
if (!timed_out(groupchats[self->num].start_time, get_unix_time(), GROUP_EVENT_WAIT))
return;
/* ignore initial name change (TODO: this is a bad way to do this) */
if (strcmp((char *) oldpeername, DEFAULT_TOX_NAME) == 0)
return;
event = " is now known as ";
line_info_add(self, timefrmt, (char *) oldpeername, (char *) peername, NAME_CHANGE, 0, 0, event);
char tmp_event[TOXIC_MAX_NAME_LENGTH * 2 + 32];
snprintf(tmp_event, sizeof(tmp_event), "is now known as %s", (char *) peername);
write_to_log(tmp_event, (char *) oldpeername, ctx->log, true);
break;
}
write_to_log(log_str, name, self->chatwin->log, true);
sound_notify(self, silent, NT_WNDALERT_2, NULL); sound_notify(self, silent, NT_WNDALERT_2, NULL);
} }
static void send_group_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *action) static void groupchat_onGroupPeerExit(ToxWindow *self, Tox *m, int groupnum, uint32_t peernum,
const char *partmessage, uint16_t len)
{ {
if (groupnum != self->num)
return;
if (peernum > groupchats[groupnum].num_peers)
return;
char name[TOX_MAX_NAME_LENGTH];
get_group_nick_truncate(m, name, peernum, groupnum);
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, name, NULL, CONNECTION, 0, GREEN, "has left the room (%s)", partmessage);
char log_str[TOXIC_MAX_NAME_LENGTH + MAX_STR_SIZE];
snprintf(log_str, sizeof(log_str), "%s has left the room (%s)", name, partmessage);
write_to_log(log_str, name, self->chatwin->log, true);
sound_notify(self, silent, NT_WNDALERT_2, NULL);
}
static void groupchat_onGroupSelfJoin(ToxWindow *self, Tox *m, int groupnum)
{
if (groupnum != self->num)
return;
char groupname[TOX_MAX_GROUP_NAME_LENGTH];
int len = tox_group_get_group_name(m, groupnum, (uint8_t *) groupname);
if (len > 0)
set_window_title(self, groupname, len);
char topic[TOX_MAX_GROUP_TOPIC_LENGTH];
tox_group_get_topic(m, groupnum, (uint8_t *) topic);
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 0, 0, "Connected.");
line_info_add(self, timefrmt, NULL, NULL, SYS_MSG, 0, 0, "Topic set to: %s", topic);
}
static void groupchat_onGroupSelfTimeout(ToxWindow *self, Tox *m, int groupnum)
{
if (groupnum != self->num)
return;
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Disconnected from group. Attempting to reconnect...");
}
static void groupchat_onGroupOpCertificate(ToxWindow *self, Tox *m, int groupnum, uint32_t src_peernum,
uint32_t tgt_peernum, uint8_t type)
{
if (groupnum != self->num)
return;
char src_name[TOX_MAX_NAME_LENGTH];
get_group_nick_truncate(m, src_name, src_peernum, groupnum);
char tgt_name[TOX_MAX_NAME_LENGTH];
get_group_nick_truncate(m, tgt_name, tgt_peernum, groupnum);
const char *msg = NULL;
switch (type) {
case TOX_GC_BAN:
msg = "has banned";
break;
case TOX_GC_PROMOTE_OP:
msg = "has given operator status to";
break;
case TOX_GC_REVOKE_OP:
msg = "has removed operator status from";
break;
case TOX_GC_SILENCE:
msg = "has silenced";
break;
default:
return;
}
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, src_name, tgt_name, NAME_CHANGE, 0, MAGENTA, "%s", msg);
}
static void groupchat_onGroupNickChange(ToxWindow *self, Tox *m, int groupnum, uint32_t peernum,
const char *newnick, uint16_t len)
{
if (groupnum != self->num)
return;
char oldnick[TOX_MAX_NAME_LENGTH];
get_group_nick_truncate(m, oldnick, peernum, groupnum);
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, oldnick, (char *) newnick, NAME_CHANGE, 0, MAGENTA, "is now known as");
}
static void send_group_message(ToxWindow *self, Tox *m, int groupnum, const char *msg)
{
ChatContext *ctx = self->chatwin;
if (tox_group_message_send(m, self->num, (uint8_t *) msg, strlen(msg)) == -1) {
const char *errmsg = " * Failed to send message.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
return;
}
char selfname[TOX_MAX_NAME_LENGTH];
uint16_t len = tox_group_get_self_name(m, groupnum, (uint8_t *) selfname);
selfname[len] = '\0';
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, selfname, NULL, OUT_MSG_READ, 0, 0, msg);
write_to_log(msg, selfname, ctx->log, false);
}
static void send_group_action(ToxWindow *self, Tox *m, int groupnum, char *action)
{
ChatContext *ctx = self->chatwin;
if (action == NULL) { if (action == NULL) {
wprintw(ctx->history, "Invalid syntax.\n"); wprintw(ctx->history, "Invalid syntax.\n");
return; return;
} }
if (tox_group_action_send(m, self->num, (uint8_t *) action, strlen(action)) == -1) { if (tox_group_action_send(m, groupnum, (uint8_t *) action, strlen(action)) == -1) {
const char *errmsg = " * Failed to send action."; const char *errmsg = " * Failed to send action.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg); line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
return;
} }
char selfname[TOX_MAX_NAME_LENGTH];
uint16_t len = tox_group_get_self_name(m, groupnum, (uint8_t *) selfname);
selfname[len] = '\0';
char timefrmt[TIME_STR_SIZE];
get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, selfname, NULL, OUT_ACTION_READ, 0, 0, action);
write_to_log(action, selfname, ctx->log, true);
} }
static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr) static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
@ -618,19 +630,16 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
add_line_to_hist(ctx); add_line_to_hist(ctx);
if (line[0] == '/') { if (line[0] == '/') {
if (strcmp(line, "/close") == 0) { if (strncmp(line, "/close", 6) == 0) {
close_groupchat(self, m, self->num); close_groupchat(self, m, self->num, line + 6, ctx->len - 6);
return; return;
} else if (strncmp(line, "/me ", strlen("/me ")) == 0) { } else if (strncmp(line, "/me ", strlen("/me ")) == 0) {
send_group_action(self, ctx, m, line + strlen("/me ")); send_group_action(self, m, self->num, line + strlen("/me "));
} else { } else {
execute(ctx->history, self, m, line, GROUPCHAT_COMMAND_MODE); execute(ctx->history, self, m, line, GROUPCHAT_COMMAND_MODE);
} }
} else if (!string_is_empty(line)) { } else if (!string_is_empty(line)) {
if (tox_group_message_send(m, self->num, (uint8_t *) line, strlen(line)) == -1) { send_group_message(self, m, self->num, line);
const char *errmsg = " * Failed to send message.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
}
} }
wclear(ctx->linewin); wclear(ctx->linewin);
@ -727,6 +736,14 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE); execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);
char selfname[TOX_MAX_NAME_LENGTH];
uint16_t len = tox_get_self_name(m, (uint8_t *) selfname);
selfname[len] = '\0';
tox_group_set_name(m, self->num, (uint8_t *) selfname, len);
uint8_t status = tox_get_self_user_status(m);
tox_group_set_status(m, self->num, status);
scrollok(ctx->history, 0); scrollok(ctx->history, 0);
wmove(self->window, y2 - CURS_Y_OFFSET, 0); wmove(self->window, y2 - CURS_Y_OFFSET, 0);
} }
@ -849,7 +866,7 @@ static void groupchat_onWriteDevice(ToxWindow *self, Tox *m, int groupnum, int p
} }
#endif /* AUDIO */ #endif /* AUDIO */
ToxWindow new_group_chat(Tox *m, int groupnum) ToxWindow new_group_chat(Tox *m, int groupnum, const char *groupname, int length)
{ {
ToxWindow ret; ToxWindow ret;
memset(&ret, 0, sizeof(ret)); memset(&ret, 0, sizeof(ret));
@ -862,14 +879,24 @@ ToxWindow new_group_chat(Tox *m, int groupnum)
ret.onInit = &groupchat_onInit; ret.onInit = &groupchat_onInit;
ret.onGroupMessage = &groupchat_onGroupMessage; ret.onGroupMessage = &groupchat_onGroupMessage;
ret.onGroupNamelistChange = &groupchat_onGroupNamelistChange; ret.onGroupNamelistChange = &groupchat_onGroupNamelistChange;
ret.onGroupPrivateMessage = &groupchat_onGroupPrivateMessage;
ret.onGroupAction = &groupchat_onGroupAction; ret.onGroupAction = &groupchat_onGroupAction;
ret.onGroupTitleChange = &groupchat_onGroupTitleChange; ret.onGroupPeerJoin = &groupchat_onGroupPeerJoin;
ret.onGroupPeerExit = &groupchat_onGroupPeerExit;
ret.onGroupTopicChange = &groupchat_onGroupTopicChange;
ret.onGroupOpCertificate = &groupchat_onGroupOpCertificate;
ret.onGroupNickChange = &groupchat_onGroupNickChange;
ret.onGroupSelfJoin = &groupchat_onGroupSelfJoin;
ret.onGroupSelfTimeout = &groupchat_onGroupSelfTimeout;
#ifdef AUDIO #ifdef AUDIO
ret.onWriteDevice = &groupchat_onWriteDevice; ret.onWriteDevice = &groupchat_onWriteDevice;
#endif #endif
snprintf(ret.name, sizeof(ret.name), "Group %d", groupnum); if (groupname && length)
set_window_title(&ret, groupname, length);
else
snprintf(ret.name, sizeof(ret.name), "Group %d", groupnum);
ChatContext *chatwin = calloc(1, sizeof(ChatContext)); ChatContext *chatwin = calloc(1, sizeof(ChatContext));
Help *help = calloc(1, sizeof(Help)); Help *help = calloc(1, sizeof(Help));

View File

@ -61,26 +61,19 @@ struct GAudio {
typedef struct { typedef struct {
int chatwin; int chatwin;
bool active; bool active;
uint8_t type;
int num_peers; int num_peers;
int side_pos; /* current position of the sidebar - used for scrolling up and down */ int side_pos; /* current position of the sidebar - used for scrolling up and down */
uint64_t start_time;
uint8_t *peer_names; uint8_t *peer_names;
uint8_t *oldpeer_names; uint32_t *peer_name_lengths;
uint16_t *peer_name_lengths;
uint16_t *oldpeer_name_lengths;
#ifdef AUDIO #ifdef AUDIO
struct GAudio audio; struct GAudio audio;
#endif #endif
} GroupChat; } GroupChat;
void close_groupchat(ToxWindow *self, Tox *m, int groupnum); void close_groupchat(ToxWindow *self, Tox *m, int groupnum, const char *partmessage, int length);
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, uint8_t type); int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, const char *groupname, int length);
/* destroys and re-creates groupchat window with or without the peerlist */ /* destroys and re-creates groupchat window with or without the peerlist */
void redraw_groupchat_win(ToxWindow *self); void redraw_groupchat_win(ToxWindow *self);
ToxWindow new_group_chat(Tox *m, int groupnum);
#endif /* #define GROUPCHAT_H */ #endif /* #define GROUPCHAT_H */

View File

@ -150,9 +150,10 @@ static void help_draw_global(ToxWindow *self)
wprintw(win, " /connect <ip> <port> <key> : Manually connect to a DHT node\n"); wprintw(win, " /connect <ip> <port> <key> : Manually connect to a DHT node\n");
wprintw(win, " /status <type> <msg> : Set status with optional note\n"); wprintw(win, " /status <type> <msg> : Set status with optional note\n");
wprintw(win, " /note <msg> : Set a personal note\n"); wprintw(win, " /note <msg> : Set a personal note\n");
wprintw(win, " /group : Create a group chat\n");
wprintw(win, " /join <chat id> : Join a group chat\n");
wprintw(win, " /nick <nick> : Set your nickname\n"); wprintw(win, " /nick <nick> : Set your nickname\n");
wprintw(win, " /log <on> or <off> : Enable/disable logging\n"); wprintw(win, " /log <on> or <off> : Enable/disable logging\n");
wprintw(win, " /group <type> : Create a group chat where type: text | audio\n");
wprintw(win, " /myid : Print your Tox ID\n"); wprintw(win, " /myid : Print your Tox ID\n");
wprintw(win, " /clear : Clear window history\n"); wprintw(win, " /clear : Clear window history\n");
wprintw(win, " /close : Close the current chat window\n"); wprintw(win, " /close : Close the current chat window\n");
@ -183,8 +184,6 @@ static void help_draw_chat(ToxWindow *self)
wprintw(win, "Chat Commands:\n"); wprintw(win, "Chat Commands:\n");
wattroff(win, A_BOLD | COLOR_PAIR(RED)); wattroff(win, A_BOLD | COLOR_PAIR(RED));
wprintw(win, " /invite <n> : Invite contact to a group chat\n");
wprintw(win, " /join : Join a pending group chat\n");
wprintw(win, " /sendfile <path> : Send a file\n"); wprintw(win, " /sendfile <path> : Send a file\n");
wprintw(win, " /savefile <id> : Receive a file\n"); wprintw(win, " /savefile <id> : Receive a file\n");
wprintw(win, " /cancel <type> <id> : Cancel file transfer where type: in|out\n"); wprintw(win, " /cancel <type> <id> : Cancel file transfer where type: in|out\n");
@ -243,14 +242,17 @@ static void help_draw_group(ToxWindow *self)
wprintw(win, "Group commands:\n"); wprintw(win, "Group commands:\n");
wattroff(win, A_BOLD | COLOR_PAIR(RED)); wattroff(win, A_BOLD | COLOR_PAIR(RED));
wprintw(win, " /title <msg> : Set group title (show current title if no msg)\n\n"); wprintw(win, " /topic <msg> : Set group topic (show current topic if no msg)\n");
wprintw(win, " /chatid : Print the group chat id to share with others.\n\n");
#ifdef AUDIO
wattron(win, A_BOLD); wattron(win, A_BOLD);
wprintw(win, " Audio commands:\n"); wprintw(win, " Audio commands:\n");
wattroff(win, A_BOLD); wattroff(win, A_BOLD);
wprintw(win, " /mute <type> : Mute active device where type: in | out\n"); wprintw(win, " /mute <type> : Mute active device where type: in | out\n");
wprintw(win, " /sense <n> : VAD sensitivity threshold\n\n"); wprintw(win, " /sense <n> : VAD sensitivity threshold\n\n");
#endif /* AUDIO */
help_draw_bottom_menu(win); help_draw_bottom_menu(win);
@ -290,28 +292,30 @@ void help_onKey(ToxWindow *self, wint_t key)
case 'c': case 'c':
#ifdef AUDIO #ifdef AUDIO
help_init_window(self, 19, 80); help_init_window(self, 18, 80);
#else #else
help_init_window(self, 9, 80); help_init_window(self, 8, 80);
#endif #endif
self->help->type = HELP_CHAT; self->help->type = HELP_CHAT;
break; break;
case 'g': case 'g':
#ifdef AUDIO #ifdef AUDIO
help_init_window(self, 24, 80); help_init_window(self, 25, 80);
#else #else
help_init_window(self, 20, 80); help_init_window(self, 21, 80);
#endif #endif
self->help->type = HELP_GLOBAL; self->help->type = HELP_GLOBAL;
break; break;
#ifdef AUDIO /* remove if/when we add non-audio group commands */
case 'r': case 'r':
help_init_window(self, 10, 80); #ifdef AUDIO
help_init_window(self, 11, 80);
#else
help_init_window(self, 7, 80);
#endif
self->help->type = HELP_GROUP; self->help->type = HELP_GROUP;
break; break;
#endif
case 'f': case 'f':
help_init_window(self, 10, 80); help_init_window(self, 10, 80);

View File

@ -35,7 +35,7 @@ enum {
SYS_MSG, SYS_MSG,
IN_MSG, IN_MSG,
OUT_MSG, OUT_MSG,
OUT_MSG_READ, /* for sent messages that have received a read reply. don't set this with line_info_add */ OUT_MSG_READ, /* for sent messages that have received a read reply. */
IN_ACTION, IN_ACTION,
OUT_ACTION, OUT_ACTION,
OUT_ACTION_READ, /* same as OUT_MSG_READ but for actions */ OUT_ACTION_READ, /* same as OUT_MSG_READ but for actions */

View File

@ -281,7 +281,7 @@ int get_nick_truncate(Tox *m, char *buf, int friendnum)
/* same as get_nick_truncate but for groupchats */ /* same as get_nick_truncate but for groupchats */
int get_group_nick_truncate(Tox *m, char *buf, int peernum, int groupnum) int get_group_nick_truncate(Tox *m, char *buf, int peernum, int groupnum)
{ {
int len = tox_group_peername(m, groupnum, peernum, (uint8_t *) buf); int len = tox_group_get_peer_name(m, groupnum, peernum, (uint8_t *) buf);
if (len == -1) { if (len == -1) {
strcpy(buf, UNKNOWN_NAME); strcpy(buf, UNKNOWN_NAME);
@ -395,11 +395,7 @@ int check_file_signature(const char *signature, size_t size, FILE *fp)
void set_window_title(ToxWindow *self, const char *title, int len) void set_window_title(ToxWindow *self, const char *title, int len)
{ {
char cpy[TOXIC_MAX_NAME_LENGTH + 1]; char cpy[TOXIC_MAX_NAME_LENGTH + 1];
snprintf(cpy, sizeof(cpy), "%s", title);
if (self->is_groupchat) /* keep groupnumber in title */
snprintf(cpy, sizeof(cpy), "%d %s", self->num, title);
else
snprintf(cpy, sizeof(cpy), "%s", title);
if (len > MAX_WINDOW_NAME_LENGTH) { if (len > MAX_WINDOW_NAME_LENGTH) {
strcpy(&cpy[MAX_WINDOW_NAME_LENGTH - 3], "..."); strcpy(&cpy[MAX_WINDOW_NAME_LENGTH - 3], "...");

View File

@ -306,15 +306,21 @@ static Tox *init_tox(void)
tox_callback_user_status(m, on_statuschange, NULL); tox_callback_user_status(m, on_statuschange, NULL);
tox_callback_status_message(m, on_statusmessagechange, NULL); tox_callback_status_message(m, on_statusmessagechange, NULL);
tox_callback_friend_action(m, on_action, NULL); tox_callback_friend_action(m, on_action, NULL);
tox_callback_group_invite(m, on_groupinvite, NULL);
tox_callback_group_message(m, on_groupmessage, NULL);
tox_callback_group_action(m, on_groupaction, NULL);
tox_callback_group_namelist_change(m, on_group_namelistchange, NULL);
tox_callback_group_title(m, on_group_titlechange, NULL);
tox_callback_file_send_request(m, on_file_sendrequest, NULL); tox_callback_file_send_request(m, on_file_sendrequest, NULL);
tox_callback_file_control(m, on_file_control, NULL); tox_callback_file_control(m, on_file_control, NULL);
tox_callback_file_data(m, on_file_data, NULL); tox_callback_file_data(m, on_file_data, NULL);
tox_callback_read_receipt(m, on_read_receipt, NULL); tox_callback_read_receipt(m, on_read_receipt, NULL);
tox_callback_group_message(m, on_group_message, NULL);
tox_callback_group_action(m, on_group_action, NULL);
tox_callback_group_private_message(m, on_group_private_message, NULL);
tox_callback_group_op_certificate(m, on_group_op_certificate, NULL);
tox_callback_group_peerlist_update(m, on_group_namelistchange, NULL);
tox_callback_group_peer_join(m, on_group_peer_join, NULL);
tox_callback_group_peer_exit(m, on_group_peer_exit, NULL);
tox_callback_group_nick_change(m, on_group_nick_change, NULL);
tox_callback_group_topic_change(m, on_group_topic_change, NULL);
tox_callback_group_self_join(m, on_group_self_join, NULL);
tox_callback_group_self_timeout(m, on_group_self_timeout, NULL);
tox_set_name(m, (uint8_t *) "Toxic User", strlen("Toxic User")); tox_set_name(m, (uint8_t *) "Toxic User", strlen("Toxic User"));

View File

@ -103,11 +103,6 @@ void on_nickchange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t
void on_statuschange(Tox *m, int32_t friendnumber, uint8_t status, void *userdata); void on_statuschange(Tox *m, int32_t friendnumber, uint8_t status, void *userdata);
void on_statusmessagechange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata); void on_statusmessagechange(Tox *m, int32_t friendnumber, const uint8_t *string, uint16_t length, void *userdata);
void on_friendadded(Tox *m, int32_t friendnumber, bool sort); void on_friendadded(Tox *m, int32_t friendnumber, bool sort);
void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, void *userdata);
void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *action, uint16_t length, void *userdata);
void on_groupinvite(Tox *m, int32_t friendnumber, uint8_t type, const uint8_t *group_pub_key, uint16_t length, void *userdata);
void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata);
void on_group_titlechange(Tox *m, int groupnumber, int peernumber, const uint8_t *title, uint8_t length, void *userdata);
void on_file_sendrequest(Tox *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, const uint8_t *pathname, void on_file_sendrequest(Tox *m, int32_t friendnumber, uint8_t filenumber, uint64_t filesize, const uint8_t *pathname,
uint16_t pathname_length, void *userdata); uint16_t pathname_length, void *userdata);
void on_file_control(Tox *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type, void on_file_control(Tox *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber, uint8_t control_type,
@ -116,6 +111,18 @@ void on_file_data(Tox *m, int32_t friendnumber, uint8_t filenumber, const uint8_
void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *userdata); void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *userdata);
void on_read_receipt(Tox *m, int32_t, uint32_t, void *userdata); void on_read_receipt(Tox *m, int32_t, uint32_t, void *userdata);
void on_group_message(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *message, uint16_t length, void *userdata);
void on_group_action(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *action, uint16_t length, void *userdata);
void on_group_private_message(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *message, uint16_t length, void *userdata);
void on_group_namelistchange(Tox *m, int groupnumber, void *userdata);
void on_group_peer_join(Tox *m, int groupnumber, uint32_t peernumber, void *userdata);
void on_group_peer_exit(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *partmsg, uint16_t length, void *userdata);
void on_group_topic_change(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *topic, uint16_t length, void *userdata);
void on_group_nick_change(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *newname, uint16_t length, void *userdata);
void on_group_op_certificate(Tox *m, int groupnumber, uint32_t src_peernum, uint32_t tgt_peernum, uint8_t cert_type, void *userdata);
void on_group_self_join(Tox *m, int groupnumber, void *userdata);
void on_group_self_timeout(Tox *m, int groupnumber, void *userdata);
#ifdef AUDIO #ifdef AUDIO
void write_device_callback_group(Tox *m, int groupnum, int peernum, const int16_t *pcm, unsigned int samples, void write_device_callback_group(Tox *m, int groupnum, int peernum, const int16_t *pcm, unsigned int samples,
uint8_t channels, unsigned int sample_rate, void *arg); uint8_t channels, unsigned int sample_rate, void *arg);

View File

@ -161,8 +161,8 @@ void on_friendadded(Tox *m, int32_t friendnumber, bool sort)
store_data(m, DATA_FILE); store_data(m, DATA_FILE);
} }
void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, void on_group_message(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *message, uint16_t length,
void *userdata) void *userdata)
{ {
char msg[MAX_STR_SIZE + 1]; char msg[MAX_STR_SIZE + 1];
length = copy_tox_str(msg, sizeof(msg), (const char *) message, length); length = copy_tox_str(msg, sizeof(msg), (const char *) message, length);
@ -175,8 +175,8 @@ void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *mes
} }
} }
void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *action, uint16_t length, void on_group_action(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *action, uint16_t length,
void *userdata) void *userdata)
{ {
char msg[MAX_STR_SIZE + 1]; char msg[MAX_STR_SIZE + 1];
length = copy_tox_str(msg, sizeof(msg), (const char *) action, length); length = copy_tox_str(msg, sizeof(msg), (const char *) action, length);
@ -189,38 +189,117 @@ void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *acti
} }
} }
void on_groupinvite(Tox *m, int32_t friendnumber, uint8_t type, const uint8_t *group_pub_key, uint16_t length, void on_group_private_message(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *message, uint16_t length,
void *userdata) void *userdata)
{ {
char msg[MAX_STR_SIZE + 1];
length = copy_tox_str(msg, sizeof(msg), (const char *) message, length);
int i; int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) { for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupInvite != NULL) if (windows[i].onGroupPrivateMessage != NULL)
windows[i].onGroupInvite(&windows[i], m, friendnumber, type, (char *) group_pub_key, length); windows[i].onGroupPrivateMessage(&windows[i], m, groupnumber, peernumber, msg, length);
} }
} }
void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata) void on_group_namelistchange(Tox *m, int groupnumber, void *userdata)
{ {
int i; int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) { for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupNamelistChange != NULL) if (windows[i].onGroupNamelistChange != NULL)
windows[i].onGroupNamelistChange(&windows[i], m, groupnumber, peernumber, change); windows[i].onGroupNamelistChange(&windows[i], m, groupnumber);
} }
} }
void on_group_titlechange(Tox *m, int groupnumber, int peernumber, const uint8_t *title, uint8_t length, void on_group_peer_join(Tox *m, int groupnumber, uint32_t peernumber, void *userdata)
void *userdata)
{ {
char data[MAX_STR_SIZE + 1]; int i;
length = copy_tox_str(data, sizeof(data), (const char *) title, length);
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupPeerJoin != NULL)
windows[i].onGroupPeerJoin(&windows[i], m, groupnumber, peernumber);
}
}
void on_group_peer_exit(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *partmsg, uint16_t length,
void *userdata)
{
char msg[MAX_STR_SIZE + 1];
if (length == 0 || !partmsg) {
strcpy(msg, "Quit.");
length = 5;
} else {
length = copy_tox_str(msg, sizeof(msg), (const char *) partmsg, length);
}
int i; int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) { for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupTitleChange != NULL) if (windows[i].onGroupPeerExit != NULL)
windows[i].onGroupTitleChange(&windows[i], m, groupnumber, peernumber, data, length); windows[i].onGroupPeerExit(&windows[i], m, groupnumber, peernumber, msg, length);
}
}
void on_group_topic_change(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *topic, uint16_t length,
void *userdata)
{
char data[MAX_STR_SIZE + 1];
length = copy_tox_str(data, sizeof(data), (const char *) topic, length);
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupTopicChange != NULL)
windows[i].onGroupTopicChange(&windows[i], m, groupnumber, peernumber, data, length);
}
}
void on_group_nick_change(Tox *m, int groupnumber, uint32_t peernumber, const uint8_t *newname, uint16_t length,
void *userdata)
{
char name[TOXIC_MAX_NAME_LENGTH + 1];
length = copy_tox_str(name, sizeof(name), (const char *) newname, length);
filter_str(name, length);
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupNickChange != NULL)
windows[i].onGroupNickChange(&windows[i], m, groupnumber, peernumber, name, length);
}
}
void on_group_op_certificate(Tox *m, int groupnumber, uint32_t src_peernum, uint32_t tgt_peernum, uint8_t cert_type,
void *userdata)
{
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupOpCertificate != NULL)
windows[i].onGroupOpCertificate(&windows[i], m, groupnumber, src_peernum, tgt_peernum, cert_type);
}
}
void on_group_self_join(Tox *m, int groupnumber, void *userdata)
{
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupSelfJoin != NULL)
windows[i].onGroupSelfJoin(&windows[i], m, groupnumber);
}
}
void on_group_self_timeout(Tox *m, int groupnumber, void *userdata)
{
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onGroupSelfTimeout != NULL)
windows[i].onGroupSelfTimeout(&windows[i], m, groupnumber);
} }
} }
@ -270,14 +349,14 @@ void on_read_receipt(Tox *m, int32_t friendnumber, uint32_t receipt, void *userd
} }
#ifdef AUDIO #ifdef AUDIO
void write_device_callback_group(Tox *m, int groupnum, int peernum, const int16_t *pcm, unsigned int samples, void write_device_callback_group(Tox *m, int groupnum, int peernumber, const int16_t *pcm, unsigned int samples,
uint8_t channels, unsigned int sample_rate, void *arg) uint8_t channels, unsigned int sample_rate, void *arg)
{ {
int i; int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) { for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
if (windows[i].onWriteDevice != NULL) if (windows[i].onWriteDevice != NULL)
windows[i].onWriteDevice(&windows[i], m, groupnum, peernum, pcm, samples, channels, samples); windows[i].onWriteDevice(&windows[i], m, groupnum, peernumber, pcm, samples, channels, samples);
} }
} }
#endif /* AUDIO */ #endif /* AUDIO */
@ -575,7 +654,7 @@ void kill_all_windows(Tox *m)
if (windows[i].is_chat) if (windows[i].is_chat)
kill_chat_window(&windows[i], m); kill_chat_window(&windows[i], m);
else if (windows[i].is_groupchat) else if (windows[i].is_groupchat)
close_groupchat(&windows[i], m, i); close_groupchat(&windows[i], m, i, "Quit.", 5);
} }
kill_prompt_window(prompt); kill_prompt_window(prompt);

View File

@ -117,17 +117,24 @@ struct ToxWindow {
void(*onStatusChange)(ToxWindow *, Tox *, int32_t, uint8_t); void(*onStatusChange)(ToxWindow *, Tox *, int32_t, uint8_t);
void(*onStatusMessageChange)(ToxWindow *, int32_t, const char *, uint16_t); void(*onStatusMessageChange)(ToxWindow *, int32_t, const char *, uint16_t);
void(*onAction)(ToxWindow *, Tox *, int32_t, const char *, uint16_t); void(*onAction)(ToxWindow *, Tox *, int32_t, const char *, uint16_t);
void(*onGroupMessage)(ToxWindow *, Tox *, int, int, const char *, uint16_t);
void(*onGroupAction)(ToxWindow *, Tox *, int, int, const char *, uint16_t);
void(*onGroupInvite)(ToxWindow *, Tox *, int32_t, uint8_t, const char *, uint16_t);
void(*onGroupNamelistChange)(ToxWindow *, Tox *, int, int, uint8_t);
void(*onGroupTitleChange)(ToxWindow *, Tox *, int, int, const char *, uint8_t);
void(*onFileSendRequest)(ToxWindow *, Tox *, int32_t, uint8_t, uint64_t, const char *, uint16_t); void(*onFileSendRequest)(ToxWindow *, Tox *, int32_t, uint8_t, uint64_t, const char *, uint16_t);
void(*onFileControl)(ToxWindow *, Tox *, int32_t, uint8_t, uint8_t, uint8_t, const char *, uint16_t); void(*onFileControl)(ToxWindow *, Tox *, int32_t, uint8_t, uint8_t, uint8_t, const char *, uint16_t);
void(*onFileData)(ToxWindow *, Tox *, int32_t, uint8_t, const char *, uint16_t); void(*onFileData)(ToxWindow *, Tox *, int32_t, uint8_t, const char *, uint16_t);
void(*onTypingChange)(ToxWindow *, Tox *, int32_t, uint8_t); void(*onTypingChange)(ToxWindow *, Tox *, int32_t, uint8_t);
void(*onReadReceipt)(ToxWindow *, Tox *, int32_t, uint32_t); void(*onReadReceipt)(ToxWindow *, Tox *, int32_t, uint32_t);
void(*onGroupMessage)(ToxWindow *, Tox *, int, int, const char *, uint16_t);
void(*onGroupAction)(ToxWindow *, Tox *, int, int, const char *, uint16_t);
void(*onGroupPrivateMessage)(ToxWindow *, Tox *, int, uint32_t, const char *, uint16_t);
void(*onGroupOpCertificate)(ToxWindow *, Tox *, int, uint32_t, uint32_t, uint8_t);
void(*onGroupNamelistChange)(ToxWindow *, Tox *, int);
void(*onGroupPeerJoin)(ToxWindow *, Tox *, int, uint32_t);
void(*onGroupPeerExit)(ToxWindow *, Tox *, int, uint32_t, const char *, uint16_t);
void(*onGroupNickChange)(ToxWindow *, Tox *, int, uint32_t, const char *, uint16_t);
void(*onGroupTopicChange)(ToxWindow *, Tox *, int, uint32_t, const char *, uint16_t);
void(*onGroupSelfJoin)(ToxWindow *, Tox *, int);
void(*onGroupSelfTimeout)(ToxWindow *, Tox *, int);
#ifdef AUDIO #ifdef AUDIO
void(*onInvite)(ToxWindow *, ToxAv *, int); void(*onInvite)(ToxWindow *, ToxAv *, int);