mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Removed send_group_message_packet and its callback function from
Messenger.
This commit is contained in:
parent
964fcacb32
commit
230a65c91f
|
@ -999,14 +999,6 @@ void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_
|
|||
m->group_invite = function;
|
||||
}
|
||||
|
||||
/* Set the callback for group messages.
|
||||
*
|
||||
* Function(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length)
|
||||
*/
|
||||
void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t))
|
||||
{
|
||||
m->group_message = function;
|
||||
}
|
||||
|
||||
/* Send a group invite packet.
|
||||
*
|
||||
|
@ -1018,17 +1010,6 @@ int send_group_invite_packet(const Messenger *m, int32_t friendnumber, const uin
|
|||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_INVITE_GROUPCHAT, data, length, 0);
|
||||
}
|
||||
|
||||
/* Send a group message packet.
|
||||
*
|
||||
* return 1 on success
|
||||
* return 0 on failure
|
||||
*/
|
||||
int send_group_message_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length)
|
||||
{
|
||||
return write_cryptpacket_id(m, friendnumber, PACKET_ID_MESSAGE_GROUPCHAT, data, length, 0);
|
||||
}
|
||||
|
||||
|
||||
/****************FILE SENDING*****************/
|
||||
|
||||
|
||||
|
@ -1230,7 +1211,8 @@ int file_data(const Messenger *m, int32_t friendnumber, uint8_t filenumber, cons
|
|||
return -1;
|
||||
|
||||
/* Prevent file sending from filling up the entire buffer preventing messages from being sent. TODO: remove */
|
||||
if (crypto_num_free_sendqueue_slots(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, m->friendlist[friendnumber].friendcon_id)) < MIN_SLOTS_FREE)
|
||||
if (crypto_num_free_sendqueue_slots(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
|
||||
m->friendlist[friendnumber].friendcon_id)) < MIN_SLOTS_FREE)
|
||||
return -1;
|
||||
|
||||
uint8_t packet[MAX_CRYPTO_DATA_SIZE];
|
||||
|
@ -2125,16 +2107,6 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len)
|
|||
break;
|
||||
}
|
||||
|
||||
case PACKET_ID_MESSAGE_GROUPCHAT: {
|
||||
if (data_length == 0)
|
||||
break;
|
||||
|
||||
if (m->group_message)
|
||||
(*m->group_message)(m, i, data, data_length);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case PACKET_ID_FILE_SENDREQUEST: {
|
||||
if (data_length < 1 + sizeof(uint64_t) + 1)
|
||||
break;
|
||||
|
|
|
@ -729,12 +729,6 @@ void m_callback_avatar_data(Messenger *m, void (*function)(Messenger *m, int32_t
|
|||
*/
|
||||
void m_callback_group_invite(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t));
|
||||
|
||||
/* Set the callback for group messages.
|
||||
*
|
||||
* Function(Messenger *m, int32_t friendnumber, uint8_t *data, uint16_t length)
|
||||
*/
|
||||
void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int32_t, const uint8_t *, uint16_t));
|
||||
|
||||
/* Send a group invite packet.
|
||||
*
|
||||
* return 1 on success
|
||||
|
@ -742,13 +736,6 @@ void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int32
|
|||
*/
|
||||
int send_group_invite_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length);
|
||||
|
||||
/* Send a group message packet.
|
||||
*
|
||||
* return 1 on success
|
||||
* return 0 on failure
|
||||
*/
|
||||
int send_group_message_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length);
|
||||
|
||||
/****************FILE SENDING*****************/
|
||||
|
||||
|
||||
|
|
|
@ -223,6 +223,8 @@ static int addpeer(Group_c *chat, const uint8_t *client_id, uint16_t peer_number
|
|||
return (chat->numpeers - 1);
|
||||
}
|
||||
|
||||
static int handle_packet(void *object, int number, uint8_t *data, uint16_t length);
|
||||
|
||||
/* Add friend to group chat.
|
||||
*
|
||||
* return 0 on success
|
||||
|
@ -246,7 +248,7 @@ static int add_friend_to_groupchat(Group_Chats *g_c, int32_t friendnumber, int g
|
|||
continue;
|
||||
}
|
||||
|
||||
if (g->close[i].type == GROUPCHAT_CLOSE_FRIEND && g->close[i].number == (uint32_t)friendnumber) {
|
||||
if (g->close[i].type == GROUPCHAT_CLOSE_CONNECTION && g->close[i].number == (uint32_t)friendnumber) {
|
||||
g->close[i].group_number = other_groupnum; /* update groupnum. */
|
||||
return 0; /* Already in list. */
|
||||
}
|
||||
|
@ -257,9 +259,13 @@ static int add_friend_to_groupchat(Group_Chats *g_c, int32_t friendnumber, int g
|
|||
if (ind == MAX_GROUP_CONNECTIONS)
|
||||
return -1;
|
||||
|
||||
g->close[ind].type = GROUPCHAT_CLOSE_FRIEND;
|
||||
g->close[ind].type = GROUPCHAT_CLOSE_CONNECTION;
|
||||
g->close[ind].number = friendnumber;
|
||||
g->close[ind].group_number = other_groupnum;
|
||||
int friendcon_id = g_c->m->friendlist[friendnumber].friendcon_id;
|
||||
//TODO
|
||||
friend_connection_callbacks(g_c->m->fr_c, friendcon_id, GROUPCHAT_CALLBACK_INDEX, 0, &handle_packet, 0, g_c->m,
|
||||
friendnumber);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -300,6 +306,23 @@ int del_groupchat(Group_Chats *g_c, int groupnumber)
|
|||
return wipe_group_chat(g_c, groupnumber);
|
||||
}
|
||||
|
||||
/* Send a group message packet.
|
||||
*
|
||||
* return 1 on success
|
||||
* return 0 on failure
|
||||
*/
|
||||
int send_group_message_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint16_t length)
|
||||
{
|
||||
if (length >= MAX_CRYPTO_DATA_SIZE)
|
||||
return 0;
|
||||
|
||||
uint8_t packet[1 + length];
|
||||
packet[0] = PACKET_ID_MESSAGE_GROUPCHAT;
|
||||
memcpy(packet + 1, data, length);
|
||||
return write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
|
||||
m->friendlist[friendnumber].friendcon_id), packet, sizeof(packet), 0) != -1;
|
||||
}
|
||||
|
||||
#define INVITE_PACKET_SIZE (1 + sizeof(uint16_t) + GROUP_IDENTIFIER_LENGTH)
|
||||
#define INVITE_ID 0
|
||||
|
||||
|
@ -464,7 +487,7 @@ static int friend_in_close(Group_c *g, int32_t friendnumber)
|
|||
int i;
|
||||
|
||||
for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) {
|
||||
if (g->close[i].type != GROUPCHAT_CLOSE_FRIEND)
|
||||
if (g->close[i].type != GROUPCHAT_CLOSE_CONNECTION)
|
||||
continue;
|
||||
|
||||
if (g->close[i].number != (uint32_t)friendnumber)
|
||||
|
@ -649,6 +672,31 @@ static void handle_friend_message_packet(Messenger *m, int32_t friendnumber, con
|
|||
handle_message_packet_group(g_c, groupnumber, data, length, index);
|
||||
}
|
||||
|
||||
static int handle_packet(void *object, int number, uint8_t *data, uint16_t length)
|
||||
{
|
||||
if (length <= 1)
|
||||
return -1;
|
||||
|
||||
switch (data[0]) {
|
||||
case PACKET_ID_INVITE_GROUPCHAT: {
|
||||
handle_friend_invite_packet(object, number, data + 1, length - 1);
|
||||
break;
|
||||
}
|
||||
|
||||
case PACKET_ID_MESSAGE_GROUPCHAT: {
|
||||
handle_friend_message_packet(object, number, data + 1, length - 1);
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Create new groupchat instance. */
|
||||
Group_Chats *new_groupchats(Messenger *m)
|
||||
{
|
||||
|
@ -663,7 +711,6 @@ Group_Chats *new_groupchats(Messenger *m)
|
|||
temp->m = m;
|
||||
m->group_chat_object = temp;
|
||||
m_callback_group_invite(m, &handle_friend_invite_packet);
|
||||
m_callback_group_message(m, &handle_friend_message_packet);
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
|
|
@ -56,8 +56,7 @@ typedef struct {
|
|||
|
||||
enum {
|
||||
GROUPCHAT_CLOSE_NONE,
|
||||
GROUPCHAT_CLOSE_FRIEND,
|
||||
GROUPCHAT_CLOSE_GROUPCON
|
||||
GROUPCHAT_CLOSE_CONNECTION
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
|
Loading…
Reference in New Issue
Block a user