Skip to content

Commit bf21600

Browse files
committed
make kill packet sending part of del_groupchat
1 parent bc8e0a8 commit bf21600

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

toxcore/group.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,19 +1034,24 @@ int add_groupchat(Group_Chats *g_c, uint8_t type)
10341034
return groupnumber;
10351035
}
10361036

1037-
/* Delete a groupchat from the chats array.
1037+
/* Delete a groupchat from the chats array, informing the group first as
1038+
* appropriate.
10381039
*
10391040
* return 0 on success.
10401041
* return -1 if groupnumber is invalid.
10411042
*/
1042-
int del_groupchat(Group_Chats *g_c, uint32_t groupnumber)
1043+
int del_groupchat(Group_Chats *g_c, uint32_t groupnumber, bool leave_permanently)
10431044
{
10441045
Group_c *g = get_group_c(g_c, groupnumber);
10451046

10461047
if (!g) {
10471048
return -1;
10481049
}
10491050

1051+
if (leave_permanently) {
1052+
group_leave(g_c, groupnumber);
1053+
}
1054+
10501055
for (uint32_t i = 0; i < MAX_GROUP_CONNECTIONS; ++i) {
10511056
if (g->close[i].type == GROUPCHAT_CLOSE_NONE) {
10521057
continue;
@@ -3231,7 +3236,7 @@ void do_groupchats(Group_Chats *g_c, void *userdata)
32313236
void kill_groupchats(Group_Chats *g_c)
32323237
{
32333238
for (uint16_t i = 0; i < g_c->num_chats; ++i) {
3234-
del_groupchat(g_c, i);
3239+
leave_groupchat(g_c, i, false);
32353240
}
32363241

32373242
m_callback_conference_invite(g_c->m, nullptr);

toxcore/group.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,13 @@ void g_callback_peer_list_changed(Group_Chats *g_c, peer_list_changed_cb *functi
238238
*/
239239
int add_groupchat(Group_Chats *g_c, uint8_t type);
240240

241-
/* Delete a groupchat from the chats array.
241+
/* Delete a groupchat from the chats array, informing the group first as
242+
* appropriate.
242243
*
243244
* return 0 on success.
244245
* return -1 if groupnumber is invalid.
245246
*/
246-
int del_groupchat(Group_Chats *g_c, uint32_t groupnumber);
247+
int del_groupchat(Group_Chats *g_c, uint32_t groupnumber, bool leave_permanently);
247248

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

319-
/* send message to announce leaving group
320-
* return true on success
321-
* return false on failure
322-
*/
323-
bool group_leave(const Group_Chats *g_c, uint32_t groupnumber);
324-
325320
/* set the group's title, limited to MAX_NAME_LENGTH
326321
* return 0 on success
327322
* return -1 if groupnumber is invalid.

toxcore/tox.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,8 +1534,7 @@ uint32_t tox_conference_new(Tox *tox, Tox_Err_Conference_New *error)
15341534
bool tox_conference_delete(Tox *tox, uint32_t conference_number, Tox_Err_Conference_Delete *error)
15351535
{
15361536
Messenger *m = tox->m;
1537-
group_leave(m->conferences_object, conference_number);
1538-
int ret = del_groupchat(m->conferences_object, conference_number);
1537+
int ret = del_groupchat(m->conferences_object, conference_number, true);
15391538

15401539
if (ret == -1) {
15411540
SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_DELETE_CONFERENCE_NOT_FOUND);

0 commit comments

Comments
 (0)