mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Added function to get the number of peers and list of names for group chats.
This commit is contained in:
parent
2079cbc2db
commit
d2b56faded
|
@ -974,13 +974,25 @@ void print_invite(Tox *m, int friendnumber, uint8_t *group_public_key, void *use
|
||||||
tox_join_groupchat(m, friendnumber, group_public_key));
|
tox_join_groupchat(m, friendnumber, group_public_key));
|
||||||
new_lines(msg);
|
new_lines(msg);
|
||||||
}
|
}
|
||||||
|
void print_groupchatpeers(Tox *m, int groupnumber)
|
||||||
|
{
|
||||||
|
char msg[256];
|
||||||
|
int num = tox_group_number_peers(m, groupnumber);
|
||||||
|
if (num == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint8_t names[num][TOX_MAX_NAME_LENGTH];
|
||||||
|
tox_group_copy_names(m, groupnumber, names, num);
|
||||||
|
uint32_t i;
|
||||||
|
for (i = 0; i < num; ++i)
|
||||||
|
new_lines(names[i]);
|
||||||
|
}
|
||||||
void print_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message, uint16_t length, void *userdata)
|
void print_groupmessage(Tox *m, int groupnumber, int peernumber, uint8_t *message, uint16_t length, void *userdata)
|
||||||
{
|
{
|
||||||
char msg[256 + length];
|
char msg[256 + length];
|
||||||
uint8_t name[TOX_MAX_NAME_LENGTH];
|
uint8_t name[TOX_MAX_NAME_LENGTH];
|
||||||
int len = tox_group_peername(m, groupnumber, peernumber, name);
|
int len = tox_group_peername(m, groupnumber, peernumber, name);
|
||||||
|
//print_groupchatpeers(m, groupnumber);
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
name[0] = 0;
|
name[0] = 0;
|
||||||
|
|
||||||
|
|
|
@ -707,6 +707,23 @@ int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint
|
||||||
|
|
||||||
/**********GROUP CHATS************/
|
/**********GROUP CHATS************/
|
||||||
|
|
||||||
|
/* return 1 if the groupnumber is not valid.
|
||||||
|
* return 0 if the groupnumber is valid.
|
||||||
|
*/
|
||||||
|
static uint8_t groupnumber_not_valid(Messenger *m, int groupnumber)
|
||||||
|
{
|
||||||
|
if ((unsigned int)groupnumber >= m->numchats)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (m->chats == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (m->chats[groupnumber] == NULL)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* returns valid ip port of connected friend on success
|
/* returns valid ip port of connected friend on success
|
||||||
* returns zeroed out IP_Port on failure
|
* returns zeroed out IP_Port on failure
|
||||||
*/
|
*/
|
||||||
|
@ -964,6 +981,7 @@ int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* send a group message
|
/* send a group message
|
||||||
* return 0 on success
|
* return 0 on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
|
@ -971,13 +989,7 @@ int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_
|
||||||
|
|
||||||
int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length)
|
int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length)
|
||||||
{
|
{
|
||||||
if ((unsigned int)groupnumber >= m->numchats)
|
if (groupnumber_not_valid(m, groupnumber))
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (m->chats == NULL)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (m->chats[groupnumber] == NULL)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (group_sendmessage(m->chats[groupnumber], message, length) > 0)
|
if (group_sendmessage(m->chats[groupnumber], message, length) > 0)
|
||||||
|
@ -986,6 +998,33 @@ int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return the number of peers in the group chat on success.
|
||||||
|
* return -1 on failure
|
||||||
|
*/
|
||||||
|
int group_number_peers(Messenger *m, int groupnumber)
|
||||||
|
{
|
||||||
|
if (groupnumber_not_valid(m, groupnumber))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return group_numpeers(m->chats[groupnumber]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* List all the peers in the group chat.
|
||||||
|
*
|
||||||
|
* Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
|
||||||
|
*
|
||||||
|
* returns the number of peers on success.
|
||||||
|
*
|
||||||
|
* return -1 on failure.
|
||||||
|
*/
|
||||||
|
int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t length)
|
||||||
|
{
|
||||||
|
if (groupnumber_not_valid(m, groupnumber))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return group_client_names(m->chats[groupnumber], names, length);
|
||||||
|
}
|
||||||
|
|
||||||
static int handle_group(void *object, IP_Port source, uint8_t *packet, uint32_t length)
|
static int handle_group(void *object, IP_Port source, uint8_t *packet, uint32_t length)
|
||||||
{
|
{
|
||||||
Messenger *m = object;
|
Messenger *m = object;
|
||||||
|
|
|
@ -497,6 +497,21 @@ int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_
|
||||||
|
|
||||||
int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length);
|
int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length);
|
||||||
|
|
||||||
|
/* Return the number of peers in the group chat on success.
|
||||||
|
* return -1 on failure
|
||||||
|
*/
|
||||||
|
int group_number_peers(Messenger *m, int groupnumber);
|
||||||
|
|
||||||
|
/* List all the peers in the group chat.
|
||||||
|
*
|
||||||
|
* Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
|
||||||
|
*
|
||||||
|
* returns the number of peers on success.
|
||||||
|
*
|
||||||
|
* return -1 on failure.
|
||||||
|
*/
|
||||||
|
int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t length);
|
||||||
|
|
||||||
/****************FILE SENDING*****************/
|
/****************FILE SENDING*****************/
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -616,6 +616,19 @@ void callback_groupmessage(Group_Chat *chat, void (*function)(Group_Chat *chat,
|
||||||
chat->group_message_userdata = userdata;
|
chat->group_message_userdata = userdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t group_numpeers(Group_Chat *chat)
|
||||||
|
{
|
||||||
|
return chat->numpeers;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t group_client_names(Group_Chat *chat, uint8_t names[][MAX_NICK_BYTES], uint16_t length)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
for (i = 0; i < chat->numpeers && i < length; ++i) {
|
||||||
|
group_peername(chat, i, names[i]);
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
Group_Chat *new_groupchat(Networking_Core *net)
|
Group_Chat *new_groupchat(Networking_Core *net)
|
||||||
{
|
{
|
||||||
|
|
|
@ -128,6 +128,18 @@ uint32_t group_newpeer(Group_Chat *chat, uint8_t *client_id);
|
||||||
Group_Chat *new_groupchat(Networking_Core *net);
|
Group_Chat *new_groupchat(Networking_Core *net);
|
||||||
|
|
||||||
|
|
||||||
|
/* Return the number of peers in the group chat.
|
||||||
|
*/
|
||||||
|
uint32_t group_numpeers(Group_Chat *chat);
|
||||||
|
|
||||||
|
/* List all the peers in the group chat.
|
||||||
|
*
|
||||||
|
* Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
|
||||||
|
*
|
||||||
|
* returns the number of peers.
|
||||||
|
*/
|
||||||
|
uint32_t group_client_names(Group_Chat *chat, uint8_t names[][MAX_NICK_BYTES], uint16_t length);
|
||||||
|
|
||||||
/* Kill a group chat
|
/* Kill a group chat
|
||||||
*
|
*
|
||||||
* Frees the memory and everything.
|
* Frees the memory and everything.
|
||||||
|
|
|
@ -477,6 +477,29 @@ int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t
|
||||||
return group_message_send(m, groupnumber, message, length);
|
return group_message_send(m, groupnumber, message, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return the number of peers in the group chat on success.
|
||||||
|
* return -1 on failure
|
||||||
|
*/
|
||||||
|
int tox_group_number_peers(Tox *tox, int groupnumber)
|
||||||
|
{
|
||||||
|
Messenger *m = tox;
|
||||||
|
return group_number_peers(m, groupnumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* List all the peers in the group chat.
|
||||||
|
*
|
||||||
|
* Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
|
||||||
|
*
|
||||||
|
* returns the number of peers on success.
|
||||||
|
*
|
||||||
|
* return -1 on failure.
|
||||||
|
*/
|
||||||
|
int tox_group_copy_names(Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t length)
|
||||||
|
{
|
||||||
|
Messenger *m = tox;
|
||||||
|
return group_names(m, groupnumber, names, length);
|
||||||
|
}
|
||||||
|
|
||||||
/* Return the number of chats in the instance m.
|
/* Return the number of chats in the instance m.
|
||||||
* You should use this to determine how much memory to allocate
|
* You should use this to determine how much memory to allocate
|
||||||
* for copy_chatlist. */
|
* for copy_chatlist. */
|
||||||
|
|
|
@ -398,13 +398,27 @@ int tox_invite_friend(Tox *tox, int friendnumber, int groupnumber);
|
||||||
*/
|
*/
|
||||||
int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key);
|
int tox_join_groupchat(Tox *tox, int friendnumber, uint8_t *friend_group_public_key);
|
||||||
|
|
||||||
|
|
||||||
/* send a group message
|
/* send a group message
|
||||||
* return 0 on success
|
* return 0 on success
|
||||||
* return -1 on failure
|
* return -1 on failure
|
||||||
*/
|
*/
|
||||||
int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length);
|
int tox_group_message_send(Tox *tox, int groupnumber, uint8_t *message, uint32_t length);
|
||||||
|
|
||||||
|
/* Return the number of peers in the group chat on success.
|
||||||
|
* return -1 on failure
|
||||||
|
*/
|
||||||
|
int tox_group_number_peers(Tox *tox, int groupnumber);
|
||||||
|
|
||||||
|
/* List all the peers in the group chat.
|
||||||
|
*
|
||||||
|
* Copies the names of the peers to the name[length][TOX_MAX_NAME_LENGTH] array.
|
||||||
|
*
|
||||||
|
* returns the number of peers on success.
|
||||||
|
*
|
||||||
|
* return -1 on failure.
|
||||||
|
*/
|
||||||
|
int tox_group_copy_names(Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t length);
|
||||||
|
|
||||||
/* Return the number of chats in the instance m.
|
/* Return the number of chats in the instance m.
|
||||||
* You should use this to determine how much memory to allocate
|
* You should use this to determine how much memory to allocate
|
||||||
* for copy_chatlist. */
|
* for copy_chatlist. */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user