summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/group.c35
-rw-r--r--toxcore/group.h15
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
431 g_c->peer_namelistchange(g_c->m, groupnumber, g->numpeers - 1, CHAT_CHANGE_PEER_ADD, 431 g_c->peer_namelistchange(g_c->m, groupnumber, g->numpeers - 1, CHAT_CHANGE_PEER_ADD,
432 g_c->group_namelistchange_userdata); 432 g_c->group_namelistchange_userdata);
433 433
434 if (g_c->peer_on_join) 434 if (g->peer_on_join)
435 g_c->peer_on_join(g->object, groupnumber, g->numpeers - 1); 435 g->peer_on_join(g->object, groupnumber, g->numpeers - 1);
436 436
437 return (g->numpeers - 1); 437 return (g->numpeers - 1);
438} 438}
@@ -483,8 +483,8 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index)
483 if (g_c->peer_namelistchange) 483 if (g_c->peer_namelistchange)
484 g_c->peer_namelistchange(g_c->m, groupnumber, peer_index, CHAT_CHANGE_PEER_DEL, g_c->group_namelistchange_userdata); 484 g_c->peer_namelistchange(g_c->m, groupnumber, peer_index, CHAT_CHANGE_PEER_DEL, g_c->group_namelistchange_userdata);
485 485
486 if (g_c->peer_on_leave) 486 if (g->peer_on_leave)
487 g_c->peer_on_leave(g->object, groupnumber, peer_index, peer_object); 487 g->peer_on_leave(g->object, groupnumber, peer_index, peer_object);
488 488
489 return 0; 489 return 0;
490} 490}
@@ -960,19 +960,37 @@ void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenge
960/* Set a function to be called when a new peer joins a group chat. 960/* Set a function to be called when a new peer joins a group chat.
961 * 961 *
962 * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber) 962 * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber)
963 *
964 * return 0 on success.
965 * return -1 on failure.
963 */ 966 */
964void callback_groupchat_peer_new(const Group_Chats *g_c, void (*function)(void *, int, int)) 967int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int))
965{ 968{
966 g_c->peer_on_join = function; 969 Group_c *g = get_group_c(g_c, groupnumber);
970
971 if (!g)
972 return -1;
973
974 g->peer_on_join = function;
975 return 0;
967} 976}
968 977
969/* Set a function to be called when a peer leaves a group chat. 978/* Set a function to be called when a peer leaves a group chat.
970 * 979 *
971 * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object)) 980 * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object))
981 *
982 * return 0 on success.
983 * return -1 on failure.
972 */ 984 */
973void callback_groupchat_peer_delete(const Group_Chats *g_c, void (*function)(void *, int, int, void *)) 985int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int, void *))
974{ 986{
975 g_c->peer_on_leave = function; 987 Group_c *g = get_group_c(g_c, groupnumber);
988
989 if (!g)
990 return -1;
991
992 g->peer_on_leave = function;
993 return 0;
976} 994}
977 995
978static unsigned int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data, 996static 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
1020 */ 1038 */
1021int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num) 1039int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num)
1022{ 1040{
1023
1024 uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH]; 1041 uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH];
1025 1042
1026 peer_num = htons(peer_num); 1043 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 {
95 int number_joined; /* friendcon_id of person that invited us to the chat. (-1 means none) */ 95 int number_joined; /* friendcon_id of person that invited us to the chat. (-1 means none) */
96 96
97 void *object; 97 void *object;
98
99 void (*peer_on_join)(void *, int, int);
100 void (*peer_on_leave)(void *, int, int, void *);
98} Group_c; 101} Group_c;
99 102
100typedef struct { 103typedef struct {
@@ -113,8 +116,6 @@ typedef struct {
113 void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *); 116 void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *);
114 void *group_namelistchange_userdata; 117 void *group_namelistchange_userdata;
115 118
116 void (*peer_on_join)(void *, int, int);
117 void (*peer_on_leave)(void *, int, int, void *);
118 struct { 119 struct {
119 int (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); 120 int (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *);
120 void *userdata; 121 void *userdata;
@@ -289,14 +290,20 @@ void *group_peer_get_object(const Group_Chats *g_c, int groupnumber, int peernum
289/* Set a function to be called when a new peer joins a group chat. 290/* Set a function to be called when a new peer joins a group chat.
290 * 291 *
291 * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber) 292 * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber)
293 *
294 * return 0 on success.
295 * return -1 on failure.
292 */ 296 */
293void callback_groupchat_peer_new(const Group_Chats *g_c, void (*function)(void *, int, int)); 297int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int));
294 298
295/* Set a function to be called when a peer leaves a group chat. 299/* Set a function to be called when a peer leaves a group chat.
296 * 300 *
297 * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object)) 301 * Function(void *group object (set with group_set_object), int groupnumber, int friendgroupnumber, void *group peer object (set with group_peer_set_object))
302 *
303 * return 0 on success.
304 * return -1 on failure.
298 */ 305 */
299void callback_groupchat_peer_delete(const Group_Chats *g_c, void (*function)(void *, int, int, void *)); 306int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int, void *));
300 307
301/* Create new groupchat instance. */ 308/* Create new groupchat instance. */
302Group_Chats *new_groupchats(Messenger *m); 309Group_Chats *new_groupchats(Messenger *m);