summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-01-30 20:29:33 -0500
committerirungentoo <irungentoo@gmail.com>2015-01-30 20:29:33 -0500
commit8e9a971e95fea02e19dd7e187baf38c848515c32 (patch)
tree14ce9c30899462d2d9da328d996f6cfea5e4d193 /toxcore
parentb8d530c9e0bbce331f22cbff7f818e49673d5bd7 (diff)
Prevent unnecessary sending of packets.
If name/status/typing didn't actually change return success and don't actually do anything.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/Messenger.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c
index 1404d816..4cf0edeb 100644
--- a/toxcore/Messenger.c
+++ b/toxcore/Messenger.c
@@ -488,6 +488,9 @@ int setname(Messenger *m, const uint8_t *name, uint16_t length)
488 if (length > MAX_NAME_LENGTH || length == 0) 488 if (length > MAX_NAME_LENGTH || length == 0)
489 return -1; 489 return -1;
490 490
491 if (m->name_length == length && memcmp(name, m->name, length) == 0)
492 return 0;
493
491 memcpy(m->name, name, length); 494 memcpy(m->name, name, length);
492 m->name_length = length; 495 m->name_length = length;
493 uint32_t i; 496 uint32_t i;
@@ -547,6 +550,9 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length)
547 if (length > MAX_STATUSMESSAGE_LENGTH) 550 if (length > MAX_STATUSMESSAGE_LENGTH)
548 return -1; 551 return -1;
549 552
553 if (m->statusmessage_length == length && memcmp(m->statusmessage, status, length) == 0)
554 return 0;
555
550 memcpy(m->statusmessage, status, length); 556 memcpy(m->statusmessage, status, length);
551 m->statusmessage_length = length; 557 m->statusmessage_length = length;
552 558
@@ -560,9 +566,11 @@ int m_set_statusmessage(Messenger *m, const uint8_t *status, uint16_t length)
560 566
561int m_set_userstatus(Messenger *m, uint8_t status) 567int m_set_userstatus(Messenger *m, uint8_t status)
562{ 568{
563 if (status >= USERSTATUS_INVALID) { 569 if (status >= USERSTATUS_INVALID)
564 return -1; 570 return -1;
565 } 571
572 if (m->userstatus == status)
573 return 0;
566 574
567 m->userstatus = status; 575 m->userstatus = status;
568 uint32_t i; 576 uint32_t i;
@@ -788,13 +796,15 @@ uint64_t m_get_last_online(const Messenger *m, int32_t friendnumber)
788int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing) 796int m_set_usertyping(Messenger *m, int32_t friendnumber, uint8_t is_typing)
789 797
790{ 798{
791 if (is_typing != 0 && is_typing != 1) { 799 if (is_typing != 0 && is_typing != 1)
792 return -1; 800 return -1;
793 }
794 801
795 if (friend_not_valid(m, friendnumber)) 802 if (friend_not_valid(m, friendnumber))
796 return -1; 803 return -1;
797 804
805 if (m->friendlist[friendnumber].user_istyping == is_typing)
806 return 0;
807
798 m->friendlist[friendnumber].user_istyping = is_typing; 808 m->friendlist[friendnumber].user_istyping = is_typing;
799 m->friendlist[friendnumber].user_istyping_sent = 0; 809 m->friendlist[friendnumber].user_istyping_sent = 0;
800 810
@@ -1659,6 +1669,8 @@ static int handle_status(void *object, int i, uint8_t status)
1659 m->friendlist[i].name_sent = 0; 1669 m->friendlist[i].name_sent = 0;
1660 m->friendlist[i].userstatus_sent = 0; 1670 m->friendlist[i].userstatus_sent = 0;
1661 m->friendlist[i].statusmessage_sent = 0; 1671 m->friendlist[i].statusmessage_sent = 0;
1672 m->friendlist[i].user_istyping_sent = 0;
1673 m->friendlist[i].avatar_info_sent = 0;
1662 m->friendlist[i].ping_lastrecv = temp_time; 1674 m->friendlist[i].ping_lastrecv = temp_time;
1663 } else { /* Went offline. */ 1675 } else { /* Went offline. */
1664 if (m->friendlist[i].status == FRIEND_ONLINE) { 1676 if (m->friendlist[i].status == FRIEND_ONLINE) {