mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 21:03:02 +01:00
simplify pending groupchat handling
This commit is contained in:
parent
9b7b401455
commit
be88c89e09
29
src/chat.c
29
src/chat.c
@ -17,22 +17,6 @@
|
||||
extern char *DATA_FILE;
|
||||
extern int store_data(Tox *m, char *path);
|
||||
|
||||
/* One group chat request slot for each friend; slot is
|
||||
overwritten on subsequent requests by the same friend. */
|
||||
extern uint8_t pending_grp_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
|
||||
|
||||
/* Adds group chat invite to pending group chat requests.
|
||||
Returns friend number on success, -1 if f_num is out of range. */
|
||||
static int add_group_request(uint8_t *group_pub_key, int f_num)
|
||||
{
|
||||
if (f_num >= 0 && f_num < MAX_FRIENDS_NUM) {
|
||||
memcpy(pending_grp_requests[f_num], group_pub_key, TOX_CLIENT_ID_SIZE);
|
||||
return f_num;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint16_t len)
|
||||
{
|
||||
if (self->num != num)
|
||||
@ -159,7 +143,7 @@ static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int num, uint8_t fil
|
||||
strcat(filename, d);
|
||||
filename[len + strlen(d)] = '\0';
|
||||
|
||||
if (count >= 999999) {
|
||||
if (count > 999999) {
|
||||
wprintw(ctx->history, "Error saving file to disk.\n");
|
||||
return;
|
||||
}
|
||||
@ -229,7 +213,7 @@ static void chat_onFileData(ToxWindow *self, Tox *m, int num, uint8_t filenum, u
|
||||
|
||||
static void chat_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint8_t *group_pub_key)
|
||||
{
|
||||
if (friendnumber < 0)
|
||||
if (self->num != friendnumber)
|
||||
return;
|
||||
|
||||
ChatContext *ctx = (ChatContext *) self->chatwin;
|
||||
@ -247,14 +231,9 @@ static void chat_onGroupInvite(ToxWindow *self, Tox *m, int friendnumber, uint8_
|
||||
return;
|
||||
}
|
||||
|
||||
int n = add_group_request(group_pub_key, friendnumber);
|
||||
memcpy(friends[friendnumber].pending_groupchat, group_pub_key, TOX_CLIENT_ID_SIZE);
|
||||
|
||||
if (n == -1) {
|
||||
wprintw(ctx->history, "Something bad happened. Discarding invite.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
wprintw(ctx->history, "Type \"/join %d\" to join the chat.\n", n);
|
||||
wprintw(ctx->history, "Type \"/join\" to join the chat.\n");
|
||||
self->blink = true;
|
||||
beep();
|
||||
}
|
||||
|
@ -12,8 +12,6 @@
|
||||
#include "toxic_windows.h"
|
||||
#include "misc_tools.h"
|
||||
|
||||
extern uint8_t pending_grp_requests[MAX_FRIENDS_NUM][TOX_CLIENT_ID_SIZE];
|
||||
|
||||
void cmd_chat_help(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
wattron(window, COLOR_PAIR(CYAN) | A_BOLD);
|
||||
@ -23,10 +21,10 @@ void cmd_chat_help(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc,
|
||||
wprintw(window, " /status <type> <message> : Set your status with optional note\n");
|
||||
wprintw(window, " /note <message> : Set a personal note\n");
|
||||
wprintw(window, " /nick <nickname> : Set your nickname\n");
|
||||
wprintw(window, " /invite <n> : Invite friend to a groupchat\n");
|
||||
wprintw(window, " /invite <n> : Invite friend to a group chat\n");
|
||||
wprintw(window, " /me <action> : Do an action\n");
|
||||
wprintw(window, " /myid : Print your ID\n");
|
||||
wprintw(window, " /join <n> : Join a group chat\n");
|
||||
wprintw(window, " /join : Join a pending group chat\n");
|
||||
wprintw(window, " /clear : Clear the screen\n");
|
||||
wprintw(window, " /close : Close the current chat window\n");
|
||||
wprintw(window, " /sendfile <filepath> : Send a file\n");
|
||||
@ -65,26 +63,14 @@ void cmd_groupinvite(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int arg
|
||||
|
||||
void cmd_join_group(WINDOW *window, ToxWindow *prompt, Tox *m, int num, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
if (argc != 1) {
|
||||
wprintw(window, "Invalid syntax.\n");
|
||||
return;
|
||||
}
|
||||
uint8_t *groupkey = friends[num].pending_groupchat;
|
||||
|
||||
int g_num = atoi(argv[1]);
|
||||
|
||||
if ((g_num == 0 && strcmp(argv[1], "0")) || g_num >= MAX_FRIENDS_NUM) {
|
||||
wprintw(window, "No pending group chat invite with that number.\n");
|
||||
if (groupkey[0] == '\0') {
|
||||
wprintw(window, "No pending group chat invite.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *groupkey = pending_grp_requests[g_num];
|
||||
|
||||
if (!strlen(groupkey)) {
|
||||
wprintw(window, "No pending group chat invite with that number.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
int groupnum = tox_join_groupchat(m, g_num, groupkey);
|
||||
int groupnum = tox_join_groupchat(m, num, groupkey);
|
||||
|
||||
if (groupnum == -1) {
|
||||
wprintw(window, "Group chat instance failed to initialize.\n");
|
||||
|
@ -111,6 +111,7 @@ int friendlist_onFriendAdded(Tox *m, int num)
|
||||
friends[i].online = false;
|
||||
friends[i].status = TOX_USERSTATUS_NONE;
|
||||
friends[i].namelength = tox_getname(m, num, friends[i].name);
|
||||
memset(friends[i].pending_groupchat, 0, TOX_CLIENT_ID_SIZE);
|
||||
|
||||
if (friends[i].namelength == -1 || friends[i].name[0] == '\0') {
|
||||
strcpy((char *) friends[i].name, UNKNOWN_NAME);
|
||||
|
@ -128,6 +128,7 @@ typedef struct {
|
||||
uint16_t namelength;
|
||||
uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH];
|
||||
uint16_t statusmsg_len;
|
||||
uint8_t pending_groupchat[TOX_CLIENT_ID_SIZE];
|
||||
int num;
|
||||
int chatwin;
|
||||
bool active;
|
||||
|
@ -16,10 +16,6 @@ static ToxWindow *active_window;
|
||||
static ToxWindow *prompt;
|
||||
static Tox *m;
|
||||
|
||||
/* 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] = {0};
|
||||
|
||||
/* CALLBACKS START */
|
||||
void on_request(uint8_t *public_key, uint8_t *data, uint16_t length, void *userdata)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user