diff options
author | irungentoo <irungentoo@gmail.com> | 2013-11-23 17:19:02 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-11-23 17:19:02 -0500 |
commit | f21a9a7666e0f93cd8c19d1491c92526424ae0cb (patch) | |
tree | 2ebed714b388f18917ac6473ad6d7ec9f8ed8cfc /toxcore/Messenger.c | |
parent | d2b56faded6e88e916d8f291c1cdff82f5cdd1ff (diff) |
Added callback that tells you when the peer name list of a group chat changes.
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 889de367..acb038df 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -779,20 +779,51 @@ void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, | |||
779 | m->group_message = function; | 779 | m->group_message = function; |
780 | m->group_message_userdata = userdata; | 780 | m->group_message_userdata = userdata; |
781 | } | 781 | } |
782 | static void group_message_function(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) | 782 | |
783 | /* Set callback function for peer name list changes. | ||
784 | * | ||
785 | * It gets called every time the name list changes(new peer/name, deleted peer) | ||
786 | * Function(Tox *tox, int groupnumber, void *userdata) | ||
787 | */ | ||
788 | void m_callback_group_namelistchange(Messenger *m, void (*function)(Messenger *m, int, void *), void *userdata) | ||
783 | { | 789 | { |
784 | Messenger *m = userdata; | 790 | m->group_namelistchange = function; |
785 | uint32_t i; | 791 | m->group_namelistchange_userdata = userdata; |
792 | } | ||
786 | 793 | ||
794 | static int get_chat_num(Messenger *m, Group_Chat *chat) | ||
795 | { | ||
796 | uint32_t i; | ||
787 | for (i = 0; i < m->numchats; ++i) { //TODO: remove this | 797 | for (i = 0; i < m->numchats; ++i) { //TODO: remove this |
788 | if (m->chats[i] == chat) | 798 | if (m->chats[i] == chat) |
789 | break; | 799 | return i; |
790 | } | 800 | } |
801 | return -1; | ||
802 | } | ||
803 | |||
804 | static void group_message_function(Group_Chat *chat, int peer_number, uint8_t *message, uint16_t length, void *userdata) | ||
805 | { | ||
806 | Messenger *m = userdata; | ||
807 | int i = get_chat_num(m, chat); | ||
808 | if (i == -1) | ||
809 | return; | ||
791 | 810 | ||
792 | if (m->group_message) | 811 | if (m->group_message) |
793 | (*m->group_message)(m, i, peer_number, message, length, m->group_message_userdata); | 812 | (*m->group_message)(m, i, peer_number, message, length, m->group_message_userdata); |
794 | } | 813 | } |
795 | 814 | ||
815 | static void group_namelistchange_function(Group_Chat *chat, void *userdata) | ||
816 | { | ||
817 | Messenger *m = userdata; | ||
818 | int i = get_chat_num(m, chat); | ||
819 | if (i == -1) | ||
820 | return; | ||
821 | |||
822 | if (m->group_namelistchange) | ||
823 | (*m->group_namelistchange)(m, i, m->group_namelistchange_userdata); | ||
824 | } | ||
825 | |||
826 | |||
796 | /* Creates a new groupchat and puts it in the chats array. | 827 | /* Creates a new groupchat and puts it in the chats array. |
797 | * | 828 | * |
798 | * return group number on success. | 829 | * return group number on success. |
@@ -810,6 +841,7 @@ int add_groupchat(Messenger *m) | |||
810 | return -1; | 841 | return -1; |
811 | 842 | ||
812 | callback_groupmessage(newchat, &group_message_function, m); | 843 | callback_groupmessage(newchat, &group_message_function, m); |
844 | callback_namelistchange(newchat, &group_namelistchange_function, m); | ||
813 | /* TODO: remove this (group nicks should not be tied to the global one) */ | 845 | /* TODO: remove this (group nicks should not be tied to the global one) */ |
814 | set_nick(newchat, m->name, m->name_length); | 846 | set_nick(newchat, m->name, m->name_length); |
815 | m->chats[i] = newchat; | 847 | m->chats[i] = newchat; |
@@ -830,6 +862,7 @@ int add_groupchat(Messenger *m) | |||
830 | 862 | ||
831 | m->chats = temp; | 863 | m->chats = temp; |
832 | callback_groupmessage(temp[m->numchats], &group_message_function, m); | 864 | callback_groupmessage(temp[m->numchats], &group_message_function, m); |
865 | callback_namelistchange(temp[m->numchats], &group_namelistchange_function, m); | ||
833 | /* TODO: remove this (group nicks should not be tied to the global one) */ | 866 | /* TODO: remove this (group nicks should not be tied to the global one) */ |
834 | set_nick(temp[m->numchats], m->name, m->name_length); | 867 | set_nick(temp[m->numchats], m->name, m->name_length); |
835 | ++m->numchats; | 868 | ++m->numchats; |