mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 16:23:26 +01:00
fixes
This commit is contained in:
parent
390cdc7b33
commit
b6bf0eb0a0
@ -26,15 +26,14 @@ extern int store_data(Tox *m, char *path);
|
||||
|
||||
int get_num_groupchats(void)
|
||||
{
|
||||
int count = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < group_chat_index; ++i) {
|
||||
if (groupchats[i].active)
|
||||
++count;
|
||||
for (i = 0; i <= group_chat_index; ++i) {
|
||||
if (!groupchats[i].active)
|
||||
return i;
|
||||
}
|
||||
|
||||
return count;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int init_groupchat_win(ToxWindow *prompt, Tox *m)
|
||||
@ -45,7 +44,7 @@ int init_groupchat_win(ToxWindow *prompt, Tox *m)
|
||||
if (!groupchats[i].active) {
|
||||
groupchats[i].active = true;
|
||||
groupchats[i].chatwin = add_window(m, new_groupchat(m, prompt, i));
|
||||
set_active_window(groupchats[i].chatwin);
|
||||
//set_active_window(groupchats[i].chatwin);
|
||||
|
||||
if (i == group_chat_index)
|
||||
++group_chat_index;
|
||||
@ -140,7 +139,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
|
||||
if (line[0] == '/') {
|
||||
if (close_win = !strncmp(line, "/close", strlen("/close"))) {
|
||||
set_active_window(0);
|
||||
int group_num = groupchats[self->num].chatwin;
|
||||
int group_num = self->num;
|
||||
delwin(ctx->linewin);
|
||||
del_window(self);
|
||||
close_groupchatwin(m, group_num);
|
||||
|
@ -3,4 +3,4 @@
|
||||
*/
|
||||
|
||||
int init_groupchat_win(ToxWindow *prompt, Tox *m);
|
||||
int get_num_groupchats(void);
|
||||
int get_num_groupchats(void);
|
||||
|
69
src/prompt.c
69
src/prompt.c
@ -18,7 +18,7 @@ extern char *DATA_FILE;
|
||||
uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
|
||||
uint8_t num_frnd_requests = 0;
|
||||
|
||||
uint8_t pending_grp_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
|
||||
uint8_t pending_grp_requests[MAX_GROUPCHAT_NUM][TOX_CLIENT_ID_SIZE];
|
||||
uint8_t num_grp_requests = 0;
|
||||
|
||||
static char prompt_buf[MAX_STR_SIZE] = {'\0'};
|
||||
@ -92,18 +92,28 @@ void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected)
|
||||
statusbar->is_online = is_connected;
|
||||
}
|
||||
|
||||
/* Adds friend request to pending friend requests. */
|
||||
/* Adds friend request to pending friend requests.
|
||||
Returns friend number on success, -1 if queue is full or other error. */
|
||||
int add_friend_req(uint8_t *public_key)
|
||||
{
|
||||
memcpy(pending_frnd_requests[num_frnd_requests++], public_key, TOX_CLIENT_ID_SIZE);
|
||||
return num_frnd_requests - 1;
|
||||
if (num_frnd_requests < MAX_FRIENDS_NUM) {
|
||||
memcpy(pending_frnd_requests[num_frnd_requests++], public_key, TOX_CLIENT_ID_SIZE);
|
||||
return num_frnd_requests - 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Adds group chat invite to pending group chat requests */
|
||||
/* Adds group chat invite to pending group chat requests.
|
||||
Returns group number on success, -1 if queue is full or other error. */
|
||||
int add_group_req(uint8_t *group_pub_key)
|
||||
{
|
||||
memcpy(pending_grp_requests[num_grp_requests++], group_pub_key, TOX_CLIENT_ID_SIZE);
|
||||
return num_grp_requests - 1;
|
||||
if (num_grp_requests < MAX_GROUPCHAT_NUM) {
|
||||
memcpy(pending_grp_requests[num_grp_requests++], group_pub_key, TOX_CLIENT_ID_SIZE);
|
||||
return num_grp_requests - 1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// XXX: FIX
|
||||
@ -143,13 +153,13 @@ void cmd_accept(ToxWindow *self, Tox *m, int argc, char **argv)
|
||||
return;
|
||||
}
|
||||
|
||||
num = tox_addfriend_norequest(m, pending_frnd_requests[num]);
|
||||
int friendnum = tox_addfriend_norequest(m, pending_frnd_requests[num]);
|
||||
|
||||
if (num == -1)
|
||||
if (friendnum == -1)
|
||||
wprintw(self->window, "Failed to add friend.\n");
|
||||
else {
|
||||
wprintw(self->window, "Friend accepted.\n");
|
||||
on_friendadded(m, num);
|
||||
wprintw(self->window, "Friend request accepted.\n");
|
||||
on_friendadded(m, friendnum);
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,7 +306,7 @@ void cmd_groupchat(ToxWindow *self, Tox *m, int argc, char **argv)
|
||||
{
|
||||
int ngc = get_num_groupchats();
|
||||
|
||||
if (ngc < 0 || ngc >= MAX_GROUPCHAT_NUM) {
|
||||
if (ngc < 0 || ngc > MAX_GROUPCHAT_NUM) {
|
||||
wprintw(self->window, "\nMaximum number of group chats has been reached.\n");
|
||||
return;
|
||||
}
|
||||
@ -357,9 +367,8 @@ void cmd_invite(ToxWindow *self, Tox *m, int argc, char **argv)
|
||||
|
||||
int friendnum = atoi(argv[1]);
|
||||
int groupnum = atoi(argv[2]);
|
||||
int n = tox_invite_friend(m, friendnum, groupnum);
|
||||
|
||||
if (n == -1) {
|
||||
if (tox_invite_friend(m, friendnum, groupnum) == -1) {
|
||||
wprintw(self->window, "Failed to invite friend.\n");
|
||||
return;
|
||||
}
|
||||
@ -386,10 +395,18 @@ void cmd_join(ToxWindow *self, Tox *m, int argc, char **argv)
|
||||
return;
|
||||
}
|
||||
|
||||
num = tox_join_groupchat(m, num, pending_grp_requests[num]);
|
||||
int groupnum = tox_join_groupchat(m, num, pending_grp_requests[num]);
|
||||
|
||||
if (num == -1 || init_groupchat_win(self, m) == -1)
|
||||
if (groupnum == -1) {
|
||||
wprintw(self->window, "Group chat failed to initialize.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (init_groupchat_win(self, m) == -1) {
|
||||
wprintw(self->window, "Group chat failed to initialize.\n");
|
||||
tox_del_groupchat(m, groupnum);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void cmd_msg(ToxWindow *self, Tox *m, int argc, char **argv)
|
||||
@ -484,7 +501,7 @@ void cmd_status(ToxWindow *self, Tox *m, int argc, char **argv)
|
||||
wprintw(self->window, "Messages must be enclosed in quotes.\n");
|
||||
return;
|
||||
}
|
||||
} else if (argc < 1 || argc > 2) {
|
||||
} else if (argc != 1) {
|
||||
wprintw(self->window, "Wrong number of arguments.\n");
|
||||
return;
|
||||
}
|
||||
@ -736,6 +753,12 @@ static void prompt_onInit(ToxWindow *self, Tox *m)
|
||||
void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data, uint16_t length)
|
||||
{
|
||||
int n = add_friend_req(key);
|
||||
|
||||
if (n == -1) {
|
||||
wprintw(self->window, "Friend request queue is full. Discarding request.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
wprintw(self->window, "\nFriend request from:\n");
|
||||
|
||||
int i;
|
||||
@ -753,16 +776,22 @@ void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data, uint16
|
||||
|
||||
void prompt_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint8_t *group_pub_key)
|
||||
{
|
||||
wprintw(self->window, "\nGroup chat invite from: %d\n", friendnumber);
|
||||
|
||||
int ngc = get_num_groupchats();
|
||||
if (ngc < 0 || ngc >= MAX_GROUPCHAT_NUM) {
|
||||
wprintw(self->window, "\nGroup chat invite from: %d\n", friendnumber);
|
||||
|
||||
if (ngc < 0 || ngc > MAX_GROUPCHAT_NUM) {
|
||||
wprintw(self->window, "\nMaximum number of group chats has been reached. Discarding invite.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int n = add_group_req(group_pub_key);
|
||||
|
||||
wprintw(self->window, "\nGroup chat invite from: %d\n", friendnumber);
|
||||
if (n == -1) {
|
||||
wprintw(self->window, "\nGroup chat queue is full. Discarding invite.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
wprintw(self->window, "Type \"join %d\" to join the chat.\n", n);
|
||||
|
||||
self->blink = true;
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#define MAX_WINDOWS_NUM 32
|
||||
#define MAX_FRIENDS_NUM 100
|
||||
#define MAX_GROUPCHAT_NUM 32
|
||||
#define MAX_GROUPCHAT_NUM 30
|
||||
#define MAX_STR_SIZE 256
|
||||
#define KEY_SIZE_BYTES 32
|
||||
#define TOXIC_MAX_NAME_LENGTH 30 /* Not to be confused with TOX_MAX_NAME_LENGTH */
|
||||
|
Loading…
Reference in New Issue
Block a user