diff options
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 692d3d0e..ee5213a7 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -268,6 +268,7 @@ int m_addfriend(Messenger *m, uint8_t *address, uint8_t *data, uint16_t length) | |||
268 | m->friendlist[i].statusmessage = calloc(1, 1); | 268 | m->friendlist[i].statusmessage = calloc(1, 1); |
269 | m->friendlist[i].statusmessage_length = 1; | 269 | m->friendlist[i].statusmessage_length = 1; |
270 | m->friendlist[i].userstatus = USERSTATUS_NONE; | 270 | m->friendlist[i].userstatus = USERSTATUS_NONE; |
271 | m->friendlist[i].is_typing = 0; | ||
271 | memcpy(m->friendlist[i].info, data, length); | 272 | memcpy(m->friendlist[i].info, data, length); |
272 | m->friendlist[i].info_size = length; | 273 | m->friendlist[i].info_size = length; |
273 | m->friendlist[i].message_id = 0; | 274 | m->friendlist[i].message_id = 0; |
@@ -315,6 +316,7 @@ int m_addfriend_norequest(Messenger *m, uint8_t *client_id) | |||
315 | m->friendlist[i].statusmessage = calloc(1, 1); | 316 | m->friendlist[i].statusmessage = calloc(1, 1); |
316 | m->friendlist[i].statusmessage_length = 1; | 317 | m->friendlist[i].statusmessage_length = 1; |
317 | m->friendlist[i].userstatus = USERSTATUS_NONE; | 318 | m->friendlist[i].userstatus = USERSTATUS_NONE; |
319 | m->friendlist[i].is_typing = 0; | ||
318 | m->friendlist[i].message_id = 0; | 320 | m->friendlist[i].message_id = 0; |
319 | m->friendlist[i].receives_read_receipts = 1; /* Default: YES. */ | 321 | m->friendlist[i].receives_read_receipts = 1; /* Default: YES. */ |
320 | 322 | ||
@@ -615,6 +617,29 @@ USERSTATUS m_get_self_userstatus(Messenger *m) | |||
615 | return m->userstatus; | 617 | return m->userstatus; |
616 | } | 618 | } |
617 | 619 | ||
620 | int m_set_usertyping(Messenger *m, int friendnumber, uint8_t is_typing) | ||
621 | { | ||
622 | if (is_typing != 0 || is_typing != 1) { | ||
623 | return -1; | ||
624 | } | ||
625 | |||
626 | if (friend_not_valid(m, friendnumber)) | ||
627 | return -1; | ||
628 | |||
629 | m->friendlist[friendnumber].user_istyping = is_typing; | ||
630 | m->friendlist[friendnumber].user_istyping_sent = 0; | ||
631 | |||
632 | return 0; | ||
633 | } | ||
634 | |||
635 | uint8_t m_get_istyping(Messenger *m, int friendnumber) | ||
636 | { | ||
637 | if (friend_not_valid(m, friendnumber)) | ||
638 | return -1; | ||
639 | |||
640 | return m->friendlist[friendnumber].is_typing; | ||
641 | } | ||
642 | |||
618 | static int send_statusmessage(Messenger *m, int friendnumber, uint8_t *status, uint16_t length) | 643 | static int send_statusmessage(Messenger *m, int friendnumber, uint8_t *status, uint16_t length) |
619 | { | 644 | { |
620 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length); | 645 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_STATUSMESSAGE, status, length); |
@@ -626,6 +651,12 @@ static int send_userstatus(Messenger *m, int friendnumber, USERSTATUS status) | |||
626 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &stat, sizeof(stat)); | 651 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_USERSTATUS, &stat, sizeof(stat)); |
627 | } | 652 | } |
628 | 653 | ||
654 | static int send_user_istyping(Messenger *m, int friendnumber, uint8_t is_typing) | ||
655 | { | ||
656 | uint8_t typing = is_typing; | ||
657 | return write_cryptpacket_id(m, friendnumber, PACKET_ID_TYPING, &typing, sizeof(typing)); | ||
658 | } | ||
659 | |||
629 | static int send_ping(Messenger *m, int friendnumber) | 660 | static int send_ping(Messenger *m, int friendnumber) |
630 | { | 661 | { |
631 | int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_PING, 0, 0); | 662 | int ret = write_cryptpacket_id(m, friendnumber, PACKET_ID_PING, 0, 0); |
@@ -654,6 +685,11 @@ static void set_friend_userstatus(Messenger *m, int friendnumber, USERSTATUS sta | |||
654 | m->friendlist[friendnumber].userstatus = status; | 685 | m->friendlist[friendnumber].userstatus = status; |
655 | } | 686 | } |
656 | 687 | ||
688 | static void set_friend_typing(Messenger *m, int friendnumber, uint8_t is_typing) | ||
689 | { | ||
690 | m->friendlist[friendnumber].is_typing = is_typing; | ||
691 | } | ||
692 | |||
657 | /* Sets whether we send read receipts for friendnumber. */ | 693 | /* Sets whether we send read receipts for friendnumber. */ |
658 | void m_set_sends_receipts(Messenger *m, int friendnumber, int yesno) | 694 | void m_set_sends_receipts(Messenger *m, int friendnumber, int yesno) |
659 | { | 695 | { |
@@ -707,6 +743,12 @@ void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USE | |||
707 | m->friend_userstatuschange_userdata = userdata; | 743 | m->friend_userstatuschange_userdata = userdata; |
708 | } | 744 | } |
709 | 745 | ||
746 | void m_callback_typingchange(Messenger *m, void(*function)(Messenger *m, int, uint8_t, void *), void *userdata) | ||
747 | { | ||
748 | m->friend_typingchange = function; | ||
749 | m->friend_typingchange_userdata = userdata; | ||
750 | } | ||
751 | |||
710 | void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t, void *), void *userdata) | 752 | void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t, void *), void *userdata) |
711 | { | 753 | { |
712 | m->read_receipt = function; | 754 | m->read_receipt = function; |
@@ -1821,6 +1863,11 @@ void do_friends(Messenger *m) | |||
1821 | if (send_userstatus(m, i, m->userstatus)) | 1863 | if (send_userstatus(m, i, m->userstatus)) |
1822 | m->friendlist[i].userstatus_sent = 1; | 1864 | m->friendlist[i].userstatus_sent = 1; |
1823 | } | 1865 | } |
1866 | |||
1867 | if (m->friendlist[i].user_istyping_sent == 0) { | ||
1868 | if (send_user_istyping(m, i, m->friendlist[i].user_istyping)) | ||
1869 | m->friendlist[i].user_istyping_sent = 1; | ||
1870 | } | ||
1824 | 1871 | ||
1825 | if (m->friendlist[i].ping_lastsent + FRIEND_PING_INTERVAL < temp_time) { | 1872 | if (m->friendlist[i].ping_lastsent + FRIEND_PING_INTERVAL < temp_time) { |
1826 | send_ping(m, i); | 1873 | send_ping(m, i); |
@@ -1882,6 +1929,19 @@ void do_friends(Messenger *m) | |||
1882 | set_friend_userstatus(m, i, status); | 1929 | set_friend_userstatus(m, i, status); |
1883 | break; | 1930 | break; |
1884 | } | 1931 | } |
1932 | |||
1933 | case PACKET_ID_TYPING: { | ||
1934 | if (data_length != 1) | ||
1935 | break; | ||
1936 | |||
1937 | uint8_t typing = data[0]; | ||
1938 | |||
1939 | if (m->friend_typingchange) | ||
1940 | m->friend_typingchange(m, i, typing, m->friend_typingchange_userdata); | ||
1941 | |||
1942 | set_friend_typing(m, i, typing); | ||
1943 | break; | ||
1944 | } | ||
1885 | 1945 | ||
1886 | case PACKET_ID_MESSAGE: { | 1946 | case PACKET_ID_MESSAGE: { |
1887 | uint8_t *message_id = data; | 1947 | uint8_t *message_id = data; |