diff options
Diffstat (limited to 'toxcore/group.c')
-rw-r--r-- | toxcore/group.c | 71 |
1 files changed, 46 insertions, 25 deletions
diff --git a/toxcore/group.c b/toxcore/group.c index 730378ea..55531ad3 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -808,6 +808,25 @@ int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, u | |||
808 | return 0; | 808 | return 0; |
809 | } | 809 | } |
810 | 810 | ||
811 | int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber) | ||
812 | { | ||
813 | Group_c *g = get_group_c(g_c, groupnumber); | ||
814 | |||
815 | if (!g) { | ||
816 | return -1; | ||
817 | } | ||
818 | |||
819 | if ((uint32_t)peernumber >= g->numpeers) { | ||
820 | return -1; | ||
821 | } | ||
822 | |||
823 | if (g->group[peernumber].nick_len == 0) { | ||
824 | return 8; | ||
825 | } | ||
826 | |||
827 | return g->group[peernumber].nick_len; | ||
828 | } | ||
829 | |||
811 | /* Copy the name of peernumber who is in groupnumber to name. | 830 | /* Copy the name of peernumber who is in groupnumber to name. |
812 | * name must be at least MAX_NAME_LENGTH long. | 831 | * name must be at least MAX_NAME_LENGTH long. |
813 | * | 832 | * |
@@ -1063,8 +1082,8 @@ int join_groupchat(Group_Chats *g_c, int32_t friendnumber, uint8_t expected_type | |||
1063 | * | 1082 | * |
1064 | * data of length is what needs to be passed to join_groupchat(). | 1083 | * data of length is what needs to be passed to join_groupchat(). |
1065 | */ | 1084 | */ |
1066 | void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, uint8_t, const uint8_t *, | 1085 | void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, int, const uint8_t *, |
1067 | uint16_t, void *), void *userdata) | 1086 | size_t, void *), void *userdata) |
1068 | { | 1087 | { |
1069 | g_c->invite_callback = function; | 1088 | g_c->invite_callback = function; |
1070 | g_c->invite_callback_userdata = userdata; | 1089 | g_c->invite_callback_userdata = userdata; |
@@ -1074,24 +1093,14 @@ void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, in | |||
1074 | * | 1093 | * |
1075 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) | 1094 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) |
1076 | */ | 1095 | */ |
1077 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, | 1096 | void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, |
1097 | size_t, | ||
1078 | void *), void *userdata) | 1098 | void *), void *userdata) |
1079 | { | 1099 | { |
1080 | g_c->message_callback = function; | 1100 | g_c->message_callback = function; |
1081 | g_c->message_callback_userdata = userdata; | 1101 | g_c->message_callback_userdata = userdata; |
1082 | } | 1102 | } |
1083 | 1103 | ||
1084 | /* Set the callback for group actions. | ||
1085 | * | ||
1086 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) | ||
1087 | */ | ||
1088 | void g_callback_group_action(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, | ||
1089 | void *), void *userdata) | ||
1090 | { | ||
1091 | g_c->action_callback = function; | ||
1092 | g_c->action_callback_userdata = userdata; | ||
1093 | } | ||
1094 | |||
1095 | /* Set handlers for custom lossy packets. | 1104 | /* Set handlers for custom lossy packets. |
1096 | * | 1105 | * |
1097 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. | 1106 | * NOTE: Handler must return 0 if packet is to be relayed, -1 if the packet should not be relayed. |
@@ -1121,7 +1130,8 @@ void g_callback_group_namelistchange(Group_Chats *g_c, void (*function)(Messenge | |||
1121 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) | 1130 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) |
1122 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) | 1131 | * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) |
1123 | */ | 1132 | */ |
1124 | void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint8_t, | 1133 | void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *, |
1134 | size_t, | ||
1125 | void *), void *userdata) | 1135 | void *), void *userdata) |
1126 | { | 1136 | { |
1127 | g_c->title_callback = function; | 1137 | g_c->title_callback = function; |
@@ -1298,13 +1308,28 @@ int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *tit | |||
1298 | return -1; | 1308 | return -1; |
1299 | } | 1309 | } |
1300 | 1310 | ||
1311 | int group_title_get_size(const Group_Chats *g_c, int groupnumber) | ||
1312 | { | ||
1313 | Group_c *g = get_group_c(g_c, groupnumber); | ||
1314 | |||
1315 | if (!g) { | ||
1316 | return -1; | ||
1317 | } | ||
1318 | |||
1319 | if (g->title_len == 0 || g->title_len > MAX_NAME_LENGTH) { | ||
1320 | return -1; | ||
1321 | } | ||
1322 | |||
1323 | return g->title_len; | ||
1324 | } | ||
1325 | |||
1301 | /* Get group title from groupnumber and put it in title. | 1326 | /* Get group title from groupnumber and put it in title. |
1302 | * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes. | 1327 | * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes. |
1303 | * | 1328 | * |
1304 | * return length of copied title if success. | 1329 | * return length of copied title if success. |
1305 | * return -1 if failure. | 1330 | * return -1 if failure. |
1306 | */ | 1331 | */ |
1307 | int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title, uint32_t max_length) | 1332 | int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title) |
1308 | { | 1333 | { |
1309 | Group_c *g = get_group_c(g_c, groupnumber); | 1334 | Group_c *g = get_group_c(g_c, groupnumber); |
1310 | 1335 | ||
@@ -1316,12 +1341,8 @@ int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title, uin | |||
1316 | return -1; | 1341 | return -1; |
1317 | } | 1342 | } |
1318 | 1343 | ||
1319 | if (max_length > g->title_len) { | 1344 | memcpy(title, g->title, g->title_len); |
1320 | max_length = g->title_len; | 1345 | return g->title_len; |
1321 | } | ||
1322 | |||
1323 | memcpy(title, g->title, max_length); | ||
1324 | return max_length; | ||
1325 | } | 1346 | } |
1326 | 1347 | ||
1327 | static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length) | 1348 | static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length) |
@@ -2035,7 +2056,7 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const | |||
2035 | 2056 | ||
2036 | // TODO(irungentoo): | 2057 | // TODO(irungentoo): |
2037 | if (g_c->message_callback) { | 2058 | if (g_c->message_callback) { |
2038 | g_c->message_callback(g_c->m, groupnumber, index, newmsg, msg_data_len, g_c->message_callback_userdata); | 2059 | g_c->message_callback(g_c->m, groupnumber, index, 0, newmsg, msg_data_len, g_c->message_callback_userdata); |
2039 | } | 2060 | } |
2040 | 2061 | ||
2041 | break; | 2062 | break; |
@@ -2051,8 +2072,8 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const | |||
2051 | newmsg[msg_data_len] = 0; | 2072 | newmsg[msg_data_len] = 0; |
2052 | 2073 | ||
2053 | // TODO(irungentoo): | 2074 | // TODO(irungentoo): |
2054 | if (g_c->action_callback) { | 2075 | if (g_c->message_callback) { |
2055 | g_c->action_callback(g_c->m, groupnumber, index, newmsg, msg_data_len, g_c->action_callback_userdata); | 2076 | g_c->message_callback(g_c->m, groupnumber, index, 1, newmsg, msg_data_len, g_c->message_callback_userdata); |
2056 | } | 2077 | } |
2057 | 2078 | ||
2058 | break; | 2079 | break; |