mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Group chats now have types.
This commit is contained in:
parent
5715a94061
commit
97742ed1e9
|
@ -629,11 +629,13 @@ static int add_conn_to_groupchat(Group_Chats *g_c, int friendcon_id, int groupnu
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Creates a new groupchat and puts it in the chats array.
|
/* Creates a new groupchat and puts it in the chats array.
|
||||||
|
*
|
||||||
|
* type is one of GROUPCHAT_TYPE_*
|
||||||
*
|
*
|
||||||
* return group number on success.
|
* return group number on success.
|
||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
*/
|
*/
|
||||||
int add_groupchat(Group_Chats *g_c)
|
int add_groupchat(Group_Chats *g_c, uint8_t type)
|
||||||
{
|
{
|
||||||
int groupnumber = create_group_chat(g_c);
|
int groupnumber = create_group_chat(g_c);
|
||||||
|
|
||||||
|
@ -644,7 +646,8 @@ int add_groupchat(Group_Chats *g_c)
|
||||||
|
|
||||||
g->status = GROUPCHAT_STATUS_CONNECTED;
|
g->status = GROUPCHAT_STATUS_CONNECTED;
|
||||||
g->number_joined = -1;
|
g->number_joined = -1;
|
||||||
new_symmetric_key(g->identifier);
|
new_symmetric_key(g->identifier + 1);
|
||||||
|
g->identifier[0] = type;
|
||||||
g->peer_number = 0; /* Founder is peer 0. */
|
g->peer_number = 0; /* Founder is peer 0. */
|
||||||
memcpy(g->real_pk, g_c->m->net_crypto->self_public_key, crypto_box_PUBLICKEYBYTES);
|
memcpy(g->real_pk, g_c->m->net_crypto->self_public_key, crypto_box_PUBLICKEYBYTES);
|
||||||
int peer_index = addpeer(g_c, groupnumber, g->real_pk, g_c->m->dht->self_public_key, 0);
|
int peer_index = addpeer(g_c, groupnumber, g->real_pk, g_c->m->dht->self_public_key, 0);
|
||||||
|
@ -845,15 +848,20 @@ int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber)
|
||||||
static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t group_num);
|
static unsigned int send_peer_query(Group_Chats *g_c, int friendcon_id, uint16_t group_num);
|
||||||
|
|
||||||
/* Join a group (you need to have been invited first.)
|
/* Join a group (you need to have been invited first.)
|
||||||
|
*
|
||||||
|
* expected_type is the groupchat type we expect the chat we are joining is.
|
||||||
*
|
*
|
||||||
* returns group number on success
|
* returns group number on success
|
||||||
* returns -1 on failure.
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int join_groupchat(Group_Chats *g_c, int32_t friendnumber, const uint8_t *data, uint16_t length)
|
int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
if (length != sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH)
|
if (length != sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (data[sizeof(uint16_t)] != expected_type)
|
||||||
|
return -1;
|
||||||
|
|
||||||
int friendcon_id = getfriendcon_id(g_c->m, friendnumber);
|
int friendcon_id = getfriendcon_id(g_c->m, friendnumber);
|
||||||
|
|
||||||
if (friendcon_id == -1)
|
if (friendcon_id == -1)
|
||||||
|
@ -899,12 +907,12 @@ int join_groupchat(Group_Chats *g_c, int32_t friendnumber, const uint8_t *data,
|
||||||
|
|
||||||
/* Set the callback for group invites.
|
/* Set the callback for group invites.
|
||||||
*
|
*
|
||||||
* Function(Group_Chats *g_c, int32_t friendnumber, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*
|
*
|
||||||
* data of length is what needs to be passed to join_groupchat().
|
* data of length is what needs to be passed to join_groupchat().
|
||||||
*/
|
*/
|
||||||
void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t,
|
void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, uint8_t, const uint8_t *,
|
||||||
void *), void *userdata)
|
uint16_t, void *), void *userdata)
|
||||||
{
|
{
|
||||||
g_c->invite_callback = function;
|
g_c->invite_callback = function;
|
||||||
g_c->invite_callback_userdata = userdata;
|
g_c->invite_callback_userdata = userdata;
|
||||||
|
@ -1086,7 +1094,8 @@ static void handle_friend_invite_packet(Messenger *m, int32_t friendnumber, cons
|
||||||
|
|
||||||
if (groupnumber == -1) {
|
if (groupnumber == -1) {
|
||||||
if (g_c->invite_callback)
|
if (g_c->invite_callback)
|
||||||
g_c->invite_callback(m, friendnumber, invite_data, invite_length, g_c->invite_callback_userdata);
|
g_c->invite_callback(m, friendnumber, *(invite_data + sizeof(uint16_t)), invite_data, invite_length,
|
||||||
|
g_c->invite_callback_userdata);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -2002,6 +2011,7 @@ void kill_groupchats(Group_Chats *g_c)
|
||||||
|
|
||||||
m_callback_group_invite(g_c->m, NULL);
|
m_callback_group_invite(g_c->m, NULL);
|
||||||
g_c->m->group_chat_object = 0;
|
g_c->m->group_chat_object = 0;
|
||||||
|
free(g_c->av_object);
|
||||||
free(g_c);
|
free(g_c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,11 @@ enum {
|
||||||
GROUPCHAT_STATUS_CONNECTED
|
GROUPCHAT_STATUS_CONNECTED
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
GROUPCHAT_TYPE_TEXT,
|
||||||
|
GROUPCHAT_TYPE_AV
|
||||||
|
};
|
||||||
|
|
||||||
#define MAX_LOSSY_COUNT 256
|
#define MAX_LOSSY_COUNT 256
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -55,7 +60,7 @@ typedef struct {
|
||||||
|
|
||||||
#define DESIRED_CLOSE_CONNECTIONS 4
|
#define DESIRED_CLOSE_CONNECTIONS 4
|
||||||
#define MAX_GROUP_CONNECTIONS 16
|
#define MAX_GROUP_CONNECTIONS 16
|
||||||
#define GROUP_IDENTIFIER_LENGTH crypto_box_KEYBYTES /* So we can use new_symmetric_key(...) to fill it */
|
#define GROUP_IDENTIFIER_LENGTH (1 + crypto_box_KEYBYTES) /* crypto_box_KEYBYTES so we can use new_symmetric_key(...) to fill it */
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
GROUPCHAT_CLOSE_NONE,
|
GROUPCHAT_CLOSE_NONE,
|
||||||
|
@ -107,7 +112,7 @@ typedef struct {
|
||||||
Group_c *chats;
|
Group_c *chats;
|
||||||
uint32_t num_chats;
|
uint32_t num_chats;
|
||||||
|
|
||||||
void (*invite_callback)(Messenger *m, int32_t, const uint8_t *, uint16_t, void *);
|
void (*invite_callback)(Messenger *m, int32_t, uint8_t, const uint8_t *, uint16_t, void *);
|
||||||
void *invite_callback_userdata;
|
void *invite_callback_userdata;
|
||||||
void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *);
|
void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *);
|
||||||
void *message_callback_userdata;
|
void *message_callback_userdata;
|
||||||
|
@ -119,16 +124,18 @@ typedef struct {
|
||||||
struct {
|
struct {
|
||||||
int (*function)(void *, int, int, void *, const uint8_t *, uint16_t);
|
int (*function)(void *, int, int, void *, const uint8_t *, uint16_t);
|
||||||
} lossy_packethandlers[256];
|
} lossy_packethandlers[256];
|
||||||
|
|
||||||
|
void *av_object;
|
||||||
} Group_Chats;
|
} Group_Chats;
|
||||||
|
|
||||||
/* Set the callback for group invites.
|
/* Set the callback for group invites.
|
||||||
*
|
*
|
||||||
* Function(Group_Chats *g_c, int32_t friendnumber, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Group_Chats *g_c, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*
|
*
|
||||||
* data of length is what needs to be passed to join_groupchat().
|
* data of length is what needs to be passed to join_groupchat().
|
||||||
*/
|
*/
|
||||||
void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t,
|
void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, uint8_t, const uint8_t *,
|
||||||
void *), void *userdata);
|
uint16_t, void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for group messages.
|
/* Set the callback for group messages.
|
||||||
*
|
*
|
||||||
|
@ -158,11 +165,13 @@ void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenge
|
||||||
void *userdata);
|
void *userdata);
|
||||||
|
|
||||||
/* Creates a new groupchat and puts it in the chats array.
|
/* Creates a new groupchat and puts it in the chats array.
|
||||||
|
*
|
||||||
|
* type is one of GROUPCHAT_TYPE_*
|
||||||
*
|
*
|
||||||
* return group number on success.
|
* return group number on success.
|
||||||
* return -1 on failure.
|
* return -1 on failure.
|
||||||
*/
|
*/
|
||||||
int add_groupchat(Group_Chats *g_c);
|
int add_groupchat(Group_Chats *g_c, uint8_t type);
|
||||||
|
|
||||||
/* Delete a groupchat from the chats array.
|
/* Delete a groupchat from the chats array.
|
||||||
*
|
*
|
||||||
|
@ -186,11 +195,13 @@ int group_peername(const Group_Chats *g_c, int groupnumber, int peernumber, uint
|
||||||
int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber);
|
int invite_friend(Group_Chats *g_c, int32_t friendnumber, int groupnumber);
|
||||||
|
|
||||||
/* Join a group (you need to have been invited first.)
|
/* Join a group (you need to have been invited first.)
|
||||||
|
*
|
||||||
|
* expected_type is the groupchat type we expect the chat we are joining is.
|
||||||
*
|
*
|
||||||
* returns group number on success
|
* returns group number on success
|
||||||
* returns -1 on failure.
|
* returns -1 on failure.
|
||||||
*/
|
*/
|
||||||
int join_groupchat(Group_Chats *g_c, int32_t friendnumber, const uint8_t *data, uint16_t length);
|
int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type, const uint8_t *data, uint16_t length);
|
||||||
|
|
||||||
/* send a group message
|
/* send a group message
|
||||||
* return 0 on success
|
* return 0 on success
|
||||||
|
|
|
@ -551,12 +551,12 @@ int tox_send_lossless_packet(const Tox *tox, int32_t friendnumber, const uint8_t
|
||||||
|
|
||||||
/* Set the callback for group invites.
|
/* Set the callback for group invites.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int32_t friendnumber, uint8_t *data, uint16_t length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*
|
*
|
||||||
* data of length is what needs to be passed to join_groupchat().
|
* data of length is what needs to be passed to join_groupchat().
|
||||||
*/
|
*/
|
||||||
void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, const uint8_t *, uint16_t, void *),
|
void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, const uint8_t *, uint16_t,
|
||||||
void *userdata)
|
void *), void *userdata)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
g_callback_group_invite(m->group_chat_object, function, userdata);
|
g_callback_group_invite(m->group_chat_object, function, userdata);
|
||||||
|
@ -603,7 +603,7 @@ void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int
|
||||||
int tox_add_groupchat(Tox *tox)
|
int tox_add_groupchat(Tox *tox)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return add_groupchat(m->group_chat_object);
|
return add_groupchat(m->group_chat_object, GROUPCHAT_TYPE_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete a groupchat from the chats array.
|
/* Delete a groupchat from the chats array.
|
||||||
|
@ -648,7 +648,7 @@ int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber)
|
||||||
int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length)
|
int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length)
|
||||||
{
|
{
|
||||||
Messenger *m = tox;
|
Messenger *m = tox;
|
||||||
return join_groupchat(m->group_chat_object, friendnumber, data, length);
|
return join_groupchat(m->group_chat_object, friendnumber, GROUPCHAT_TYPE_TEXT, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* send a group message
|
/* send a group message
|
||||||
|
|
|
@ -417,14 +417,26 @@ int tox_send_lossless_packet(const Tox *tox, int32_t friendnumber, const uint8_t
|
||||||
|
|
||||||
/**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/
|
/**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/
|
||||||
|
|
||||||
|
/* Group chat types for tox_callback_group_invite function.
|
||||||
|
*
|
||||||
|
* TOX_GROUPCHAT_TYPE_TEXT groupchats must be accepted with the tox_join_groupchat() function.
|
||||||
|
* The function to accept TOX_GROUPCHAT_TYPE_AV is in toxav.
|
||||||
|
*/
|
||||||
|
enum {
|
||||||
|
TOX_GROUPCHAT_TYPE_TEXT,
|
||||||
|
TOX_GROUPCHAT_TYPE_AV
|
||||||
|
};
|
||||||
|
|
||||||
/* Set the callback for group invites.
|
/* Set the callback for group invites.
|
||||||
*
|
*
|
||||||
* Function(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length, void *userdata)
|
* Function(Tox *tox, int32_t friendnumber, uint8_t type, uint8_t *data, uint16_t length, void *userdata)
|
||||||
*
|
*
|
||||||
* data of length is what needs to be passed to join_groupchat().
|
* data of length is what needs to be passed to join_groupchat().
|
||||||
|
*
|
||||||
|
* for what type means see the enum right above this comment.
|
||||||
*/
|
*/
|
||||||
void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int32_t, const uint8_t *, uint16_t, void *),
|
void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, const uint8_t *, uint16_t,
|
||||||
void *userdata);
|
void *), void *userdata);
|
||||||
|
|
||||||
/* Set the callback for group messages.
|
/* Set the callback for group messages.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue
Block a user