Some function changes for better A/V integration to group chats.

This commit is contained in:
irungentoo 2014-11-07 21:28:47 -05:00
parent 1c5e93cf6c
commit 6d90808c15
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
2 changed files with 37 additions and 13 deletions

View File

@ -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->peer_namelistchange(g_c->m, groupnumber, g->numpeers - 1, CHAT_CHANGE_PEER_ADD,
g_c->group_namelistchange_userdata); g_c->group_namelistchange_userdata);
if (g_c->peer_on_join) if (g->peer_on_join)
g_c->peer_on_join(g->object, groupnumber, g->numpeers - 1); g->peer_on_join(g->object, groupnumber, g->numpeers - 1);
return (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) if (g_c->peer_namelistchange)
g_c->peer_namelistchange(g_c->m, groupnumber, peer_index, CHAT_CHANGE_PEER_DEL, g_c->group_namelistchange_userdata); 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) if (g->peer_on_leave)
g_c->peer_on_leave(g->object, groupnumber, peer_index, peer_object); g->peer_on_leave(g->object, groupnumber, peer_index, peer_object);
return 0; 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. /* 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) * 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. /* 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)) * 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, 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) int group_kill_peer_send(const Group_Chats *g_c, int groupnumber, uint16_t peer_num)
{ {
uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH]; uint8_t packet[GROUP_MESSAGE_KILL_PEER_LENGTH];
peer_num = htons(peer_num); peer_num = htons(peer_num);

View File

@ -95,6 +95,9 @@ typedef struct {
int number_joined; /* friendcon_id of person that invited us to the chat. (-1 means none) */ int number_joined; /* friendcon_id of person that invited us to the chat. (-1 means none) */
void *object; void *object;
void (*peer_on_join)(void *, int, int);
void (*peer_on_leave)(void *, int, int, void *);
} Group_c; } Group_c;
typedef struct { typedef struct {
@ -113,8 +116,6 @@ typedef struct {
void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *); void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *);
void *group_namelistchange_userdata; void *group_namelistchange_userdata;
void (*peer_on_join)(void *, int, int);
void (*peer_on_leave)(void *, int, int, void *);
struct { struct {
int (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); int (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, void *);
void *userdata; 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. /* 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) * 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. /* 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)) * 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. */ /* Create new groupchat instance. */
Group_Chats *new_groupchats(Messenger *m); Group_Chats *new_groupchats(Messenger *m);