From 26d119a17b032830f4ba5063a4e5f9037a8240e9 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Thu, 2 Oct 2014 17:52:56 -0400 Subject: [PATCH] Implemented tox_callback_group_namelist_change callback in group chats. No names yet though. --- toxcore/group.c | 27 ++++++++++++++++++++------- toxcore/group.h | 9 ++++++++- toxcore/tox.c | 2 +- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/toxcore/group.c b/toxcore/group.c index d94349f4..96f5ba2f 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -398,8 +398,10 @@ static int addpeer(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, co ++g->numpeers; add_to_closest(g_c, groupnumber, real_pk, temp_pk); - //if (g->peer_namelistchange != NULL) - // (*g->peer_namelistchange)(g, g->numpeers - 1, CHAT_CHANGE_PEER_ADD, g->group_namelistchange_userdata); + + if (g_c->peer_namelistchange) + g_c->peer_namelistchange(g_c->m, groupnumber, g->numpeers - 1, CHAT_CHANGE_PEER_ADD, + g_c->group_namelistchange_userdata); return (g->numpeers - 1); } @@ -445,11 +447,10 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index) return -1; g->group = temp; - /* - if (g->peer_namelistchange != NULL) { - (*g->peer_namelistchange)(g, peer_index, CHAT_CHANGE_PEER_DEL, g->group_namelistchange_userdata); - } - */ + + if (g_c->peer_namelistchange) + g_c->peer_namelistchange(g_c->m, groupnumber, peer_index, CHAT_CHANGE_PEER_DEL, g_c->group_namelistchange_userdata); + return 0; } @@ -781,6 +782,18 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, i g_c->message_callback_userdata = userdata; } +/* Set callback function for peer name list changes. + * + * It gets called every time the name list changes(new peer/name, deleted peer) + * Function(Group_Chats *g_c, int groupnumber, int peernumber, TOX_CHAT_CHANGE change, void *userdata) + */ +void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, int, int, uint8_t, void *), + void *userdata) +{ + g_c->peer_namelistchange = function; + g_c->group_namelistchange_userdata = userdata; +} + static unsigned int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data, uint16_t len); diff --git a/toxcore/group.h b/toxcore/group.h index c91edd7b..d3a330b2 100644 --- a/toxcore/group.h +++ b/toxcore/group.h @@ -103,6 +103,8 @@ typedef struct { void *invite_callback_userdata; void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); void *message_callback_userdata; + void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *); + void *group_namelistchange_userdata; } Group_Chats; /* Set the callback for group invites. @@ -131,8 +133,13 @@ void g_callback_group_action(Group_Chats *g_c, void (*function)(Messenger *m, in /* Set callback function for peer name list changes. * * It gets called every time the name list changes(new peer/name, deleted peer) - * Function(Group_Chats *g_c, int groupnumber, void *userdata) + * Function(Group_Chats *g_c, int groupnumber, int peernumber, TOX_CHAT_CHANGE change, void *userdata) */ +enum { + CHAT_CHANGE_PEER_ADD, + CHAT_CHANGE_PEER_DEL, + CHAT_CHANGE_PEER_NAME, +}; void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenger *m, int, int, uint8_t, void *), void *userdata); diff --git a/toxcore/tox.c b/toxcore/tox.c index 35587c2b..999d81d6 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -586,7 +586,7 @@ void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, i void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t, void *), void *userdata) { Messenger *m = tox; - //m_callback_group_namelistchange(m, function, userdata); + g_callback_group_namelistchange(m->group_chat_object, function, userdata); } /* Creates a new groupchat and puts it in the chats array.