From 6d90808c15c853a0f6e63554133ce89108b0b227 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 7 Nov 2014 21:28:47 -0500 Subject: [PATCH] Some function changes for better A/V integration to group chats. --- toxcore/group.c | 35 ++++++++++++++++++++++++++--------- toxcore/group.h | 15 +++++++++++---- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/toxcore/group.c b/toxcore/group.c index 6f0cfef3..2645416b 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -431,8 +431,8 @@ static int addpeer(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, co g_c->peer_namelistchange(g_c->m, groupnumber, g->numpeers - 1, CHAT_CHANGE_PEER_ADD, g_c->group_namelistchange_userdata); - if (g_c->peer_on_join) - g_c->peer_on_join(g->object, groupnumber, g->numpeers - 1); + if (g->peer_on_join) + g->peer_on_join(g->object, groupnumber, g->numpeers - 1); return (g->numpeers - 1); } @@ -483,8 +483,8 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index) if (g_c->peer_namelistchange) g_c->peer_namelistchange(g_c->m, groupnumber, peer_index, CHAT_CHANGE_PEER_DEL, g_c->group_namelistchange_userdata); - if (g_c->peer_on_leave) - g_c->peer_on_leave(g->object, groupnumber, peer_index, peer_object); + if (g->peer_on_leave) + g->peer_on_leave(g->object, groupnumber, peer_index, peer_object); return 0; } @@ -960,19 +960,37 @@ void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenge /* Set a function to be called when a new peer joins a group chat. * * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber) + * + * return 0 on success. + * return -1 on failure. */ -void callback_groupchat_peer_new(const Group_Chats *g_c, void (*function)(void *, int, int)) +int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int)) { - g_c->peer_on_join = function; + Group_c *g = get_group_c(g_c, groupnumber); + + if (!g) + return -1; + + g->peer_on_join = function; + return 0; } /* Set a function to be called when a peer leaves a group chat. * * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object)) + * + * return 0 on success. + * return -1 on failure. */ -void callback_groupchat_peer_delete(const Group_Chats *g_c, void (*function)(void *, int, int, void *)) +int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int, void *)) { - g_c->peer_on_leave = function; + Group_c *g = get_group_c(g_c, groupnumber); + + if (!g) + return -1; + + g->peer_on_leave = function; + return 0; } static unsigned int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data, @@ -1020,7 +1038,6 @@ int group_new_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_n */ int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num) { - uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH]; peer_num = htons(peer_num); diff --git a/toxcore/group.h b/toxcore/group.h index 41c7078e..aa888b33 100644 --- a/toxcore/group.h +++ b/toxcore/group.h @@ -95,6 +95,9 @@ typedef struct { int number_joined; /* friendcon_id of person that invited us to the chat. (-1 means none) */ void *object; + + void (*peer_on_join)(void *, int, int); + void (*peer_on_leave)(void *, int, int, void *); } Group_c; typedef struct { @@ -113,8 +116,6 @@ typedef struct { void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *); void *group_namelistchange_userdata; - void (*peer_on_join)(void *, int, int); - void (*peer_on_leave)(void *, int, int, void *); struct { int (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); void *userdata; @@ -289,14 +290,20 @@ void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernum /* Set a function to be called when a new peer joins a group chat. * * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber) + * + * return 0 on success. + * return -1 on failure. */ -void callback_groupchat_peer_new(const Group_Chats *g_c, void (*function)(void *, int, int)); +int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int)); /* Set a function to be called when a peer leaves a group chat. * * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object)) + * + * return 0 on success. + * return -1 on failure. */ -void callback_groupchat_peer_delete(const Group_Chats *g_c, void (*function)(void *, int, int, void *)); +int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int, void *)); /* Create new groupchat instance. */ Group_Chats *new_groupchats(Messenger *m);