1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-03 15:57:46 +02:00

more fixes

This commit is contained in:
Jfreegman 2013-09-22 04:32:51 -04:00
parent 2892f71877
commit 7fed456e3b
2 changed files with 15 additions and 18 deletions

View File

@ -19,7 +19,6 @@ extern uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
extern uint8_t num_frnd_requests; extern uint8_t num_frnd_requests;
extern uint8_t pending_grp_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE]; extern uint8_t pending_grp_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
extern uint8_t num_grp_requests;
/* command functions */ /* command functions */
void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv) void cmd_accept(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv)
@ -254,21 +253,21 @@ void cmd_join(WINDOW *window, ToxWindow *prompt, Tox *m, int argc, char **argv)
int num = atoi(argv[1]); int num = atoi(argv[1]);
if (num < 0 || num >= MAX_FRIENDS_NUM) { if (num < 0 || num >= MAX_FRIENDS_NUM) {
wprintw(window, "Invalid number.\n"); wprintw(window, "No pending group chat invite with that number.\n");
return; return;
} }
uint8_t *groupkey = pending_grp_requests[num]; uint8_t *groupkey = pending_grp_requests[num];
if (!groupkey || !strlen(groupkey)) { if (strlen(groupkey) != TOX_CLIENT_ID_SIZE) { /* Improve this test */
wprintw(window, "No group chat request with that number.\n"); wprintw(window, "No pending group chat invite with that number.\n");
return; return;
} }
int groupnum = tox_join_groupchat(m, num, groupkey); int groupnum = tox_join_groupchat(m, num, groupkey);
if (groupnum == -1) { if (groupnum == -1) {
wprintw(window, "Group chat failed to initialize.\n"); wprintw(window, "Group chat instance failed to initialize.\n");
return; return;
} }

View File

@ -17,8 +17,9 @@
uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE]; uint8_t pending_frnd_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
uint8_t num_frnd_requests = 0; uint8_t num_frnd_requests = 0;
/* One group chat request slot for each friend; slot is
overwritten on subsequent requests by the same friend. */
uint8_t pending_grp_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE]; uint8_t pending_grp_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
uint8_t num_grp_requests = 0;
static char prompt_buf[MAX_STR_SIZE] = {'\0'}; static char prompt_buf[MAX_STR_SIZE] = {'\0'};
static int prompt_buf_pos = 0; static int prompt_buf_pos = 0;
@ -66,10 +67,10 @@ int add_friend_req(uint8_t *public_key)
} }
/* Adds group chat invite to pending group chat requests. /* Adds group chat invite to pending group chat requests.
Returns friend number on success, -1 if queue is full or other error. */ Returns friend number on success, -1 if f_num is out of range. */
int add_group_req(uint8_t *group_pub_key, int f_num) int add_group_req(uint8_t *group_pub_key, int f_num)
{ {
if (num_grp_requests++ < MAX_GROUPCHAT_NUM) { if (f_num >= 0 && f_num < MAX_FRIENDS_NUM) {
memcpy(pending_grp_requests[f_num], group_pub_key, TOX_CLIENT_ID_SIZE); memcpy(pending_grp_requests[f_num], group_pub_key, TOX_CLIENT_ID_SIZE);
return f_num; return f_num;
} }
@ -217,15 +218,7 @@ static void prompt_onInit(ToxWindow *self, Tox *m)
static void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data, uint16_t length) static 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"); wprintw(self->window, "\nFriend request from:\n");
int i; int i;
for (i = 0; i < KEY_SIZE_BYTES; ++i) { for (i = 0; i < KEY_SIZE_BYTES; ++i) {
@ -233,8 +226,14 @@ static void prompt_onFriendRequest(ToxWindow *self, uint8_t *key, uint8_t *data,
} }
wprintw(self->window, "\n\nWith the message: %s\n\n", data); wprintw(self->window, "\n\nWith the message: %s\n\n", data);
wprintw(self->window, "Type \"/accept %d\" to accept it.\n", n); int n = add_friend_req(key);
if (n == -1) {
wprintw(self->window, "Friend request queue is full. Discarding request.\n");
return;
}
wprintw(self->window, "Type \"/accept %d\" to accept it.\n", n);
self->blink = true; self->blink = true;
beep(); beep();
} }
@ -267,7 +266,6 @@ static void prompt_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint
} }
wprintw(self->window, "Type \"/join %d\" to join the chat.\n", n); wprintw(self->window, "Type \"/join %d\" to join the chat.\n", n);
self->blink = true; self->blink = true;
beep(); beep();
} }