Skip to content

Commit

Permalink
make kill packet sending part of del_groupchat
Browse files Browse the repository at this point in the history
  • Loading branch information
zugz committed Dec 2, 2018
1 parent bc8e0a8 commit bf21600
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
11 changes: 8 additions & 3 deletions toxcore/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,19 +1034,24 @@ int add_groupchat(Group_Chats *g_c, uint8_t type)
return groupnumber;
}

/* Delete a groupchat from the chats array.
/* Delete a groupchat from the chats array, informing the group first as
* appropriate.
*
* return 0 on success.
* return -1 if groupnumber is invalid.
*/
int del_groupchat(Group_Chats *g_c, uint32_t groupnumber)
int del_groupchat(Group_Chats *g_c, uint32_t groupnumber, bool leave_permanently)
{
Group_c *g = get_group_c(g_c, groupnumber);

if (!g) {
return -1;
}

if (leave_permanently) {
group_leave(g_c, groupnumber);
}

for (uint32_t i = 0; i < MAX_GROUP_CONNECTIONS; ++i) {
if (g->close[i].type == GROUPCHAT_CLOSE_NONE) {
continue;
Expand Down Expand Up @@ -3231,7 +3236,7 @@ void do_groupchats(Group_Chats *g_c, void *userdata)
void kill_groupchats(Group_Chats *g_c)
{
for (uint16_t i = 0; i < g_c->num_chats; ++i) {
del_groupchat(g_c, i);
leave_groupchat(g_c, i, false);
}

m_callback_conference_invite(g_c->m, nullptr);
Expand Down
11 changes: 3 additions & 8 deletions toxcore/group.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,13 @@ void g_callback_peer_list_changed(Group_Chats *g_c, peer_list_changed_cb *functi
*/
int add_groupchat(Group_Chats *g_c, uint8_t type);

/* Delete a groupchat from the chats array.
/* Delete a groupchat from the chats array, informing the group first as
* appropriate.
*
* return 0 on success.
* return -1 if groupnumber is invalid.
*/
int del_groupchat(Group_Chats *g_c, uint32_t groupnumber);
int del_groupchat(Group_Chats *g_c, uint32_t groupnumber, bool leave_permanently);

/* Copy the public key of (frozen) peernumber who is in groupnumber to pk.
* pk must be CRYPTO_PUBLIC_KEY_SIZE long.
Expand Down Expand Up @@ -316,12 +317,6 @@ int group_message_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8
*/
int group_action_send(const Group_Chats *g_c, uint32_t groupnumber, const uint8_t *action, uint16_t length);

/* send message to announce leaving group
* return true on success
* return false on failure
*/
bool group_leave(const Group_Chats *g_c, uint32_t groupnumber);

/* set the group's title, limited to MAX_NAME_LENGTH
* return 0 on success
* return -1 if groupnumber is invalid.
Expand Down
3 changes: 1 addition & 2 deletions toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -1534,8 +1534,7 @@ uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error)
bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error)
{
Messenger *m = tox->m;
group_leave(m->conferences_object, conference_number);
int ret = del_groupchat(m->conferences_object, conference_number);
int ret = del_groupchat(m->conferences_object, conference_number, true);

if (ret == -1) {
SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_DELETE_CONFERENCE_NOT_FOUND);
Expand Down

0 comments on commit bf21600

Please sign in to comment.