summaryrefslogtreecommitdiff
path: root/toxcore/Messenger.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-11-22 23:31:55 -0500
committerirungentoo <irungentoo@gmail.com>2013-11-22 23:31:55 -0500
commitd2b56faded6e88e916d8f291c1cdff82f5cdd1ff (patch)
tree2068305f52778446f7be10c39f47c4d1a4d53d8a /toxcore/Messenger.c
parent2079cbc2db8ee98bcf2a0c66db8e503c705e5f95 (diff)
Added function to get the number of peers and list of names for group chats.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r--toxcore/Messenger.c53
1 files changed, 46 insertions, 7 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 8f6c42f9..889de367 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -707,6 +707,23 @@ int write_cryptpacket_id(Messenger *m, int friendnumber, uint8_t packet_id, uint
707 707
708/**********GROUP CHATS************/ 708/**********GROUP CHATS************/
709 709
710/* return 1 if the groupnumber is not valid.
711 * return 0 if the groupnumber is valid.
712 */
713static uint8_t groupnumber_not_valid(Messenger *m, int groupnumber)
714{
715 if ((unsigned int)groupnumber >= m->numchats)
716 return 1;
717
718 if (m->chats == NULL)
719 return 1;
720
721 if (m->chats[groupnumber] == NULL)
722 return 1;
723 return 0;
724}
725
726
710/* returns valid ip port of connected friend on success 727/* returns valid ip port of connected friend on success
711 * returns zeroed out IP_Port on failure 728 * returns zeroed out IP_Port on failure
712 */ 729 */
@@ -964,6 +981,7 @@ int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_
964 return -1; 981 return -1;
965} 982}
966 983
984
967/* send a group message 985/* send a group message
968 * return 0 on success 986 * return 0 on success
969 * return -1 on failure 987 * return -1 on failure
@@ -971,13 +989,7 @@ int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_
971 989
972int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length) 990int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length)
973{ 991{
974 if ((unsigned int)groupnumber >= m->numchats) 992 if (groupnumber_not_valid(m, groupnumber))
975 return -1;
976
977 if (m->chats == NULL)
978 return -1;
979
980 if (m->chats[groupnumber] == NULL)
981 return -1; 993 return -1;
982 994
983 if (group_sendmessage(m->chats[groupnumber], message, length) > 0) 995 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
986 return -1; 998 return -1;
987} 999}
988 1000
1001/* Return the number of peers in the group chat on success.
1002 * return -1 on failure
1003 */
1004int group_number_peers(Messenger *m, int groupnumber)
1005{
1006 if (groupnumber_not_valid(m, groupnumber))
1007 return -1;
1008
1009 return group_numpeers(m->chats[groupnumber]);
1010}
1011
1012/* List all the peers in the group chat.
1013 *
1014 * Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
1015 *
1016 * returns the number of peers on success.
1017 *
1018 * return -1 on failure.
1019 */
1020int group_names(Messenger *m, int groupnumber, uint8_t names[][MAX_NICK_BYTES], uint16_t length)
1021{
1022 if (groupnumber_not_valid(m, groupnumber))
1023 return -1;
1024
1025 return group_client_names(m->chats[groupnumber], names, length);
1026}
1027
989static int handle_group(void *object, IP_Port source, uint8_t *packet, uint32_t length) 1028static int handle_group(void *object, IP_Port source, uint8_t *packet, uint32_t length)
990{ 1029{
991 Messenger *m = object; 1030 Messenger *m = object;