diff options
Diffstat (limited to 'toxcore/Messenger.c')
-rw-r--r-- | toxcore/Messenger.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index aa575382..021d93f7 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -781,6 +781,17 @@ void m_callback_group_message(Messenger *m, void (*function)(Messenger *m, int, | |||
781 | m->group_message_userdata = userdata; | 781 | m->group_message_userdata = userdata; |
782 | } | 782 | } |
783 | 783 | ||
784 | /* Set the callback for group actions. | ||
785 | * | ||
786 | * Function(Messenger *m, int friendnumber, uint8_t *group_public_key, void *userdata) | ||
787 | */ | ||
788 | void m_callback_group_action(Messenger *m, void (*function)(Messenger *m, int, int, uint8_t *, uint16_t, void *), | ||
789 | void *userdata) | ||
790 | { | ||
791 | m->group_action = function; | ||
792 | m->group_action_userdata = userdata; | ||
793 | } | ||
794 | |||
784 | /* Set callback function for peer name list changes. | 795 | /* Set callback function for peer name list changes. |
785 | * | 796 | * |
786 | * It gets called every time the name list changes(new peer/name, deleted peer) | 797 | * It gets called every time the name list changes(new peer/name, deleted peer) |
@@ -817,6 +828,18 @@ static void group_message_function(Group_Chat *chat, int peer_number, uint8_t *m | |||
817 | (*m->group_message)(m, i, peer_number, message, length, m->group_message_userdata); | 828 | (*m->group_message)(m, i, peer_number, message, length, m->group_message_userdata); |
818 | } | 829 | } |
819 | 830 | ||
831 | static void group_action_function(Group_Chat *chat, int peer_number, uint8_t *action, uint16_t length, void *userdata) | ||
832 | { | ||
833 | Messenger *m = userdata; | ||
834 | int i = get_chat_num(m, chat); | ||
835 | |||
836 | if (i == -1) | ||
837 | return; | ||
838 | |||
839 | if (m->group_action) | ||
840 | (*m->group_action)(m, i, peer_number, action, length, m->group_action_userdata); | ||
841 | } | ||
842 | |||
820 | static void group_namelistchange_function(Group_Chat *chat, int peer, uint8_t change, void *userdata) | 843 | static void group_namelistchange_function(Group_Chat *chat, int peer, uint8_t change, void *userdata) |
821 | { | 844 | { |
822 | Messenger *m = userdata; | 845 | Messenger *m = userdata; |
@@ -847,6 +870,7 @@ int add_groupchat(Messenger *m) | |||
847 | return -1; | 870 | return -1; |
848 | 871 | ||
849 | callback_groupmessage(newchat, &group_message_function, m); | 872 | callback_groupmessage(newchat, &group_message_function, m); |
873 | callback_groupaction(newchat, &group_action_function, m); | ||
850 | callback_namelistchange(newchat, &group_namelistchange_function, m); | 874 | callback_namelistchange(newchat, &group_namelistchange_function, m); |
851 | /* TODO: remove this (group nicks should not be tied to the global one) */ | 875 | /* TODO: remove this (group nicks should not be tied to the global one) */ |
852 | set_nick(newchat, m->name, m->name_length); | 876 | set_nick(newchat, m->name, m->name_length); |
@@ -868,6 +892,7 @@ int add_groupchat(Messenger *m) | |||
868 | return -1; | 892 | return -1; |
869 | 893 | ||
870 | callback_groupmessage(temp[m->numchats], &group_message_function, m); | 894 | callback_groupmessage(temp[m->numchats], &group_message_function, m); |
895 | callback_groupaction(temp[m->numchats], &group_action_function, m); | ||
871 | callback_namelistchange(temp[m->numchats], &group_namelistchange_function, m); | 896 | callback_namelistchange(temp[m->numchats], &group_namelistchange_function, m); |
872 | /* TODO: remove this (group nicks should not be tied to the global one) */ | 897 | /* TODO: remove this (group nicks should not be tied to the global one) */ |
873 | set_nick(temp[m->numchats], m->name, m->name_length); | 898 | set_nick(temp[m->numchats], m->name, m->name_length); |
@@ -1025,7 +1050,6 @@ int join_groupchat(Messenger *m, int friendnumber, uint8_t *friend_group_public_ | |||
1025 | * return 0 on success | 1050 | * return 0 on success |
1026 | * return -1 on failure | 1051 | * return -1 on failure |
1027 | */ | 1052 | */ |
1028 | |||
1029 | int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length) | 1053 | int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t length) |
1030 | { | 1054 | { |
1031 | if (groupnumber_not_valid(m, groupnumber)) | 1055 | if (groupnumber_not_valid(m, groupnumber)) |
@@ -1037,6 +1061,21 @@ int group_message_send(Messenger *m, int groupnumber, uint8_t *message, uint32_t | |||
1037 | return -1; | 1061 | return -1; |
1038 | } | 1062 | } |
1039 | 1063 | ||
1064 | /* send a group action | ||
1065 | * return 0 on success | ||
1066 | * return -1 on failure | ||
1067 | */ | ||
1068 | int group_action_send(Messenger *m, int groupnumber, uint8_t *action, uint32_t length) | ||
1069 | { | ||
1070 | if (groupnumber_not_valid(m, groupnumber)) | ||
1071 | return -1; | ||
1072 | |||
1073 | if (group_sendaction(m->chats[groupnumber], action, length) > 0) | ||
1074 | return 0; | ||
1075 | |||
1076 | return -1; | ||
1077 | } | ||
1078 | |||
1040 | /* Return the number of peers in the group chat on success. | 1079 | /* Return the number of peers in the group chat on success. |
1041 | * return -1 on failure | 1080 | * return -1 on failure |
1042 | */ | 1081 | */ |