summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-12-08 13:50:38 -0500
committerirungentoo <irungentoo@gmail.com>2014-12-08 13:50:38 -0500
commit7e8ab1b8fec1b4de350186ccd02d710c2685f0a6 (patch)
treed0728cc3fd6c3581ee11f6f341ecd7d83f014c28
parentaf0d6c0695e3c459989b911b6fb62ce40058440e (diff)
Delete close connection when peer leaves chat.
-rw-r--r--toxcore/group.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/toxcore/group.c b/toxcore/group.c
index 5f075c04..2c363c80 100644
--- a/toxcore/group.c
+++ b/toxcore/group.c
@@ -434,6 +434,30 @@ static int addpeer(Group_Chats *g_c, int groupnumber, const uint8_t *real_pk, co
434 return (g->numpeers - 1); 434 return (g->numpeers - 1);
435} 435}
436 436
437static int remove_close_conn(Group_Chats *g_c, int groupnumber, int friendcon_id)
438{
439 Group_c *g = get_group_c(g_c, groupnumber);
440
441 if (!g)
442 return -1;
443
444 uint32_t i;
445
446 for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) {
447 if (g->close[i].type == GROUPCHAT_CLOSE_NONE)
448 continue;
449
450 if (g->close[i].number == friendcon_id) {
451 g->close[i].type = GROUPCHAT_CLOSE_NONE;
452 kill_friend_connection(g_c->fr_c, friendcon_id);
453 return 0;
454 }
455 }
456
457 return -1;
458}
459
460
437/* 461/*
438 * Delete a peer from the group chat. 462 * Delete a peer from the group chat.
439 * 463 *
@@ -457,6 +481,12 @@ static int delpeer(Group_Chats *g_c, int groupnumber, int peer_index)
457 } 481 }
458 } 482 }
459 483
484 int friendcon_id = getfriend_conn_id_pk(g_c->fr_c, g->group[peer_index].real_pk);
485
486 if (friendcon_id != -1) {
487 remove_close_conn(g_c, groupnumber, friendcon_id);
488 }
489
460 Group_Peer *temp; 490 Group_Peer *temp;
461 --g->numpeers; 491 --g->numpeers;
462 492
@@ -533,29 +563,6 @@ static int settitle(Group_Chats *g_c, int groupnumber, int peer_index, const uin
533 return 0; 563 return 0;
534} 564}
535 565
536static int remove_close_conn(Group_Chats *g_c, int groupnumber, int friendcon_id)
537{
538 Group_c *g = get_group_c(g_c, groupnumber);
539
540 if (!g)
541 return -1;
542
543 uint32_t i;
544
545 for (i = 0; i < MAX_GROUP_CONNECTIONS; ++i) {
546 if (g->close[i].type == GROUPCHAT_CLOSE_NONE)
547 continue;
548
549 if (g->close[i].number == friendcon_id) {
550 g->close[i].type = GROUPCHAT_CLOSE_NONE;
551 kill_friend_connection(g_c->fr_c, friendcon_id);
552 return 0;
553 }
554 }
555
556 return -1;
557}
558
559static void set_conns_type_close(Group_Chats *g_c, int groupnumber, int friendcon_id, uint8_t type) 566static void set_conns_type_close(Group_Chats *g_c, int groupnumber, int friendcon_id, uint8_t type)
560{ 567{
561 Group_c *g = get_group_c(g_c, groupnumber); 568 Group_c *g = get_group_c(g_c, groupnumber);