mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-26 16:03:27 +01:00
Port to toktok-c-toxcore branch
This commit is contained in:
parent
f858714edd
commit
1d71e2eb18
@ -92,8 +92,10 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*a
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tox_invite_friend(m, self->num, groupnum) == -1) {
|
TOX_ERR_CONFERENCE_INVITE err;
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to invite contact to group.");
|
|
||||||
|
if (!tox_conference_invite(m, self->num, groupnum, &err)) {
|
||||||
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to invite contact to group (error %d)", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,25 +118,23 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int groupnum = -1;
|
if (type != TOX_CONFERENCE_TYPE_TEXT) {
|
||||||
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Toxic does not support audio groups.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == TOX_GROUPCHAT_TYPE_TEXT)
|
TOX_ERR_CONFERENCE_JOIN err;
|
||||||
groupnum = tox_join_groupchat(m, self->num, (uint8_t *) groupkey, length);
|
|
||||||
|
|
||||||
/*#ifdef AUDIO
|
uint32_t groupnum = tox_conference_join(m, self->num, (uint8_t *) groupkey, length, &err);
|
||||||
else
|
|
||||||
groupnum = toxav_join_av_groupchat(m, self->num, (uint8_t *) groupkey, length,
|
|
||||||
NULL, NULL);
|
|
||||||
#endif*/
|
|
||||||
|
|
||||||
if (groupnum == -1) {
|
if (err != TOX_ERR_CONFERENCE_JOIN_OK) {
|
||||||
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 (error %d)", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init_groupchat_win(prompt, m, groupnum, type) == -1) {
|
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.");
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
|
||||||
tox_del_groupchat(m, groupnum);
|
tox_conference_delete(m, groupnum, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,32 +336,31 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
|
|||||||
uint8_t type;
|
uint8_t type;
|
||||||
|
|
||||||
if (!strcasecmp(argv[1], "audio"))
|
if (!strcasecmp(argv[1], "audio"))
|
||||||
type = TOX_GROUPCHAT_TYPE_AV;
|
type = TOX_CONFERENCE_TYPE_AV;
|
||||||
else if (!strcasecmp(argv[1], "text"))
|
else if (!strcasecmp(argv[1], "text"))
|
||||||
type = TOX_GROUPCHAT_TYPE_TEXT;
|
type = TOX_CONFERENCE_TYPE_TEXT;
|
||||||
else {
|
else {
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Valid group types are: text | audio");
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Valid group types are: text | audio");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int groupnum = -1;
|
if (type != TOX_CONFERENCE_TYPE_TEXT) {
|
||||||
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Toxic does not support audio groups.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (type == TOX_GROUPCHAT_TYPE_TEXT)
|
TOX_ERR_CONFERENCE_NEW err;
|
||||||
groupnum = tox_add_groupchat(m);
|
|
||||||
|
|
||||||
/*#ifdef AUDIO
|
uint32_t groupnum = tox_conference_new(m, &err);
|
||||||
else
|
|
||||||
groupnum = toxav_add_av_groupchat(m, NULL, NULL);
|
|
||||||
#endif*/
|
|
||||||
|
|
||||||
if (groupnum == -1) {
|
if (err != TOX_ERR_CONFERENCE_NEW_OK) {
|
||||||
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 (error %d)", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (init_groupchat_win(prompt, m, groupnum, type) == -1) {
|
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.");
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
|
||||||
tox_del_groupchat(m, groupnum);
|
tox_conference_delete(m, groupnum, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,18 +30,25 @@
|
|||||||
|
|
||||||
void cmd_set_title(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
void cmd_set_title(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||||
{
|
{
|
||||||
|
TOX_ERR_CONFERENCE_TITLE err;
|
||||||
char title[MAX_STR_SIZE];
|
char title[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);
|
size_t tlen = tox_conference_get_title_size(m, self->num, &err);
|
||||||
|
|
||||||
if (tlen != -1) {
|
if (err != TOX_ERR_CONFERENCE_TITLE_OK) {
|
||||||
title[tlen] = '\0';
|
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Title is set to: %s", title);
|
|
||||||
} 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, "Title is not set");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!tox_conference_get_title(m, self->num, (uint8_t *) title, &err)) {
|
||||||
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Title is not set");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
title[tlen] = '\0';
|
||||||
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Title is set to: %s", title);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,8 +62,8 @@ void cmd_set_title(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
|
|||||||
int len = strlen(title) - 1;
|
int len = strlen(title) - 1;
|
||||||
title[len] = '\0';
|
title[len] = '\0';
|
||||||
|
|
||||||
if (tox_group_set_title(m, self->num, (uint8_t *) title, len) != 0) {
|
if (!tox_conference_set_title(m, self->num, (uint8_t *) title, len, &err)) {
|
||||||
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 title (error %d)", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
286
src/groupchat.c
286
src/groupchat.c
@ -97,26 +97,13 @@ static const char group_cmd_list[AC_NUM_GROUP_COMMANDS][MAX_CMDNAME_SIZE] = {
|
|||||||
{ "/requests" },
|
{ "/requests" },
|
||||||
{ "/status" },
|
{ "/status" },
|
||||||
{ "/title" },
|
{ "/title" },
|
||||||
|
|
||||||
#ifdef AUDIO
|
|
||||||
|
|
||||||
{ "/lsdev" },
|
|
||||||
{ "/sdev" },
|
|
||||||
{ "/mute" },
|
|
||||||
{ "/sense" },
|
|
||||||
|
|
||||||
#endif /* AUDIO */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef AUDIO
|
int init_groupchat_win(ToxWindow *prompt, Tox *m, uint32_t groupnum, uint8_t type)
|
||||||
static int group_audio_open_out_device(int groupnum);
|
|
||||||
static int group_audio_close_out_device(int groupnum);
|
|
||||||
#endif /* AUDIO */
|
|
||||||
|
|
||||||
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, uint8_t type)
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
int i;
|
int i;
|
||||||
@ -141,14 +128,6 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, uint8_t type)
|
|||||||
memcpy(&groupchats[i].oldpeer_names[0], UNKNOWN_NAME, sizeof(UNKNOWN_NAME));
|
memcpy(&groupchats[i].oldpeer_names[0], UNKNOWN_NAME, sizeof(UNKNOWN_NAME));
|
||||||
groupchats[i].oldpeer_name_lengths[0] = (uint16_t) strlen(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)
|
||||||
@ -176,12 +155,9 @@ 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, uint32_t groupnum)
|
||||||
{
|
{
|
||||||
tox_del_groupchat(m, groupnum);
|
tox_conference_delete(m, groupnum, NULL);
|
||||||
#ifdef AUDIO
|
|
||||||
group_audio_close_out_device(groupnum);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
free(groupchats[groupnum].peer_names);
|
free(groupchats[groupnum].peer_names);
|
||||||
free(groupchats[groupnum].oldpeer_names);
|
free(groupchats[groupnum].oldpeer_names);
|
||||||
@ -239,8 +215,8 @@ void redraw_groupchat_win(ToxWindow *self)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int peernum,
|
static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum,
|
||||||
const char *msg, uint16_t len)
|
TOX_MESSAGE_TYPE type, const char *msg, size_t len)
|
||||||
{
|
{
|
||||||
if (self->num != groupnum)
|
if (self->num != groupnum)
|
||||||
return;
|
return;
|
||||||
@ -275,47 +251,12 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int
|
|||||||
char timefrmt[TIME_STR_SIZE];
|
char timefrmt[TIME_STR_SIZE];
|
||||||
get_time_str(timefrmt, sizeof(timefrmt));
|
get_time_str(timefrmt, sizeof(timefrmt));
|
||||||
|
|
||||||
line_info_add(self, timefrmt, nick, NULL, IN_MSG, 0, nick_clr, "%s", msg);
|
line_info_add(self, timefrmt, nick, NULL, type == TOX_MESSAGE_TYPE_NORMAL ? IN_MSG : IN_ACTION, 0, nick_clr, "%s", msg);
|
||||||
write_to_log(msg, nick, ctx->log, false);
|
write_to_log(msg, nick, ctx->log, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int peernum, const char *action,
|
static void groupchat_onGroupTitleChange(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum, const char *title,
|
||||||
uint16_t len)
|
size_t length)
|
||||||
{
|
|
||||||
if (self->num != groupnum)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ChatContext *ctx = self->chatwin;
|
|
||||||
|
|
||||||
char nick[TOX_MAX_NAME_LENGTH];
|
|
||||||
get_group_nick_truncate(m, nick, peernum, groupnum);
|
|
||||||
|
|
||||||
char selfnick[TOX_MAX_NAME_LENGTH];
|
|
||||||
tox_self_get_name(m, (uint8_t *) selfnick);
|
|
||||||
|
|
||||||
size_t n_len = tox_self_get_name_size(m);
|
|
||||||
selfnick[n_len] = '\0';
|
|
||||||
|
|
||||||
if (strcasestr(action, selfnick)) {
|
|
||||||
sound_notify(self, generic_message, NT_WNDALERT_0 | user_settings->bell_on_message, NULL);
|
|
||||||
|
|
||||||
if (self->active_box != -1)
|
|
||||||
box_silent_notify2(self, NT_NOFOCUS, self->active_box, "* %s %s", nick, action );
|
|
||||||
else
|
|
||||||
box_silent_notify(self, NT_NOFOCUS, &self->active_box, self->name, "* %s %s", nick, action);
|
|
||||||
} else {
|
|
||||||
sound_notify(self, silent, NT_WNDALERT_1, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
char timefrmt[TIME_STR_SIZE];
|
|
||||||
get_time_str(timefrmt, sizeof(timefrmt));
|
|
||||||
|
|
||||||
line_info_add(self, timefrmt, nick, NULL, IN_ACTION, 0, 0, "%s", action);
|
|
||||||
write_to_log(action, nick, ctx->log, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void groupchat_onGroupTitleChange(ToxWindow *self, Tox *m, int groupnum, int peernum, const char *title,
|
|
||||||
uint8_t length)
|
|
||||||
{
|
{
|
||||||
ChatContext *ctx = self->chatwin;
|
ChatContext *ctx = self->chatwin;
|
||||||
|
|
||||||
@ -341,7 +282,7 @@ static void groupchat_onGroupTitleChange(ToxWindow *self, Tox *m, int groupnum,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Puts two copies of peerlist/lengths in chat instance */
|
/* Puts two copies of peerlist/lengths in chat instance */
|
||||||
static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], uint16_t lengths[], int npeers)
|
static void copy_peernames(Tox *m, uint32_t gnum, size_t npeers)
|
||||||
{
|
{
|
||||||
/* Assumes these are initiated in init_groupchat_win */
|
/* Assumes these are initiated in init_groupchat_win */
|
||||||
free(groupchats[gnum].peer_names);
|
free(groupchats[gnum].peer_names);
|
||||||
@ -351,27 +292,34 @@ static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], ui
|
|||||||
|
|
||||||
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].oldpeer_names = calloc(1, sizeof(uint8_t) * npeers * N);
|
||||||
groupchats[gnum].peer_name_lengths = malloc(sizeof(uint16_t) * npeers);
|
groupchats[gnum].peer_name_lengths = calloc(1, sizeof(uint16_t) * npeers);
|
||||||
groupchats[gnum].oldpeer_name_lengths = malloc(sizeof(uint16_t) * npeers);
|
groupchats[gnum].oldpeer_name_lengths = calloc(1, sizeof(uint16_t) * npeers);
|
||||||
|
|
||||||
if (groupchats[gnum].peer_names == NULL || groupchats[gnum].oldpeer_names == NULL
|
if (groupchats[gnum].peer_names == NULL || groupchats[gnum].oldpeer_names == NULL
|
||||||
|| groupchats[gnum].peer_name_lengths == NULL || groupchats[gnum].oldpeer_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);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t u_len = strlen(UNKNOWN_NAME);
|
uint16_t u_len = strlen(UNKNOWN_NAME);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < npeers; ++i) {
|
for (i = 0; i < npeers; ++i) {
|
||||||
if (!lengths[i]) {
|
uint8_t name[TOX_MAX_NAME_LENGTH];
|
||||||
|
TOX_ERR_CONFERENCE_PEER_QUERY err;
|
||||||
|
|
||||||
|
size_t n_len = tox_conference_peer_get_name_size(m, gnum, i, &err);
|
||||||
|
|
||||||
|
if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
|
||||||
memcpy(&groupchats[gnum].peer_names[i * N], UNKNOWN_NAME, u_len);
|
memcpy(&groupchats[gnum].peer_names[i * N], UNKNOWN_NAME, u_len);
|
||||||
groupchats[gnum].peer_names[i * N + u_len] = '\0';
|
groupchats[gnum].peer_names[i * N + u_len] = '\0';
|
||||||
groupchats[gnum].peer_name_lengths[i] = u_len;
|
groupchats[gnum].peer_name_lengths[i] = u_len;
|
||||||
} else {
|
} else {
|
||||||
uint16_t n_len = MIN(lengths[i], TOXIC_MAX_NAME_LENGTH - 1);
|
tox_conference_peer_get_name(m, gnum, i, name, NULL);
|
||||||
memcpy(&groupchats[gnum].peer_names[i * N], peerlist[i], n_len);
|
n_len = MIN(n_len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||||
|
memcpy(&groupchats[gnum].peer_names[i * N], name, n_len);
|
||||||
groupchats[gnum].peer_names[i * N + n_len] = '\0';
|
groupchats[gnum].peer_names[i * N + n_len] = '\0';
|
||||||
groupchats[gnum].peer_name_lengths[i] = n_len;
|
groupchats[gnum].peer_name_lengths[i] = n_len;
|
||||||
filter_str((char *) &groupchats[gnum].peer_names[i * N], n_len);
|
filter_str((char *) &groupchats[gnum].peer_names[i * N], n_len);
|
||||||
@ -385,8 +333,8 @@ static void copy_peernames(int gnum, uint8_t peerlist[][TOX_MAX_NAME_LENGTH], ui
|
|||||||
struct group_add_thrd {
|
struct group_add_thrd {
|
||||||
Tox *m;
|
Tox *m;
|
||||||
ToxWindow *self;
|
ToxWindow *self;
|
||||||
int peernum;
|
uint32_t peernum;
|
||||||
int groupnum;
|
uint32_t groupnum;
|
||||||
time_t timestamp;
|
time_t timestamp;
|
||||||
pthread_t tid;
|
pthread_t tid;
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
@ -429,7 +377,8 @@ void *group_add_wait(void *data)
|
|||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnum, int peernum, uint8_t change)
|
static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, uint32_t groupnum, uint32_t peernum,
|
||||||
|
TOX_CONFERENCE_STATE_CHANGE change)
|
||||||
{
|
{
|
||||||
if (self->num != groupnum)
|
if (self->num != groupnum)
|
||||||
return;
|
return;
|
||||||
@ -437,8 +386,15 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
|||||||
if (groupnum > max_groupchat_index)
|
if (groupnum > max_groupchat_index)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
groupchats[groupnum].num_peers = tox_group_number_peers(m, groupnum);
|
TOX_ERR_CONFERENCE_PEER_QUERY err;
|
||||||
int num_peers = groupchats[groupnum].num_peers;
|
|
||||||
|
uint32_t num_peers = tox_conference_peer_count(m, groupnum, &err);
|
||||||
|
|
||||||
|
if (err == TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
|
||||||
|
groupchats[groupnum].num_peers = num_peers;
|
||||||
|
} else {
|
||||||
|
num_peers = groupchats[groupnum].num_peers;
|
||||||
|
}
|
||||||
|
|
||||||
if (peernum > num_peers)
|
if (peernum > num_peers)
|
||||||
return;
|
return;
|
||||||
@ -446,28 +402,19 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
|||||||
/* get old peer name before updating name list */
|
/* get old peer name before updating name list */
|
||||||
uint8_t oldpeername[TOX_MAX_NAME_LENGTH];
|
uint8_t oldpeername[TOX_MAX_NAME_LENGTH];
|
||||||
|
|
||||||
if (change != TOX_CHAT_CHANGE_PEER_ADD) {
|
if (change != TOX_CONFERENCE_STATE_CHANGE_PEER_JOIN) {
|
||||||
memcpy(oldpeername, &groupchats[groupnum].oldpeer_names[peernum * TOX_MAX_NAME_LENGTH],
|
memcpy(oldpeername, &groupchats[groupnum].oldpeer_names[peernum * TOX_MAX_NAME_LENGTH], sizeof(oldpeername));
|
||||||
sizeof(oldpeername));
|
|
||||||
uint16_t old_n_len = groupchats[groupnum].oldpeer_name_lengths[peernum];
|
uint16_t old_n_len = groupchats[groupnum].oldpeer_name_lengths[peernum];
|
||||||
oldpeername[old_n_len] = '\0';
|
oldpeername[old_n_len] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update name/len lists */
|
/* Update name/len lists */
|
||||||
uint8_t tmp_peerlist[num_peers][TOX_MAX_NAME_LENGTH];
|
copy_peernames(m, groupnum, num_peers);
|
||||||
uint16_t tmp_peerlens[num_peers];
|
|
||||||
|
|
||||||
if (tox_group_get_names(m, groupnum, tmp_peerlist, tmp_peerlens, num_peers) == -1) {
|
|
||||||
memset(tmp_peerlist, 0, sizeof(tmp_peerlist));
|
|
||||||
memset(tmp_peerlens, 0, sizeof(tmp_peerlens));
|
|
||||||
}
|
|
||||||
|
|
||||||
copy_peernames(groupnum, tmp_peerlist, tmp_peerlens, num_peers);
|
|
||||||
|
|
||||||
/* get current peername then sort namelist */
|
/* get current peername then sort namelist */
|
||||||
uint8_t peername[TOX_MAX_NAME_LENGTH];
|
uint8_t peername[TOX_MAX_NAME_LENGTH];
|
||||||
|
|
||||||
if (change != TOX_CHAT_CHANGE_PEER_DEL) {
|
if (change != TOX_CONFERENCE_STATE_CHANGE_PEER_EXIT) {
|
||||||
uint16_t n_len = groupchats[groupnum].peer_name_lengths[peernum];
|
uint16_t n_len = groupchats[groupnum].peer_name_lengths[peernum];
|
||||||
memcpy(peername, &groupchats[groupnum].peer_names[peernum * TOX_MAX_NAME_LENGTH], sizeof(peername));
|
memcpy(peername, &groupchats[groupnum].peer_names[peernum * TOX_MAX_NAME_LENGTH], sizeof(peername));
|
||||||
peername[n_len] = '\0';
|
peername[n_len] = '\0';
|
||||||
@ -482,7 +429,7 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
|||||||
get_time_str(timefrmt, sizeof(timefrmt));
|
get_time_str(timefrmt, sizeof(timefrmt));
|
||||||
|
|
||||||
switch (change) {
|
switch (change) {
|
||||||
case TOX_CHAT_CHANGE_PEER_ADD:
|
case TOX_CONFERENCE_STATE_CHANGE_PEER_JOIN:
|
||||||
if (!timed_out(groupchats[groupnum].start_time, GROUP_EVENT_WAIT))
|
if (!timed_out(groupchats[groupnum].start_time, GROUP_EVENT_WAIT))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -512,7 +459,7 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOX_CHAT_CHANGE_PEER_DEL:
|
case TOX_CONFERENCE_STATE_CHANGE_PEER_EXIT:
|
||||||
event = "has left the room";
|
event = "has left the room";
|
||||||
line_info_add(self, timefrmt, (char *) oldpeername, NULL, DISCONNECTION, 0, RED, event);
|
line_info_add(self, timefrmt, (char *) oldpeername, NULL, DISCONNECTION, 0, RED, event);
|
||||||
|
|
||||||
@ -522,7 +469,7 @@ static void groupchat_onGroupNamelistChange(ToxWindow *self, Tox *m, int groupnu
|
|||||||
write_to_log(event, (char *) oldpeername, ctx->log, true);
|
write_to_log(event, (char *) oldpeername, ctx->log, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TOX_CHAT_CHANGE_PEER_NAME:
|
case TOX_CONFERENCE_STATE_CHANGE_PEER_NAME_CHANGE:
|
||||||
if (!timed_out(groupchats[self->num].start_time, GROUP_EVENT_WAIT))
|
if (!timed_out(groupchats[self->num].start_time, GROUP_EVENT_WAIT))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -549,9 +496,10 @@ static void send_group_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *a
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tox_group_action_send(m, self->num, (uint8_t *) action, strlen(action)) == -1) {
|
TOX_ERR_CONFERENCE_SEND_MESSAGE err;
|
||||||
const char *errmsg = " * Failed to send action.";
|
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
|
if (!tox_conference_send_message(m, self->num, TOX_MESSAGE_TYPE_ACTION, (uint8_t *) action, strlen(action), &err)) {
|
||||||
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send action (error %d)", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -641,9 +589,10 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
|||||||
execute(ctx->history, self, m, line, GROUPCHAT_COMMAND_MODE);
|
execute(ctx->history, self, m, line, GROUPCHAT_COMMAND_MODE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (tox_group_message_send(m, self->num, (uint8_t *) line, strlen(line)) == -1) {
|
TOX_ERR_CONFERENCE_SEND_MESSAGE err;
|
||||||
const char *errmsg = " * Failed to send message.";
|
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);
|
if (!tox_conference_send_message(m, self->num, TOX_MESSAGE_TYPE_NORMAL, (uint8_t *) line, strlen(line), &err)) {
|
||||||
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to send message (error %d)", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -701,7 +650,7 @@ static void groupchat_onDraw(ToxWindow *self, Tox *m)
|
|||||||
wmove(ctx->sidebar, i + 2, 1);
|
wmove(ctx->sidebar, i + 2, 1);
|
||||||
|
|
||||||
pthread_mutex_lock(&Winthread.lock);
|
pthread_mutex_lock(&Winthread.lock);
|
||||||
int peer = i + groupchats[self->num].side_pos;
|
uint32_t peer = i + groupchats[self->num].side_pos;
|
||||||
pthread_mutex_unlock(&Winthread.lock);
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
|
|
||||||
/* truncate nick to fit in side panel without modifying list */
|
/* truncate nick to fit in side panel without modifying list */
|
||||||
@ -766,125 +715,7 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
|
|||||||
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ToxWindow new_group_chat(Tox *m, uint32_t groupnum)
|
||||||
#ifdef AUDIO
|
|
||||||
static int group_audio_open_out_device(int groupnum)
|
|
||||||
{
|
|
||||||
char dname[MAX_STR_SIZE];
|
|
||||||
get_primary_device_name(output, dname, sizeof(dname));
|
|
||||||
dname[MAX_STR_SIZE - 1] = '\0';
|
|
||||||
|
|
||||||
groupchats[groupnum].audio.dvhandle = alcOpenDevice(dname);
|
|
||||||
|
|
||||||
if (groupchats[groupnum].audio.dvhandle == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
groupchats[groupnum].audio.dvctx = alcCreateContext(groupchats[groupnum].audio.dvhandle, NULL);
|
|
||||||
alcMakeContextCurrent(groupchats[groupnum].audio.dvctx);
|
|
||||||
alGenBuffers(OPENAL_BUFS, groupchats[groupnum].audio.buffers);
|
|
||||||
alGenSources((uint32_t) 1, &groupchats[groupnum].audio.source);
|
|
||||||
alSourcei(groupchats[groupnum].audio.source, AL_LOOPING, AL_FALSE);
|
|
||||||
|
|
||||||
if (alcGetError(groupchats[groupnum].audio.dvhandle) != AL_NO_ERROR) {
|
|
||||||
group_audio_close_out_device(groupnum);
|
|
||||||
groupchats[groupnum].audio.dvhandle = NULL;
|
|
||||||
groupchats[groupnum].audio.dvctx = NULL;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
alSourceQueueBuffers(groupchats[groupnum].audio.source, OPENAL_BUFS, groupchats[groupnum].audio.buffers);
|
|
||||||
alSourcePlay(groupchats[groupnum].audio.source);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int group_audio_close_out_device(int groupnum)
|
|
||||||
{
|
|
||||||
if (!groupchats[groupnum].audio.dvhandle)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (!groupchats[groupnum].audio.dvctx)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (alcGetCurrentContext() != groupchats[groupnum].audio.dvctx)
|
|
||||||
alcMakeContextCurrent(groupchats[groupnum].audio.dvctx);
|
|
||||||
|
|
||||||
alDeleteSources((uint32_t) 1, &groupchats[groupnum].audio.source);
|
|
||||||
alDeleteBuffers(OPENAL_BUFS, groupchats[groupnum].audio.buffers);
|
|
||||||
|
|
||||||
alcMakeContextCurrent(NULL);
|
|
||||||
alcDestroyContext(groupchats[groupnum].audio.dvctx);
|
|
||||||
|
|
||||||
if (!alcCloseDevice(groupchats[groupnum].audio.dvhandle))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// static int group_audio_write(int peernum, int groupnum, const int16_t *pcm, unsigned int samples, uint8_t channels,
|
|
||||||
// unsigned int sample_rate)
|
|
||||||
// {
|
|
||||||
// if (!pcm)
|
|
||||||
// return -1;
|
|
||||||
|
|
||||||
// if (channels == 0 || channels > 2)
|
|
||||||
// return -2;
|
|
||||||
|
|
||||||
// ALuint bufid;
|
|
||||||
// ALint processed = 0, queued = 0;
|
|
||||||
|
|
||||||
// alGetSourcei(groupchats[groupnum].audio.source, AL_BUFFERS_PROCESSED, &processed);
|
|
||||||
// alGetSourcei(groupchats[groupnum].audio.source, AL_BUFFERS_QUEUED, &queued);
|
|
||||||
// fprintf(stderr, "source: %d, queued: %d, processed: %d\n", groupchats[groupnum].audio.source, queued, processed);
|
|
||||||
|
|
||||||
// if (processed) {
|
|
||||||
// ALuint bufids[processed];
|
|
||||||
// alSourceUnqueueBuffers(groupchats[groupnum].audio.source, processed, bufids);
|
|
||||||
// alDeleteBuffers(processed - 1, bufids + 1);
|
|
||||||
// bufid = bufids[0];
|
|
||||||
// } else if (queued < 16) {
|
|
||||||
// alGenBuffers(1, &bufid);
|
|
||||||
// } else {
|
|
||||||
// return -3;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// int length = samples * channels * sizeof(int16_t);
|
|
||||||
|
|
||||||
// alBufferData(bufid, (channels == 1) ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, pcm, length, sample_rate);
|
|
||||||
// alSourceQueueBuffers(groupchats[groupnum].audio.source, 1, &bufid);
|
|
||||||
|
|
||||||
// ALint state;
|
|
||||||
// alGetSourcei(groupchats[groupnum].audio.source, AL_SOURCE_STATE, &state);
|
|
||||||
|
|
||||||
// if (state != AL_PLAYING)
|
|
||||||
// alSourcePlay(groupchats[groupnum].audio.source);
|
|
||||||
|
|
||||||
// return 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
static void groupchat_onWriteDevice(ToxWindow *self, Tox *m, uint32_t groupnum, int peernum, const int16_t *pcm,
|
|
||||||
unsigned int samples, uint8_t channels, unsigned int sample_rate)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
|
|
||||||
// if (groupnum != self->num)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// if (peernum < 0)
|
|
||||||
// return;
|
|
||||||
|
|
||||||
// if (groupchats[groupnum].audio.dvhandle == NULL)
|
|
||||||
// fprintf(stderr, "dvhandle is null)\n");
|
|
||||||
|
|
||||||
// if (groupchats[groupnum].audio.dvctx == NULL)
|
|
||||||
// fprintf(stderr, "ctx is null\n");
|
|
||||||
|
|
||||||
// int ret = group_audio_write(peernum, groupnum, pcm, samples, channels, sample_rate);
|
|
||||||
// fprintf(stderr, "write: %d\n", ret);
|
|
||||||
}
|
|
||||||
#endif /* AUDIO */
|
|
||||||
|
|
||||||
ToxWindow new_group_chat(Tox *m, int groupnum)
|
|
||||||
{
|
{
|
||||||
ToxWindow ret;
|
ToxWindow ret;
|
||||||
memset(&ret, 0, sizeof(ret));
|
memset(&ret, 0, sizeof(ret));
|
||||||
@ -897,13 +728,8 @@ 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.onGroupAction = &groupchat_onGroupAction;
|
|
||||||
ret.onGroupTitleChange = &groupchat_onGroupTitleChange;
|
ret.onGroupTitleChange = &groupchat_onGroupTitleChange;
|
||||||
|
|
||||||
#ifdef AUDIO
|
|
||||||
ret.onWriteDevice = &groupchat_onWriteDevice;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
snprintf(ret.name, sizeof(ret.name), "Group %d", groupnum);
|
snprintf(ret.name, sizeof(ret.name), "Group %d", groupnum);
|
||||||
|
|
||||||
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
|
ChatContext *chatwin = calloc(1, sizeof(ChatContext));
|
||||||
|
@ -26,61 +26,30 @@
|
|||||||
#include "toxic.h"
|
#include "toxic.h"
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
|
|
||||||
#ifdef AUDIO
|
|
||||||
#include "audio_call.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef AUDIO
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#include <OpenAL/al.h>
|
|
||||||
#include <OpenAL/alc.h>
|
|
||||||
#else
|
|
||||||
#include <AL/al.h>
|
|
||||||
#include <AL/alc.h>
|
|
||||||
/* compatibility with older versions of OpenAL */
|
|
||||||
#ifndef ALC_ALL_DEVICES_SPECIFIER
|
|
||||||
#include <AL/alext.h>
|
|
||||||
#endif /* ALC_ALL_DEVICES_SPECIFIER */
|
|
||||||
#endif /* __APPLE__ */
|
|
||||||
#endif /* AUDIO */
|
|
||||||
|
|
||||||
#define SIDEBAR_WIDTH 16
|
#define SIDEBAR_WIDTH 16
|
||||||
#define SDBAR_OFST 2 /* Offset for the peer number box at the top of the statusbar */
|
#define SDBAR_OFST 2 /* Offset for the peer number box at the top of the statusbar */
|
||||||
#define MAX_GROUPCHAT_NUM MAX_WINDOWS_NUM - 2
|
#define MAX_GROUPCHAT_NUM MAX_WINDOWS_NUM - 2
|
||||||
#define GROUP_EVENT_WAIT 3
|
#define GROUP_EVENT_WAIT 3
|
||||||
|
|
||||||
#ifdef AUDIO
|
|
||||||
struct GAudio {
|
|
||||||
ALCdevice *dvhandle; /* Handle of device selected/opened */
|
|
||||||
ALCcontext *dvctx;
|
|
||||||
ALuint source;
|
|
||||||
ALuint buffers[OPENAL_BUFS];
|
|
||||||
};
|
|
||||||
#endif /* AUDIO */
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int chatwin;
|
int chatwin;
|
||||||
bool active;
|
bool active;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
int num_peers;
|
uint32_t 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 */
|
||||||
time_t start_time;
|
time_t start_time;
|
||||||
uint8_t *peer_names;
|
uint8_t *peer_names;
|
||||||
uint8_t *oldpeer_names;
|
uint8_t *oldpeer_names;
|
||||||
uint16_t *peer_name_lengths;
|
uint16_t *peer_name_lengths;
|
||||||
uint16_t *oldpeer_name_lengths;
|
uint16_t *oldpeer_name_lengths;
|
||||||
|
|
||||||
#ifdef AUDIO
|
|
||||||
struct GAudio audio;
|
|
||||||
#endif
|
|
||||||
} GroupChat;
|
} GroupChat;
|
||||||
|
|
||||||
void close_groupchat(ToxWindow *self, Tox *m, int groupnum);
|
void close_groupchat(ToxWindow *self, Tox *m, uint32_t groupnum);
|
||||||
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, uint8_t type);
|
int init_groupchat_win(ToxWindow *prompt, Tox *m, uint32_t groupnum, uint8_t type);
|
||||||
|
|
||||||
/* 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);
|
ToxWindow new_group_chat(Tox *m, uint32_t groupnum);
|
||||||
|
|
||||||
#endif /* #define GROUPCHAT_H */
|
#endif /* #define GROUPCHAT_H */
|
||||||
|
@ -323,35 +323,53 @@ void str_to_lower(char *str)
|
|||||||
Returns nick len */
|
Returns nick len */
|
||||||
size_t get_nick_truncate(Tox *m, char *buf, uint32_t friendnum)
|
size_t get_nick_truncate(Tox *m, char *buf, uint32_t friendnum)
|
||||||
{
|
{
|
||||||
size_t len = tox_friend_get_name_size(m, friendnum, NULL);
|
TOX_ERR_FRIEND_QUERY err;
|
||||||
|
size_t len = tox_friend_get_name_size(m, friendnum, &err);
|
||||||
|
|
||||||
if (len == 0) {
|
if (err != TOX_ERR_FRIEND_QUERY_OK) {
|
||||||
strcpy(buf, UNKNOWN_NAME);
|
goto on_error;
|
||||||
len = strlen(UNKNOWN_NAME);
|
|
||||||
} else {
|
} else {
|
||||||
tox_friend_get_name(m, friendnum, (uint8_t *) buf, NULL);
|
if (!tox_friend_get_name(m, friendnum, (uint8_t *) buf, NULL)) {
|
||||||
|
goto on_error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
filter_str(buf, len);
|
filter_str(buf, len);
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
|
on_error:
|
||||||
|
strcpy(buf, UNKNOWN_NAME);
|
||||||
|
len = strlen(UNKNOWN_NAME);
|
||||||
|
buf[len] = '\0';
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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, uint32_t peernum, uint32_t groupnum)
|
||||||
{
|
{
|
||||||
int len = tox_group_peername(m, groupnum, peernum, (uint8_t *) buf);
|
TOX_ERR_CONFERENCE_PEER_QUERY err;
|
||||||
|
size_t len = tox_conference_peer_get_name_size(m, groupnum, peernum, &err);
|
||||||
|
|
||||||
if (len == -1) {
|
if (err != TOX_ERR_CONFERENCE_PEER_QUERY_OK) {
|
||||||
strcpy(buf, UNKNOWN_NAME);
|
goto on_error;
|
||||||
len = strlen(UNKNOWN_NAME);
|
} else {
|
||||||
|
if (!tox_conference_peer_get_name(m, groupnum, peernum, (uint8_t *) buf, NULL)) {
|
||||||
|
goto on_error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
len = MIN(len, TOXIC_MAX_NAME_LENGTH - 1);
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
filter_str(buf, len);
|
filter_str(buf, len);
|
||||||
return len;
|
return len;
|
||||||
|
|
||||||
|
on_error:
|
||||||
|
strcpy(buf, UNKNOWN_NAME);
|
||||||
|
len = strlen(UNKNOWN_NAME);
|
||||||
|
buf[len] = '\0';
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copies data to msg buffer.
|
/* copies data to msg buffer.
|
||||||
|
@ -126,7 +126,7 @@ void str_to_lower(char *str);
|
|||||||
size_t get_nick_truncate(Tox *m, char *buf, uint32_t friendnum);
|
size_t get_nick_truncate(Tox *m, char *buf, uint32_t 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, uint32_t peernum, uint32_t groupnum);
|
||||||
|
|
||||||
/* copies data to msg buffer.
|
/* copies data to msg buffer.
|
||||||
returns length of msg, which will be no larger than size-1 */
|
returns length of msg, which will be no larger than size-1 */
|
||||||
|
37
src/toxic.c
37
src/toxic.c
@ -520,24 +520,23 @@ int store_data(Tox *m, const char *path)
|
|||||||
|
|
||||||
static void init_tox_callbacks(Tox *m)
|
static void init_tox_callbacks(Tox *m)
|
||||||
{
|
{
|
||||||
tox_callback_self_connection_status(m, prompt_onSelfConnectionChange, NULL);
|
tox_callback_self_connection_status(m, prompt_onSelfConnectionChange);
|
||||||
tox_callback_friend_connection_status(m, on_connectionchange, NULL);
|
tox_callback_friend_connection_status(m, on_connectionchange);
|
||||||
tox_callback_friend_typing(m, on_typing_change, NULL);
|
tox_callback_friend_typing(m, on_typing_change);
|
||||||
tox_callback_friend_request(m, on_request, NULL);
|
tox_callback_friend_request(m, on_request);
|
||||||
tox_callback_friend_message(m, on_message, NULL);
|
tox_callback_friend_message(m, on_message);
|
||||||
tox_callback_friend_name(m, on_nickchange, NULL);
|
tox_callback_friend_name(m, on_nickchange);
|
||||||
tox_callback_friend_status(m, on_statuschange, NULL);
|
tox_callback_friend_status(m, on_statuschange);
|
||||||
tox_callback_friend_status_message(m, on_statusmessagechange, NULL);
|
tox_callback_friend_status_message(m, on_statusmessagechange);
|
||||||
tox_callback_friend_read_receipt(m, on_read_receipt, NULL);
|
tox_callback_friend_read_receipt(m, on_read_receipt);
|
||||||
tox_callback_group_invite(m, on_groupinvite, NULL);
|
tox_callback_conference_invite(m, on_groupinvite);
|
||||||
tox_callback_group_message(m, on_groupmessage, NULL);
|
tox_callback_conference_message(m, on_groupmessage);
|
||||||
tox_callback_group_action(m, on_groupaction, NULL);
|
tox_callback_conference_namelist_change(m, on_group_namelistchange);
|
||||||
tox_callback_group_namelist_change(m, on_group_namelistchange, NULL);
|
tox_callback_conference_title(m, on_group_titlechange);
|
||||||
tox_callback_group_title(m, on_group_titlechange, NULL);
|
tox_callback_file_recv(m, on_file_recv);
|
||||||
tox_callback_file_recv(m, on_file_recv, NULL);
|
tox_callback_file_chunk_request(m, on_file_chunk_request);
|
||||||
tox_callback_file_chunk_request(m, on_file_chunk_request, NULL);
|
tox_callback_file_recv_control(m, on_file_control);
|
||||||
tox_callback_file_recv_control(m, on_file_control, NULL);
|
tox_callback_file_recv_chunk(m, on_file_recv_chunk);
|
||||||
tox_callback_file_recv_chunk(m, on_file_recv_chunk, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init_tox_options(struct Tox_Options *tox_opts)
|
static void init_tox_options(struct Tox_Options *tox_opts)
|
||||||
@ -747,7 +746,7 @@ static void do_toxic(Tox *m)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tox_iterate(m);
|
tox_iterate(m, NULL);
|
||||||
do_tox_connection(m);
|
do_tox_connection(m);
|
||||||
pthread_mutex_unlock(&Winthread.lock);
|
pthread_mutex_unlock(&Winthread.lock);
|
||||||
}
|
}
|
||||||
|
13
src/toxic.h
13
src/toxic.h
@ -114,12 +114,13 @@ void on_nickchange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t
|
|||||||
void on_statuschange(Tox *m, uint32_t friendnumber, TOX_USER_STATUS status, void *userdata);
|
void on_statuschange(Tox *m, uint32_t friendnumber, TOX_USER_STATUS status, void *userdata);
|
||||||
void on_statusmessagechange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata);
|
void on_statusmessagechange(Tox *m, uint32_t friendnumber, const uint8_t *string, size_t length, void *userdata);
|
||||||
void on_friendadded(Tox *m, uint32_t friendnumber, bool sort);
|
void on_friendadded(Tox *m, uint32_t friendnumber, bool sort);
|
||||||
void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, void *userdata);
|
void on_groupmessage(Tox *m, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type,
|
||||||
void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *action, uint16_t length, void *userdata);
|
const uint8_t *message, size_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 on_groupinvite(Tox *m, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, const uint8_t *group_pub_key,
|
||||||
void *userdata);
|
size_t length, void *userdata);
|
||||||
void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata);
|
void on_group_namelistchange(Tox *m, uint32_t groupnumber, uint32_t peernumber, TOX_CONFERENCE_STATE_CHANGE change,
|
||||||
void on_group_titlechange(Tox *m, int groupnumber, int peernumber, const uint8_t *title, uint8_t length,
|
void *userdata);
|
||||||
|
void on_group_titlechange(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *title, size_t length,
|
||||||
void *userdata);
|
void *userdata);
|
||||||
void on_file_chunk_request(Tox *m, uint32_t friendnumber, uint32_t filenumber, uint64_t position, size_t length,
|
void on_file_chunk_request(Tox *m, uint32_t friendnumber, uint32_t filenumber, uint64_t position, size_t length,
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
@ -151,8 +151,8 @@ void on_friendadded(Tox *m, uint32_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_groupmessage(Tox *m, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type,
|
||||||
void *userdata)
|
const uint8_t *message, size_t length, 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);
|
||||||
@ -161,26 +161,12 @@ void on_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *mes
|
|||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||||
if (windows[i].onGroupMessage != NULL)
|
if (windows[i].onGroupMessage != NULL)
|
||||||
windows[i].onGroupMessage(&windows[i], m, groupnumber, peernumber, msg, length);
|
windows[i].onGroupMessage(&windows[i], m, groupnumber, peernumber, type, msg, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_groupaction(Tox *m, int groupnumber, int peernumber, const uint8_t *action, uint16_t length,
|
void on_groupinvite(Tox *m, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, const uint8_t *group_pub_key,
|
||||||
void *userdata)
|
size_t length, void *userdata)
|
||||||
{
|
|
||||||
char msg[MAX_STR_SIZE + 1];
|
|
||||||
length = copy_tox_str(msg, sizeof(msg), (const char *) action, length);
|
|
||||||
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
|
||||||
if (windows[i].onGroupAction != NULL)
|
|
||||||
windows[i].onGroupAction(&windows[i], m, groupnumber, peernumber, msg, length);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_groupinvite(Tox *m, int32_t friendnumber, uint8_t type, const uint8_t *group_pub_key, uint16_t length,
|
|
||||||
void *userdata)
|
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -190,7 +176,8 @@ void on_groupinvite(Tox *m, int32_t friendnumber, uint8_t type, const uint8_t *g
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata)
|
void on_group_namelistchange(Tox *m, uint32_t groupnumber, uint32_t peernumber, TOX_CONFERENCE_STATE_CHANGE change,
|
||||||
|
void *userdata)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
@ -200,7 +187,7 @@ void on_group_namelistchange(Tox *m, int groupnumber, int peernumber, uint8_t ch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_group_titlechange(Tox *m, int groupnumber, int peernumber, const uint8_t *title, uint8_t length,
|
void on_group_titlechange(Tox *m, uint32_t groupnumber, uint32_t peernumber, const uint8_t *title, size_t length,
|
||||||
void *userdata)
|
void *userdata)
|
||||||
{
|
{
|
||||||
char data[MAX_STR_SIZE + 1];
|
char data[MAX_STR_SIZE + 1];
|
||||||
|
@ -121,11 +121,10 @@ struct ToxWindow {
|
|||||||
void(*onNickChange)(ToxWindow *, Tox *, uint32_t, const char *, size_t);
|
void(*onNickChange)(ToxWindow *, Tox *, uint32_t, const char *, size_t);
|
||||||
void(*onStatusChange)(ToxWindow *, Tox *, uint32_t, TOX_USER_STATUS);
|
void(*onStatusChange)(ToxWindow *, Tox *, uint32_t, TOX_USER_STATUS);
|
||||||
void(*onStatusMessageChange)(ToxWindow *, uint32_t, const char *, size_t);
|
void(*onStatusMessageChange)(ToxWindow *, uint32_t, const char *, size_t);
|
||||||
void(*onGroupMessage)(ToxWindow *, Tox *, int, int, const char *, uint16_t);
|
void(*onGroupMessage)(ToxWindow *, Tox *, uint32_t, uint32_t, TOX_MESSAGE_TYPE, const char *, size_t);
|
||||||
void(*onGroupAction)(ToxWindow *, Tox *, int, int, const char *, uint16_t);
|
|
||||||
void(*onGroupInvite)(ToxWindow *, Tox *, int32_t, uint8_t, 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(*onGroupNamelistChange)(ToxWindow *, Tox *, uint32_t, uint32_t, TOX_CONFERENCE_STATE_CHANGE);
|
||||||
void(*onGroupTitleChange)(ToxWindow *, Tox *, int, int, const char *, uint8_t);
|
void(*onGroupTitleChange)(ToxWindow *, Tox *, uint32_t, uint32_t, const char *, size_t);
|
||||||
void(*onFileChunkRequest)(ToxWindow *, Tox *, uint32_t, uint32_t, uint64_t, size_t);
|
void(*onFileChunkRequest)(ToxWindow *, Tox *, uint32_t, uint32_t, uint64_t, size_t);
|
||||||
void(*onFileRecvChunk)(ToxWindow *, Tox *, uint32_t, uint32_t, uint64_t, const char *, size_t);
|
void(*onFileRecvChunk)(ToxWindow *, Tox *, uint32_t, uint32_t, uint64_t, const char *, size_t);
|
||||||
void(*onFileControl)(ToxWindow *, Tox *, uint32_t, uint32_t, TOX_FILE_CONTROL);
|
void(*onFileControl)(ToxWindow *, Tox *, uint32_t, uint32_t, TOX_FILE_CONTROL);
|
||||||
|
Loading…
Reference in New Issue
Block a user