mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Cleaned up some code, made group av clean up properly after itself
when the group is killed.
This commit is contained in:
parent
8c0225b27f
commit
3b10a248dc
|
@ -248,6 +248,12 @@ static void group_av_peer_delete(void *object, int groupnumber, int friendgroupn
|
|||
free(peer_object);
|
||||
}
|
||||
|
||||
static void group_av_groupchat_delete(void *object, int groupnumber)
|
||||
{
|
||||
if (object)
|
||||
kill_group_av(object);
|
||||
}
|
||||
|
||||
static int decode_audio_packet(Group_AV *group_av, Group_Peer_AV *peer_av, int groupnumber, int friendgroupnumber)
|
||||
{
|
||||
if (!group_av || !peer_av)
|
||||
|
@ -394,7 +400,8 @@ static int groupchat_enable_av(Group_Chats *g_c, int groupnumber, void (*audio_c
|
|||
|
||||
if (group_set_object(g_c, groupnumber, group_av) == -1
|
||||
|| callback_groupchat_peer_new(g_c, groupnumber, group_av_peer_new) == -1
|
||||
|| callback_groupchat_peer_delete(g_c, groupnumber, group_av_peer_delete) == -1) {
|
||||
|| callback_groupchat_peer_delete(g_c, groupnumber, group_av_peer_delete) == -1
|
||||
|| callback_groupchat_delete(g_c, groupnumber, group_av_groupchat_delete) == -1) {
|
||||
kill_group_av(group_av);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -686,7 +686,16 @@ int del_groupchat(Group_Chats *g_c, int groupnumber)
|
|||
kill_friend_connection(g_c->fr_c, g->close[i].number);
|
||||
}
|
||||
|
||||
for (i = 0; i < g->numpeers; ++i) {
|
||||
if (g->peer_on_leave)
|
||||
g->peer_on_leave(g->object, groupnumber, i, g->group[i].object);
|
||||
}
|
||||
|
||||
free(g->group);
|
||||
|
||||
if (g->group_on_delete)
|
||||
g->group_on_delete(g->object, groupnumber);
|
||||
|
||||
return wipe_group_chat(g_c, groupnumber);
|
||||
}
|
||||
|
||||
|
@ -1000,6 +1009,24 @@ int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*fun
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Set a function to be called when the group chat is deleted.
|
||||
*
|
||||
* Function(void *group object (set with group_set_object), int groupnumber)
|
||||
*
|
||||
* return 0 on success.
|
||||
* return -1 on failure.
|
||||
*/
|
||||
int callback_groupchat_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int))
|
||||
{
|
||||
Group_c *g = get_group_c(g_c, groupnumber);
|
||||
|
||||
if (!g)
|
||||
return -1;
|
||||
|
||||
g->group_on_delete = function;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned int send_message_group(const Group_Chats *g_c, int groupnumber, uint8_t message_id, const uint8_t *data,
|
||||
uint16_t len);
|
||||
|
||||
|
@ -2014,7 +2041,6 @@ void kill_groupchats(Group_Chats *g_c)
|
|||
|
||||
m_callback_group_invite(g_c->m, NULL);
|
||||
g_c->m->group_chat_object = 0;
|
||||
free(g_c->av_object);
|
||||
free(g_c);
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ typedef struct {
|
|||
|
||||
void (*peer_on_join)(void *, int, int);
|
||||
void (*peer_on_leave)(void *, int, int, void *);
|
||||
void (*group_on_delete)(void *, int);
|
||||
} Group_c;
|
||||
|
||||
typedef struct {
|
||||
|
@ -124,8 +125,6 @@ typedef struct {
|
|||
struct {
|
||||
int (*function)(void *, int, int, void *, const uint8_t *, uint16_t);
|
||||
} lossy_packethandlers[256];
|
||||
|
||||
void *av_object;
|
||||
} Group_Chats;
|
||||
|
||||
/* Set the callback for group invites.
|
||||
|
@ -317,6 +316,15 @@ int callback_groupchat_peer_new(const Group_Chats *g_c, int groupnumber, void (*
|
|||
*/
|
||||
int callback_groupchat_peer_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int, int, void *));
|
||||
|
||||
/* Set a function to be called when the group chat is deleted.
|
||||
*
|
||||
* Function(void *group object (set with group_set_object), int groupnumber)
|
||||
*
|
||||
* return 0 on success.
|
||||
* return -1 on failure.
|
||||
*/
|
||||
int callback_groupchat_delete(Group_Chats *g_c, int groupnumber, void (*function)(void *, int));
|
||||
|
||||
/* Create new groupchat instance. */
|
||||
Group_Chats *new_groupchats(Messenger *m);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user