Skip to content

Commit

Permalink
Rename: groupchats -> conferences
Browse files Browse the repository at this point in the history
This is in line with the toxcore API naming scheme and is in preparation
for the merge with the new groupchat implementation
  • Loading branch information
JFreegman committed Nov 6, 2020
1 parent 32eb7d3 commit d9b9b87
Show file tree
Hide file tree
Showing 28 changed files with 294 additions and 293 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LDFLAGS ?=
LDFLAGS += ${USER_LDFLAGS}

OBJ = autocomplete.o avatars.o bootstrap.o chat.o chat_commands.o configdir.o curl_util.o execute.o
OBJ += file_transfers.o friendlist.o global_commands.o group_commands.o groupchat.o help.o input.o
OBJ += file_transfers.o friendlist.o global_commands.o conference_commands.o conference.o help.o input.o
OBJ += line_info.o log.o message_queue.o misc_tools.o name_lookup.o notify.o prompt.o qr_code.o settings.o
OBJ += term_mplex.o toxic.o toxic_strings.o windows.o

Expand Down
31 changes: 16 additions & 15 deletions src/chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static const char *chat_cmd_list[] = {
"/close",
"/connect",
"/exit",
"/group",
"/conference",
"/help",
"/invite",
"/join",
Expand Down Expand Up @@ -714,41 +714,42 @@ static void chat_onFileRecv(ToxWindow *self, Tox *m, uint32_t friendnum, uint32_
}
}

static void chat_onGroupInvite(ToxWindow *self, Tox *m, int32_t friendnumber, uint8_t type, const char *group_pub_key,
uint16_t length)
static void chat_onConferenceInvite(ToxWindow *self, Tox *m, int32_t friendnumber, uint8_t type,
const char *conference_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);
if (Friends.list[friendnumber].conference_invite.key != NULL) {
free(Friends.list[friendnumber].conference_invite.key);
}

char *k = malloc(length);

if (k == NULL) {
exit_toxic_err("Failed in chat_onGroupInvite", FATALERR_MEMORY);
exit_toxic_err("Failed in chat_onConferenceInvite", 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;
memcpy(k, conference_pub_key, length);
Friends.list[friendnumber].conference_invite.key = k;
Friends.list[friendnumber].conference_invite.pending = true;
Friends.list[friendnumber].conference_invite.length = length;
Friends.list[friendnumber].conference_invite.type = type;

sound_notify(self, generic_message, NT_WNDALERT_2 | user_settings->bell_on_invite, 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");
box_silent_notify2(self, NT_WNDALERT_2 | NT_NOFOCUS, self->active_box, "invites you to join conference");
} else {
box_silent_notify(self, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name, "invites you to join group chat");
box_silent_notify(self, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name, "invites you to join conference");
}

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, "%s has invited you to a conference.", name);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Type \"/join\" to join the chat.");
}

Expand Down Expand Up @@ -1402,7 +1403,7 @@ ToxWindow *new_chat(Tox *m, uint32_t friendnum)
ret->onMessage = &chat_onMessage;
ret->onConnectionChange = &chat_onConnectionChange;
ret->onTypingChange = & chat_onTypingChange;
ret->onGroupInvite = &chat_onGroupInvite;
ret->onConferenceInvite = &chat_onConferenceInvite;
ret->onNickChange = &chat_onNickChange;
ret->onStatusChange = &chat_onStatusChange;
ret->onStatusMessageChange = &chat_onStatusMessageChange;
Expand Down
42 changes: 21 additions & 21 deletions src/chat_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "friendlist.h"
#include "execute.h"
#include "line_info.h"
#include "groupchat.h"
#include "conference.h"
#include "chat.h"
#include "file_transfers.h"

Expand Down Expand Up @@ -80,33 +80,33 @@ void cmd_cancelfile(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
close_file_transfer(self, m, ft, TOX_FILE_CONTROL_CANCEL, msg, silent);
}

void cmd_groupinvite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_conference_invite(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
UNUSED_VAR(window);

if (argc < 1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group number required.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Conference number required.");
return;
}

long int groupnum = strtol(argv[1], NULL, 10);
long int conferencenum = strtol(argv[1], NULL, 10);

if ((groupnum == 0 && strcmp(argv[1], "0")) || groupnum < 0 || groupnum == LONG_MAX) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid group number.");
if ((conferencenum == 0 && strcmp(argv[1], "0")) || conferencenum < 0 || conferencenum == LONG_MAX) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invalid conference number.");
return;
}

Tox_Err_Conference_Invite err;

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);
if (!tox_conference_invite(m, self->num, conferencenum, &err)) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Failed to invite contact to conference (error %d)", err);
return;
}

line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invited contact to Group %ld.", groupnum);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Invited contact to Conference %ld.", conferencenum);
}

void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
void cmd_conference_join(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{
UNUSED_VAR(window);
UNUSED_VAR(argc);
Expand All @@ -117,32 +117,32 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar
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;
const char *conferencekey = Friends.list[self->num].conference_invite.key;
uint16_t length = Friends.list[self->num].conference_invite.length;
uint8_t type = Friends.list[self->num].conference_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.");
if (!Friends.list[self->num].conference_invite.pending) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "No pending conference chat invite.");
return;
}

if (type != TOX_CONFERENCE_TYPE_TEXT) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Toxic does not support audio groups.");
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Toxic does not support audio conferences.");
return;
}

Tox_Err_Conference_Join err;

uint32_t groupnum = tox_conference_join(m, self->num, (const uint8_t *) groupkey, length, &err);
uint32_t conferencenum = tox_conference_join(m, self->num, (const uint8_t *) conferencekey, length, &err);

if (err != TOX_ERR_CONFERENCE_JOIN_OK) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat instance failed to initialize (error %d)", err);
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Conference instance failed to initialize (error %d)", err);
return;
}

if (init_groupchat_win(m, groupnum, type, NULL, 0) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Group chat window failed to initialize.");
tox_conference_delete(m, groupnum, NULL);
if (init_conference_win(m, conferencenum, type, NULL, 0) == -1) {
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Conference window failed to initialize.");
tox_conference_delete(m, conferencenum, NULL);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/chat_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#include "toxic.h"

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_conference_invite(WINDOW *, ToxWindow *, Tox *, int argc, char (*argv)[MAX_STR_SIZE]);
void cmd_conference_join(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]);

Expand Down
Loading

0 comments on commit d9b9b87

Please sign in to comment.