summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--auto_tests/tox_test.c40
-rw-r--r--other/apidsl/tox.in.h266
-rw-r--r--testing/irc_syncbot.c24
-rw-r--r--testing/nTox.c57
-rw-r--r--toxcore/Makefile.inc3
-rw-r--r--toxcore/group.c71
-rw-r--r--toxcore/group.h30
-rw-r--r--toxcore/tox.h237
-rw-r--r--toxcore/tox_group.c160
-rw-r--r--toxcore/tox_group.h179
11 files changed, 703 insertions, 365 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c5e8294f..6ad94588 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -350,7 +350,6 @@ install(FILES
350install(FILES 350install(FILES
351 toxav/toxav.h 351 toxav/toxav.h
352 toxcore/tox.h 352 toxcore/tox.h
353 toxcore/tox_group.h
354 toxdns/toxdns.h 353 toxdns/toxdns.h
355 toxencryptsave/toxencryptsave.h 354 toxencryptsave/toxencryptsave.h
356 DESTINATION "include/tox") 355 DESTINATION "include/tox")
diff --git a/auto_tests/tox_test.c b/auto_tests/tox_test.c
index d08fc125..14510ea4 100644
--- a/auto_tests/tox_test.c
+++ b/auto_tests/tox_test.c
@@ -1172,26 +1172,26 @@ static void g_accept_friend_request(Tox *m, const uint8_t *public_key, const uin
1172static Tox *invite_tox; 1172static Tox *invite_tox;
1173static unsigned int invite_counter; 1173static unsigned int invite_counter;
1174 1174
1175static void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t type, const uint8_t *data, 1175static void print_group_invite_callback(Tox *tox, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, const uint8_t *data,
1176 uint16_t length, 1176 size_t length,
1177 void *userdata) 1177 void *userdata)
1178{ 1178{
1179 if (*((uint32_t *)userdata) != 234212) { 1179 if (*((uint32_t *)userdata) != 234212) {
1180 return; 1180 return;
1181 } 1181 }
1182 1182
1183 if (type != TOX_GROUPCHAT_TYPE_TEXT) { 1183 if (type != TOX_CONFERENCE_TYPE_TEXT) {
1184 return; 1184 return;
1185 } 1185 }
1186 1186
1187 int g_num; 1187 int g_num;
1188 1188
1189 if ((g_num = tox_join_groupchat(tox, friendnumber, data, length)) == -1) { 1189 if ((g_num = tox_conference_join(tox, friendnumber, data, length, NULL)) == -1) {
1190 return; 1190 return;
1191 } 1191 }
1192 1192
1193 ck_assert_msg(g_num == 0, "Group number was not 0"); 1193 ck_assert_msg(g_num == 0, "Group number was not 0");
1194 ck_assert_msg(tox_join_groupchat(tox, friendnumber, data, length) == -1, 1194 ck_assert_msg(tox_conference_join(tox, friendnumber, data, length, NULL) == -1,
1195 "Joining groupchat twice should be impossible."); 1195 "Joining groupchat twice should be impossible.");
1196 1196
1197 invite_tox = tox; 1197 invite_tox = tox;
@@ -1200,7 +1200,8 @@ static void print_group_invite_callback(Tox *tox, int32_t friendnumber, uint8_t
1200 1200
1201static unsigned int num_recv; 1201static unsigned int num_recv;
1202 1202
1203static void print_group_message(Tox *tox, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, 1203static void print_group_message(Tox *tox, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type,
1204 const uint8_t *message, size_t length,
1204 void *userdata) 1205 void *userdata)
1205{ 1206{
1206 if (*((uint32_t *)userdata) != 234212) { 1207 if (*((uint32_t *)userdata) != 234212) {
@@ -1226,7 +1227,7 @@ group_test_restart:
1226 toxes[i] = tox_new(0, 0); 1227 toxes[i] = tox_new(0, 0);
1227 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i); 1228 ck_assert_msg(toxes[i] != 0, "Failed to create tox instances %u", i);
1228 tox_callback_friend_request(toxes[i], &g_accept_friend_request); 1229 tox_callback_friend_request(toxes[i], &g_accept_friend_request);
1229 tox_callback_group_invite(toxes[i], &print_group_invite_callback, &to_comp); 1230 tox_callback_conference_invite(toxes[i], &print_group_invite_callback, &to_comp);
1230 } 1231 }
1231 1232
1232 { 1233 {
@@ -1264,9 +1265,9 @@ group_test_restart:
1264 1265
1265 printf("friends connected, took %llu seconds\n", time(NULL) - cur_time); 1266 printf("friends connected, took %llu seconds\n", time(NULL) - cur_time);
1266 1267
1267 ck_assert_msg(tox_add_groupchat(toxes[0]) != -1, "Failed to create group"); 1268 ck_assert_msg(tox_conference_new(toxes[0], NULL) != -1, "Failed to create group");
1268 ck_assert_msg(tox_invite_friend(toxes[0], 0, 0) == 0, "Failed to invite friend"); 1269 ck_assert_msg(tox_conference_invite(toxes[0], 0, 0, NULL) == 0, "Failed to invite friend");
1269 ck_assert_msg(tox_group_set_title(toxes[0], 0, (const uint8_t *)"Gentoo", sizeof("Gentoo") - 1) == 0, 1270 ck_assert_msg(tox_conference_set_title(toxes[0], 0, (const uint8_t *)"Gentoo", sizeof("Gentoo") - 1, NULL) == 0,
1270 "Failed to set group title"); 1271 "Failed to set group title");
1271 invite_counter = ~0; 1272 invite_counter = ~0;
1272 1273
@@ -1279,7 +1280,7 @@ group_test_restart:
1279 } 1280 }
1280 1281
1281 if (!invite_counter) { 1282 if (!invite_counter) {
1282 ck_assert_msg(tox_invite_friend(invite_tox, 0, 0) == 0, "Failed to invite friend"); 1283 ck_assert_msg(tox_conference_invite(invite_tox, 0, 0, NULL) == 0, "Failed to invite friend");
1283 } 1284 }
1284 1285
1285 if (done == invite_counter) { 1286 if (done == invite_counter) {
@@ -1291,7 +1292,7 @@ group_test_restart:
1291 } 1292 }
1292 1293
1293 for (i = 0; i < NUM_GROUP_TOX; ++i) { 1294 for (i = 0; i < NUM_GROUP_TOX; ++i) {
1294 int num_peers = tox_group_number_peers(toxes[i], 0); 1295 int num_peers = tox_conference_peer_count(toxes[i], 0, NULL);
1295 1296
1296 /** 1297 /**
1297 * Group chats fail unpredictably, currently they'll rerun as many times 1298 * Group chats fail unpredictably, currently they'll rerun as many times
@@ -1321,7 +1322,8 @@ group_test_restart:
1321 NUM_GROUP_TOX, i, num_peers); 1322 NUM_GROUP_TOX, i, num_peers);
1322 1323
1323 uint8_t title[2048]; 1324 uint8_t title[2048];
1324 int ret = tox_group_get_title(toxes[i], 0, title, sizeof(title)); 1325 int ret = tox_conference_get_title_size(toxes[i], 0, NULL);
1326 tox_conference_get_title(toxes[i], 0, title, NULL);
1325 ck_assert_msg(ret == sizeof("Gentoo") - 1, "Wrong title length"); 1327 ck_assert_msg(ret == sizeof("Gentoo") - 1, "Wrong title length");
1326 ck_assert_msg(memcmp("Gentoo", title, ret) == 0, "Wrong title"); 1328 ck_assert_msg(memcmp("Gentoo", title, ret) == 0, "Wrong title");
1327 } 1329 }
@@ -1329,11 +1331,13 @@ group_test_restart:
1329 printf("group connected\n"); 1331 printf("group connected\n");
1330 1332
1331 for (i = 0; i < NUM_GROUP_TOX; ++i) { 1333 for (i = 0; i < NUM_GROUP_TOX; ++i) {
1332 tox_callback_group_message(toxes[i], &print_group_message, &to_comp); 1334 tox_callback_conference_message(toxes[i], &print_group_message, &to_comp);
1333 } 1335 }
1334 1336
1335 ck_assert_msg(tox_group_message_send(toxes[rand() % NUM_GROUP_TOX], 0, (const uint8_t *)"Install Gentoo", 1337 ck_assert_msg(
1336 sizeof("Install Gentoo") - 1) == 0, "Failed to send group message."); 1338 tox_conference_send_message(
1339 toxes[rand() % NUM_GROUP_TOX], 0, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"Install Gentoo",
1340 sizeof("Install Gentoo") - 1, NULL) == 0, "Failed to send group message.");
1337 num_recv = 0; 1341 num_recv = 0;
1338 1342
1339 for (j = 0; j < 20; ++j) { 1343 for (j = 0; j < 20; ++j) {
@@ -1348,7 +1352,7 @@ group_test_restart:
1348 ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages."); 1352 ck_assert_msg(num_recv == NUM_GROUP_TOX, "Failed to recv group messages.");
1349 1353
1350 for (k = NUM_GROUP_TOX; k != 0 ; --k) { 1354 for (k = NUM_GROUP_TOX; k != 0 ; --k) {
1351 tox_del_groupchat(toxes[k - 1], 0); 1355 tox_conference_delete(toxes[k - 1], 0, NULL);
1352 1356
1353 for (j = 0; j < 10; ++j) { 1357 for (j = 0; j < 10; ++j) {
1354 for (i = 0; i < NUM_GROUP_TOX; ++i) { 1358 for (i = 0; i < NUM_GROUP_TOX; ++i) {
@@ -1359,7 +1363,7 @@ group_test_restart:
1359 } 1363 }
1360 1364
1361 for (i = 0; i < (k - 1); ++i) { 1365 for (i = 0; i < (k - 1); ++i) {
1362 int num_peers = tox_group_number_peers(toxes[i], 0); 1366 int num_peers = tox_conference_peer_count(toxes[i], 0, NULL);
1363 ck_assert_msg(num_peers == (k - 1), "\n\tBad number of group peers (post check)." 1367 ck_assert_msg(num_peers == (k - 1), "\n\tBad number of group peers (post check)."
1364 "\n\t\t\tExpected: %u but tox_instance(%u) only has: %i\n\n", 1368 "\n\t\t\tExpected: %u but tox_instance(%u) only has: %i\n\n",
1365 (k - 1), i, num_peers); 1369 (k - 1), i, num_peers);
diff --git a/other/apidsl/tox.in.h b/other/apidsl/tox.in.h
index d14e48ba..cd802a94 100644
--- a/other/apidsl/tox.in.h
+++ b/other/apidsl/tox.in.h
@@ -1470,7 +1470,8 @@ namespace friend {
1470 * containing the message text. 1470 * containing the message text.
1471 * @param length Length of the message to be sent. 1471 * @param length Length of the message to be sent.
1472 */ 1472 */
1473 uint32_t message(uint32_t friend_number, MESSAGE_TYPE type, const uint8_t[length <= MAX_MESSAGE_LENGTH] message) { 1473 uint32_t message(uint32_t friend_number, MESSAGE_TYPE type,
1474 const uint8_t[length <= MAX_MESSAGE_LENGTH] message) {
1474 NULL, 1475 NULL,
1475 /** 1476 /**
1476 * The friend number did not designate a valid friend. 1477 * The friend number did not designate a valid friend.
@@ -1537,8 +1538,8 @@ namespace friend {
1537 * @param length The size of the message byte array. 1538 * @param length The size of the message byte array.
1538 */ 1539 */
1539 typedef void(const uint8_t[PUBLIC_KEY_SIZE] public_key 1540 typedef void(const uint8_t[PUBLIC_KEY_SIZE] public_key
1540 //, uint32_t time_delta 1541 //, uint32_t time_delta
1541 , const uint8_t[length <= MAX_MESSAGE_LENGTH] message); 1542 , const uint8_t[length <= MAX_MESSAGE_LENGTH] message);
1542 } 1543 }
1543 1544
1544 1545
@@ -1555,8 +1556,9 @@ namespace friend {
1555 * @see ${event request} for more information on time_delta. 1556 * @see ${event request} for more information on time_delta.
1556 */ 1557 */
1557 typedef void(uint32_t friend_number 1558 typedef void(uint32_t friend_number
1558 //, uint32_t time_delta 1559 //, uint32_t time_delta
1559 , MESSAGE_TYPE type, const uint8_t[length <= MAX_MESSAGE_LENGTH] message); 1560 , MESSAGE_TYPE type,
1561 const uint8_t[length <= MAX_MESSAGE_LENGTH] message);
1560 } 1562 }
1561 1563
1562} 1564}
@@ -1766,8 +1768,10 @@ namespace file {
1766 * 1768 *
1767 * @return true on success. 1769 * @return true on success.
1768 */ 1770 */
1769 const bool get_file_id(uint32_t friend_number, uint32_t file_number, uint8_t[FILE_ID_LENGTH] file_id) 1771 uint8_t[FILE_ID_LENGTH] file_id {
1770 with error for get; 1772 get(uint32_t friend_number, uint32_t file_number)
1773 with error for get;
1774 }
1771 1775
1772} 1776}
1773 1777
@@ -1830,7 +1834,7 @@ namespace file {
1830 * unknown or streaming. 1834 * unknown or streaming.
1831 * @param file_id A file identifier of length $FILE_ID_LENGTH that can be used to 1835 * @param file_id A file identifier of length $FILE_ID_LENGTH that can be used to
1832 * uniquely identify file transfers across core restarts. If NULL, a random one will 1836 * uniquely identify file transfers across core restarts. If NULL, a random one will
1833 * be generated by core. It can then be obtained by using $get_file_id(). 1837 * be generated by core. It can then be obtained by using ${file_id.get}().
1834 * @param filename Name of the file. Does not need to be the actual name. This 1838 * @param filename Name of the file. Does not need to be the actual name. This
1835 * name will be sent along with the file send request. 1839 * name will be sent along with the file send request.
1836 * @param filename_length Size in bytes of the filename. 1840 * @param filename_length Size in bytes of the filename.
@@ -2019,12 +2023,245 @@ namespace file {
2019 * 2023 *
2020 ******************************************************************************/ 2024 ******************************************************************************/
2021 2025
2026error for conference {
2027 /**
2028 * Some error occurred.
2029 */
2030 FAILURE,
2031}
2032
2033namespace conference {
2022 2034
2023/****************************************************************************** 2035 /**
2024 * 2036 * Conference types for the ${event invite} event.
2025 * :: Group chat message sending and receiving 2037 */
2026 * 2038 enum class TYPE {
2027 ******************************************************************************/ 2039 /**
2040 * Text-only conferences that must be accepted with the $join function.
2041 */
2042 TEXT,
2043 /**
2044 * Video conference. The function to accept these is in toxav.
2045 */
2046 AV,
2047 }
2048
2049
2050 /**
2051 * This event is triggered when the client is invited to join a conference.
2052 */
2053 event invite {
2054 /**
2055 * The invitation will remain valid until the inviting friend goes offline
2056 * or exits the conference.
2057 *
2058 * @param friend_number The friend who invited us.
2059 * @param type The conference type (text only or audio/video).
2060 * @param cookie A piece of data of variable length required to join the
2061 * conference.
2062 * @param length The length of the cookie.
2063 */
2064 typedef void(uint32_t friend_number, TYPE type, const uint8_t[length] cookie);
2065 }
2066
2067
2068 /**
2069 * Set the callback for group messages.
2070 */
2071 event message {
2072 /**
2073 * TODO
2074 */
2075 typedef void(uint32_t group_number, uint32_t peer_number, MESSAGE_TYPE type,
2076 const uint8_t[length] message);
2077 }
2078
2079
2080 /**
2081 * Set callback function for title changes.
2082 *
2083 * if peer_number == UINT32_MAX, then author is unknown (e.g. initial joining the group)
2084 */
2085 event title {
2086 /**
2087 * TODO
2088 */
2089 typedef void(uint32_t group_number, uint32_t peer_number, const uint8_t[length] title);
2090 }
2091
2092
2093 // rename CHANGE to something different that is a good prefix for the three
2094 // things below.
2095 enum class CHANGE {
2096 PEER_ADD, // JOINED?
2097 PEER_DEL, // PARTED?
2098 PEER_NAME, // NAME_CHANGE?
2099 }
2100
2101 /**
2102 * Set callback function for peer name list changes.
2103 *
2104 * It gets called every time the name list changes(new peer/name, deleted peer)
2105 */
2106 event namelist_change {
2107 /**
2108 * TODO
2109 */
2110 typedef void(uint32_t group_number, uint32_t peer_number, CHANGE change);
2111 }
2112
2113
2114 /**
2115 * Creates a new groupchat.
2116 *
2117 * @return the group number.
2118 */
2119 uint32_t new()
2120 with error for conference;
2121
2122 /**
2123 * Delete a groupchat.
2124 *
2125 * @return true on success.
2126 */
2127 bool delete(uint32_t group_number)
2128 with error for conference;
2129
2130
2131 namespace peer {
2132
2133 /**
2134 * Return the number of peers in the group chat.
2135 */
2136 const uint32_t count(uint32_t group_number)
2137 with error for conference;
2138
2139 uint8_t[size] name {
2140 size(uint32_t group_number, uint32_t peer_number)
2141 with error for conference;
2142
2143 /**
2144 * Copy the name of peer_number who is in group_number to name.
2145 * name must be at least $MAX_NAME_LENGTH long.
2146 *
2147 * return length of name if success
2148 * return -1 if failure
2149 */
2150 get(uint32_t group_number, uint32_t peer_number)
2151 with error for conference;
2152 }
2153
2154 /**
2155 * Copy the public key of peer_number who is in group_number to public_key.
2156 * public_key must be $PUBLIC_KEY_SIZE long.
2157 *
2158 * returns 0 on success
2159 * returns -1 on failure
2160 */
2161 uint8_t[PUBLIC_KEY_SIZE] public_key {
2162 get(uint32_t group_number, uint32_t peer_number)
2163 with error for conference;
2164 }
2165
2166 /**
2167 * Check if the current peer_number corresponds to ours.
2168 *
2169 * return 1 if the peer_number corresponds to ours.
2170 * return 0 on failure.
2171 */
2172 const bool number_is_ours(uint32_t group_number, uint32_t peer_number);
2173
2174 }
2175
2176
2177 /**
2178 * invite friend_number to group_number
2179 * return 0 on success
2180 * return -1 on failure
2181 */
2182 bool invite(uint32_t friend_number, uint32_t group_number)
2183 with error for conference;
2184
2185
2186 /**
2187 * Join a group (you need to have been invited first.) using cookie of length obtained
2188 * in the group invite callback.
2189 *
2190 * returns group number on success
2191 * returns -1 on failure.
2192 */
2193 uint32_t join(uint32_t friend_number, const uint8_t[length] cookie)
2194 with error for conference;
2195
2196
2197 namespace send {
2198
2199 /**
2200 * send a group message
2201 * return 0 on success
2202 * return -1 on failure
2203 */
2204 bool message(uint32_t group_number, MESSAGE_TYPE type, const uint8_t[length] message)
2205 with error for conference;
2206
2207 }
2208
2209
2210 uint8_t[length <= MAX_NAME_LENGTH] title {
2211 size(uint32_t group_number)
2212 with error for conference;
2213
2214 /**
2215 * Get group title from group_number and put it in title.
2216 * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes.
2217 *
2218 * return length of copied title if success.
2219 * return -1 if failure.
2220 */
2221 get(uint32_t group_number)
2222 with error for conference;
2223
2224 /**
2225 * set the group's title, limited to MAX_NAME_LENGTH
2226 * return 0 on success
2227 * return -1 on failure
2228 */
2229 set(uint32_t group_number)
2230 with error for conference;
2231 }
2232
2233
2234 uint32_t[size] chatlist {
2235 /**
2236 * Return the number of chats in the instance m.
2237 * You should use this to determine how much memory to allocate
2238 * for copy_chatlist.
2239 */
2240 size();
2241
2242 /**
2243 * Copy a list of valid chat IDs into the array out_list.
2244 * If out_list is NULL, returns 0.
2245 * Otherwise, returns the number of elements copied.
2246 * If the array was too small, the contents
2247 * of out_list will be truncated to list_size.
2248 */
2249 get();
2250 }
2251
2252
2253 /**
2254 * return the type of groupchat ($TYPE) that group_number is.
2255 *
2256 * return -1 on failure.
2257 * return type on success.
2258 */
2259 TYPE type {
2260 get(uint32_t group_number)
2261 with error for conference;
2262 }
2263
2264}
2028 2265
2029 2266
2030/******************************************************************************* 2267/*******************************************************************************
@@ -2188,11 +2425,10 @@ inline namespace self {
2188 2425
2189} 2426}
2190 2427
2428
2191} // class tox 2429} // class tox
2192 2430
2193%{ 2431%{
2194#include "tox_group.h"
2195
2196#ifdef __cplusplus 2432#ifdef __cplusplus
2197} 2433}
2198#endif 2434#endif
diff --git a/testing/irc_syncbot.c b/testing/irc_syncbot.c
index 6aa3875d..7373b4cd 100644
--- a/testing/irc_syncbot.c
+++ b/testing/irc_syncbot.c
@@ -83,10 +83,11 @@ static int reconnect(void)
83 83
84static int current_group = -1; 84static int current_group = -1;
85 85
86static void callback_group_invite(Tox *tox, int fid, uint8_t type, const uint8_t *data, uint16_t length, void *userdata) 86static void callback_group_invite(Tox *tox, uint32_t fid, TOX_CONFERENCE_TYPE type, const uint8_t *data, size_t length,
87 void *userdata)
87{ 88{
88 if (current_group == -1) { 89 if (current_group == -1) {
89 current_group = tox_join_groupchat(tox, fid, data, length); 90 current_group = tox_conference_join(tox, fid, data, length, NULL);
90 } 91 }
91} 92}
92 93
@@ -95,13 +96,13 @@ static void callback_friend_message(Tox *tox, uint32_t fid, TOX_MESSAGE_TYPE typ
95 void *userdata) 96 void *userdata)
96{ 97{
97 if (length == 1 && *message == 'c') { 98 if (length == 1 && *message == 'c') {
98 if (tox_del_groupchat(tox, current_group) == 0) { 99 if (tox_conference_delete(tox, current_group, NULL) == 0) {
99 current_group = -1; 100 current_group = -1;
100 } 101 }
101 } 102 }
102 103
103 if (length == 1 && *message == 'i') { 104 if (length == 1 && *message == 'i') {
104 tox_invite_friend(tox, fid, current_group); 105 tox_conference_invite(tox, fid, current_group, NULL);
105 } 106 }
106 107
107 if (length == 1 && *message == 'j' && sock >= 0) { 108 if (length == 1 && *message == 'j' && sock >= 0) {
@@ -109,15 +110,17 @@ static void callback_friend_message(Tox *tox, uint32_t fid, TOX_MESSAGE_TYPE typ
109 } 110 }
110} 111}
111 112
112static void copy_groupmessage(Tox *tox, int groupnumber, int friendgroupnumber, const uint8_t *message, uint16_t length, 113static void copy_groupmessage(Tox *tox, uint32_t groupnumber, uint32_t friendgroupnumber, TOX_MESSAGE_TYPE type,
114 const uint8_t *message, size_t length,
113 void *userdata) 115 void *userdata)
114{ 116{
115 if (tox_group_peernumber_is_ours(tox, groupnumber, friendgroupnumber)) { 117 if (tox_conference_peer_number_is_ours(tox, groupnumber, friendgroupnumber)) {
116 return; 118 return;
117 } 119 }
118 120
119 uint8_t name[TOX_MAX_NAME_LENGTH]; 121 uint8_t name[TOX_MAX_NAME_LENGTH];
120 int namelen = tox_group_peername(tox, groupnumber, friendgroupnumber, name); 122 int namelen = tox_conference_peer_get_name_size(tox, groupnumber, friendgroupnumber, NULL);
123 tox_conference_peer_get_name(tox, groupnumber, friendgroupnumber, name, NULL);
121 124
122 if (namelen == 0 || namelen == -1) { 125 if (namelen == 0 || namelen == -1) {
123 memcpy(name, "<unknown>", 9); 126 memcpy(name, "<unknown>", 9);
@@ -216,7 +219,7 @@ static void send_irc_group(Tox *tox, uint8_t *msg, uint16_t len)
216 219
217 memcpy(message + length, msg + req_len + 2, len - (req_len + 2)); 220 memcpy(message + length, msg + req_len + 2, len - (req_len + 2));
218 length += len - (req_len + 2); 221 length += len - (req_len + 2);
219 tox_group_message_send(tox, current_group, message, length); 222 tox_conference_send_message(tox, current_group, TOX_MESSAGE_TYPE_NORMAL, message, length, NULL);
220} 223}
221 224
222static Tox *init_tox(int argc, char *argv[]) 225static Tox *init_tox(int argc, char *argv[])
@@ -242,9 +245,8 @@ static Tox *init_tox(int argc, char *argv[])
242 245
243 tox_self_set_name(tox, (const uint8_t *)IRC_NAME, sizeof(IRC_NAME) - 1, 0); 246 tox_self_set_name(tox, (const uint8_t *)IRC_NAME, sizeof(IRC_NAME) - 1, 0);
244 tox_callback_friend_message(tox, &callback_friend_message); 247 tox_callback_friend_message(tox, &callback_friend_message);
245 tox_callback_group_invite(tox, &callback_group_invite, 0); 248 tox_callback_conference_invite(tox, &callback_group_invite, 0);
246 tox_callback_group_message(tox, &copy_groupmessage, 0); 249 tox_callback_conference_message(tox, &copy_groupmessage, 0);
247 tox_callback_group_action(tox, &copy_groupmessage, 0);
248 250
249 char temp_id[128]; 251 char temp_id[128];
250 printf("\nEnter the address of irc_syncbots master (38 bytes HEX format):\n"); 252 printf("\nEnter the address of irc_syncbots master (38 bytes HEX format):\n");
diff --git a/testing/nTox.c b/testing/nTox.c
index a12480ec..b1c29c2d 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -529,7 +529,7 @@ static void line_eval(Tox *m, char *line)
529 new_lines(idstring); 529 new_lines(idstring);
530 } else if (inpt_command == 'g') { //create new group chat 530 } else if (inpt_command == 'g') { //create new group chat
531 char msg[256]; 531 char msg[256];
532 sprintf(msg, "[g] Created new group chat with number: %u", tox_add_groupchat(m)); 532 sprintf(msg, "[g] Created new group chat with number: %u", tox_conference_new(m, NULL));
533 new_lines(msg); 533 new_lines(msg);
534 } else if (inpt_command == 'i') { //invite friendnum to groupnum 534 } else if (inpt_command == 'i') { //invite friendnum to groupnum
535 char *posi[1]; 535 char *posi[1];
@@ -537,14 +537,15 @@ static void line_eval(Tox *m, char *line)
537 int groupnumber = strtoul(*posi + 1, NULL, 0); 537 int groupnumber = strtoul(*posi + 1, NULL, 0);
538 char msg[256]; 538 char msg[256];
539 sprintf(msg, "[g] Invited friend number %u to group number %u, returned: %u (0 means success)", friendnumber, 539 sprintf(msg, "[g] Invited friend number %u to group number %u, returned: %u (0 means success)", friendnumber,
540 groupnumber, tox_invite_friend(m, friendnumber, groupnumber)); 540 groupnumber, tox_conference_invite(m, friendnumber, groupnumber, NULL));
541 new_lines(msg); 541 new_lines(msg);
542 } else if (inpt_command == 'z') { //send message to groupnum 542 } else if (inpt_command == 'z') { //send message to groupnum
543 char *posi[1]; 543 char *posi[1];
544 int groupnumber = strtoul(line + prompt_offset, posi, 0); 544 int groupnumber = strtoul(line + prompt_offset, posi, 0);
545 545
546 if (**posi != 0) { 546 if (**posi != 0) {
547 int res = tox_group_message_send(m, groupnumber, (uint8_t *)*posi + 1, strlen(*posi + 1)); 547 int res = tox_conference_send_message(m, groupnumber, TOX_MESSAGE_TYPE_NORMAL, (uint8_t *)*posi + 1, strlen(*posi + 1),
548 NULL);
548 549
549 if (res == 0) { 550 if (res == 0) {
550 char msg[32 + STRING_LENGTH]; 551 char msg[32 + STRING_LENGTH];
@@ -611,7 +612,7 @@ static void line_eval(Tox *m, char *line)
611 612
612 if (posi != NULL) { 613 if (posi != NULL) {
613 char msg[64]; 614 char msg[64];
614 int peer_cnt = tox_group_number_peers(m, group_number); 615 int peer_cnt = tox_conference_peer_count(m, group_number, NULL);
615 616
616 if (peer_cnt < 0) { 617 if (peer_cnt < 0) {
617 new_lines("[g] Invalid group number."); 618 new_lines("[g] Invalid group number.");
@@ -642,7 +643,7 @@ static void line_eval(Tox *m, char *line)
642 } 643 }
643 } else { 644 } else {
644 int groupnumber = - conversation_default - 1; 645 int groupnumber = - conversation_default - 1;
645 int res = tox_group_message_send(m, groupnumber, (uint8_t *)line, strlen(line)); 646 int res = tox_conference_send_message(m, groupnumber, TOX_MESSAGE_TYPE_NORMAL, (uint8_t *)line, strlen(line), NULL);
646 647
647 if (res == 0) { 648 if (res == 0) {
648 char msg[32 + STRING_LENGTH]; 649 char msg[32 + STRING_LENGTH];
@@ -1050,13 +1051,14 @@ static void print_help(char *prog_name)
1050 puts(" -f keyfile [Optional] Specify a keyfile to read from and write to."); 1051 puts(" -f keyfile [Optional] Specify a keyfile to read from and write to.");
1051} 1052}
1052 1053
1053static void print_invite(Tox *m, int friendnumber, uint8_t type, const uint8_t *data, uint16_t length, void *userdata) 1054static void print_invite(Tox *m, uint32_t friendnumber, TOX_CONFERENCE_TYPE type, const uint8_t *data, size_t length,
1055 void *userdata)
1054{ 1056{
1055 char msg[256]; 1057 char msg[256];
1056 1058
1057 if (type == TOX_GROUPCHAT_TYPE_TEXT) { 1059 if (type == TOX_CONFERENCE_TYPE_TEXT) {
1058 sprintf(msg, "[i] received group chat invite from: %u, auto accepting and joining. group number: %u", friendnumber, 1060 sprintf(msg, "[i] received group chat invite from: %u, auto accepting and joining. group number: %u", friendnumber,
1059 tox_join_groupchat(m, friendnumber, data, length)); 1061 tox_conference_join(m, friendnumber, data, length, NULL));
1060 } else { 1062 } else {
1061 sprintf(msg, "[i] Group chat invite received of type %u that could not be accepted by ntox.", type); 1063 sprintf(msg, "[i] Group chat invite received of type %u that could not be accepted by ntox.", type);
1062 } 1064 }
@@ -1066,7 +1068,7 @@ static void print_invite(Tox *m, int friendnumber, uint8_t type, const uint8_t *
1066 1068
1067static void print_groupchatpeers(Tox *m, int groupnumber) 1069static void print_groupchatpeers(Tox *m, int groupnumber)
1068{ 1070{
1069 int num = tox_group_number_peers(m, groupnumber); 1071 int num = tox_conference_peer_count(m, groupnumber, NULL);
1070 1072
1071 if (num < 0) { 1073 if (num < 0) {
1072 return; 1074 return;
@@ -1079,8 +1081,14 @@ static void print_groupchatpeers(Tox *m, int groupnumber)
1079 1081
1080 uint8_t names[num][TOX_MAX_NAME_LENGTH]; 1082 uint8_t names[num][TOX_MAX_NAME_LENGTH];
1081 uint16_t lengths[num]; 1083 uint16_t lengths[num];
1082 tox_group_get_names(m, groupnumber, names, lengths, num); 1084
1083 int i; 1085 int i;
1086
1087 for (i = 0; i < num; ++i) {
1088 lengths[i] = tox_conference_peer_get_name_size(m, groupnumber, i, NULL);
1089 tox_conference_peer_get_name(m, groupnumber, i, names[i], NULL);
1090 }
1091
1084 char numstr[16]; 1092 char numstr[16];
1085 char header[] = "[g]+ "; 1093 char header[] = "[g]+ ";
1086 size_t header_len = strlen(header); 1094 size_t header_len = strlen(header);
@@ -1113,12 +1121,14 @@ static void print_groupchatpeers(Tox *m, int groupnumber)
1113 new_lines_mark(msg, 1); 1121 new_lines_mark(msg, 1);
1114} 1122}
1115 1123
1116static void print_groupmessage(Tox *m, int groupnumber, int peernumber, const uint8_t *message, uint16_t length, 1124static void print_groupmessage(Tox *m, uint32_t groupnumber, uint32_t peernumber, TOX_MESSAGE_TYPE type,
1125 const uint8_t *message, size_t length,
1117 void *userdata) 1126 void *userdata)
1118{ 1127{
1119 char msg[256 + length]; 1128 char msg[256 + length];
1120 uint8_t name[TOX_MAX_NAME_LENGTH] = {0}; 1129 uint8_t name[TOX_MAX_NAME_LENGTH] = {0};
1121 int len = tox_group_peername(m, groupnumber, peernumber, name); 1130 int len = tox_conference_peer_get_name_size(m, groupnumber, peernumber, NULL);
1131 tox_conference_peer_get_name(m, groupnumber, peernumber, name, NULL);
1122 1132
1123 //print_groupchatpeers(m, groupnumber); 1133 //print_groupchatpeers(m, groupnumber);
1124 if (len <= 0) { 1134 if (len <= 0) {
@@ -1133,27 +1143,29 @@ static void print_groupmessage(Tox *m, int groupnumber, int peernumber, const ui
1133 1143
1134 new_lines(msg); 1144 new_lines(msg);
1135} 1145}
1136static void print_groupnamelistchange(Tox *m, int groupnumber, int peernumber, uint8_t change, void *userdata) 1146static void print_groupnamelistchange(Tox *m, uint32_t groupnumber, uint32_t peernumber, TOX_CONFERENCE_CHANGE change,
1147 void *userdata)
1137{ 1148{
1138 char msg[256]; 1149 char msg[256];
1139 1150
1140 if (change == TOX_CHAT_CHANGE_PEER_ADD) { 1151 if (change == TOX_CONFERENCE_CHANGE_PEER_ADD) {
1141 sprintf(msg, "[g] #%i: New peer %i.", groupnumber, peernumber); 1152 sprintf(msg, "[g] #%i: New peer %i.", groupnumber, peernumber);
1142 new_lines(msg); 1153 new_lines(msg);
1143 } else if (change == TOX_CHAT_CHANGE_PEER_DEL) { 1154 } else if (change == TOX_CONFERENCE_CHANGE_PEER_DEL) {
1144 /* if peer was the last in list, it simply dropped, 1155 /* if peer was the last in list, it simply dropped,
1145 * otherwise it was overwritten by the last peer 1156 * otherwise it was overwritten by the last peer
1146 * 1157 *
1147 * adjust output 1158 * adjust output
1148 */ 1159 */
1149 int peers_total = tox_group_number_peers(m, groupnumber); 1160 int peers_total = tox_conference_peer_count(m, groupnumber, NULL);
1150 1161
1151 if (peers_total == peernumber) { 1162 if (peers_total == peernumber) {
1152 sprintf(msg, "[g] #%i: Peer %i left.", groupnumber, peernumber); 1163 sprintf(msg, "[g] #%i: Peer %i left.", groupnumber, peernumber);
1153 new_lines(msg); 1164 new_lines(msg);
1154 } else { 1165 } else {
1155 uint8_t peername[TOX_MAX_NAME_LENGTH] = {0}; 1166 uint8_t peername[TOX_MAX_NAME_LENGTH] = {0};
1156 int len = tox_group_peername(m, groupnumber, peernumber, peername); 1167 int len = tox_conference_peer_get_name_size(m, groupnumber, peernumber, NULL);
1168 tox_conference_peer_get_name(m, groupnumber, peernumber, peername, NULL);
1157 1169
1158 if (len <= 0) { 1170 if (len <= 0) {
1159 peername[0] = 0; 1171 peername[0] = 0;
@@ -1163,9 +1175,10 @@ static void print_groupnamelistchange(Tox *m, int groupnumber, int peernumber, u
1163 peers_total, peername, peernumber); 1175 peers_total, peername, peernumber);
1164 new_lines(msg); 1176 new_lines(msg);
1165 } 1177 }
1166 } else if (change == TOX_CHAT_CHANGE_PEER_NAME) { 1178 } else if (change == TOX_CONFERENCE_CHANGE_PEER_NAME) {
1167 uint8_t peername[TOX_MAX_NAME_LENGTH] = {0}; 1179 uint8_t peername[TOX_MAX_NAME_LENGTH] = {0};
1168 int len = tox_group_peername(m, groupnumber, peernumber, peername); 1180 int len = tox_conference_peer_get_name_size(m, groupnumber, peernumber, NULL);
1181 tox_conference_peer_get_name(m, groupnumber, peernumber, peername, NULL);
1169 1182
1170 if (len <= 0) { 1183 if (len <= 0) {
1171 peername[0] = 0; 1184 peername[0] = 0;
@@ -1343,13 +1356,13 @@ int main(int argc, char *argv[])
1343 tox_callback_friend_message(m, print_message); 1356 tox_callback_friend_message(m, print_message);
1344 tox_callback_friend_name(m, print_nickchange); 1357 tox_callback_friend_name(m, print_nickchange);
1345 tox_callback_friend_status_message(m, print_statuschange); 1358 tox_callback_friend_status_message(m, print_statuschange);
1346 tox_callback_group_invite(m, print_invite, NULL); 1359 tox_callback_conference_invite(m, print_invite, NULL);
1347 tox_callback_group_message(m, print_groupmessage, NULL); 1360 tox_callback_conference_message(m, print_groupmessage, NULL);
1348 tox_callback_file_recv_chunk(m, write_file); 1361 tox_callback_file_recv_chunk(m, write_file);
1349 tox_callback_file_recv_control(m, file_print_control); 1362 tox_callback_file_recv_control(m, file_print_control);
1350 tox_callback_file_recv(m, file_request_accept); 1363 tox_callback_file_recv(m, file_request_accept);
1351 tox_callback_file_chunk_request(m, tox_file_chunk_request); 1364 tox_callback_file_chunk_request(m, tox_file_chunk_request);
1352 tox_callback_group_namelist_change(m, print_groupnamelistchange, NULL); 1365 tox_callback_conference_namelist_change(m, print_groupnamelistchange, NULL);
1353 tox_callback_friend_connection_status(m, print_online); 1366 tox_callback_friend_connection_status(m, print_online);
1354 1367
1355 initscr(); 1368 initscr();
diff --git a/toxcore/Makefile.inc b/toxcore/Makefile.inc
index f73ac3e9..cf1dfa2c 100644
--- a/toxcore/Makefile.inc
+++ b/toxcore/Makefile.inc
@@ -1,8 +1,7 @@
1lib_LTLIBRARIES += libtoxcore.la 1lib_LTLIBRARIES += libtoxcore.la
2 2
3libtoxcore_la_include_HEADERS = \ 3libtoxcore_la_include_HEADERS = \
4 ../toxcore/tox.h \ 4 ../toxcore/tox.h
5 ../toxcore/tox_group.h
6 5
7libtoxcore_la_includedir = $(includedir)/tox 6libtoxcore_la_includedir = $(includedir)/tox
8 7
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
811int 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 */
1066void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, uint8_t, const uint8_t *, 1085void 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 */
1077void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, 1096void 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 */
1088void 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 */
1124void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint8_t, 1133void 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
1311int 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 */
1307int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title, uint32_t max_length) 1332int 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
1327static void handle_friend_invite_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length) 1348static 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;
diff --git a/toxcore/group.h b/toxcore/group.h
index 56151402..6d278dde 100644
--- a/toxcore/group.h
+++ b/toxcore/group.h
@@ -116,15 +116,13 @@ typedef struct {
116 Group_c *chats; 116 Group_c *chats;
117 uint32_t num_chats; 117 uint32_t num_chats;
118 118
119 void (*invite_callback)(Messenger *m, int32_t, uint8_t, const uint8_t *, uint16_t, void *); 119 void (*invite_callback)(Messenger *m, uint32_t, int, const uint8_t *, size_t, void *);
120 void *invite_callback_userdata; 120 void *invite_callback_userdata;
121 void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); 121 void (*message_callback)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *);
122 void *message_callback_userdata; 122 void *message_callback_userdata;
123 void (*action_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *);
124 void *action_callback_userdata;
125 void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *); 123 void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *);
126 void *group_namelistchange_userdata; 124 void *group_namelistchange_userdata;
127 void (*title_callback)(Messenger *m, int, int, const uint8_t *, uint8_t, void *); 125 void (*title_callback)(Messenger *m, uint32_t, uint32_t, const uint8_t *, size_t, void *);
128 void *title_callback_userdata; 126 void *title_callback_userdata;
129 127
130 struct { 128 struct {
@@ -138,29 +136,25 @@ typedef struct {
138 * 136 *
139 * data of length is what needs to be passed to join_groupchat(). 137 * data of length is what needs to be passed to join_groupchat().
140 */ 138 */
141void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, int32_t, uint8_t, const uint8_t *, 139void g_callback_group_invite(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, int, const uint8_t *,
142 uint16_t, void *), void *userdata); 140 size_t, void *), void *userdata);
143 141
144/* Set the callback for group messages. 142/* Set the callback for group messages.
145 * 143 *
146 * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) 144 * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
147 */ 145 */
148void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, 146void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, int, const uint8_t *,
147 size_t,
149 void *), void *userdata); 148 void *), void *userdata);
150 149
151/* Set the callback for group actions.
152 *
153 * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata)
154 */
155void g_callback_group_action(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t,
156 void *), void *userdata);
157 150
158/* Set callback function for title changes. 151/* Set callback function for title changes.
159 * 152 *
160 * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata) 153 * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * title, uint8_t length, void *userdata)
161 * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group) 154 * if friendgroupnumber == -1, then author is unknown (e.g. initial joining the group)
162 */ 155 */
163void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint8_t, 156void g_callback_group_title(Group_Chats *g_c, void (*function)(Messenger *m, uint32_t, uint32_t, const uint8_t *,
157 size_t,
164 void *), void *userdata); 158 void *), void *userdata);
165 159
166/* Set callback function for peer name list changes. 160/* Set callback function for peer name list changes.
@@ -200,6 +194,8 @@ int del_groupchat(Group_Chats *g_c, int groupnumber);
200 */ 194 */
201int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *pk); 195int group_peer_pubkey(const Group_Chats *g_c, int groupnumber, int peernumber, uint8_t *pk);
202 196
197int group_peername_size(const Group_Chats *g_c, int groupnumber, int peernumber);
198
203/* Copy the name of peernumber who is in groupnumber to name. 199/* Copy the name of peernumber who is in groupnumber to name.
204 * name must be at least MAX_NAME_LENGTH long. 200 * name must be at least MAX_NAME_LENGTH long.
205 * 201 *
@@ -242,13 +238,15 @@ int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *ac
242int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint8_t title_len); 238int group_title_send(const Group_Chats *g_c, int groupnumber, const uint8_t *title, uint8_t title_len);
243 239
244 240
241int group_title_get_size(const Group_Chats *g_c, int groupnumber);
242
245/* Get group title from groupnumber and put it in title. 243/* Get group title from groupnumber and put it in title.
246 * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes. 244 * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes.
247 * 245 *
248 * return length of copied title if success. 246 * return length of copied title if success.
249 * return -1 if failure. 247 * return -1 if failure.
250 */ 248 */
251int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title, uint32_t max_length); 249int group_title_get(const Group_Chats *g_c, int groupnumber, uint8_t *title);
252 250
253/* Return the number of peers in the group chat on success. 251/* Return the number of peers in the group chat on success.
254 * return -1 on failure 252 * return -1 on failure
diff --git a/toxcore/tox.h b/toxcore/tox.h
index 61c4227a..7b04bb14 100644
--- a/toxcore/tox.h
+++ b/toxcore/tox.h
@@ -2274,14 +2274,243 @@ void tox_callback_file_recv_chunk(Tox *tox, tox_file_recv_chunk_cb *callback);
2274 2274
2275 2275
2276 2276
2277typedef enum TOX_ERR_CONFERENCE {
2277 2278
2278/******************************************************************************* 2279 /**
2280 * The function returned successfully.
2281 */
2282 TOX_ERR_CONFERENCE_OK,
2283
2284 /**
2285 * Some error occurred.
2286 */
2287 TOX_ERR_CONFERENCE_FAILURE,
2288
2289} TOX_ERR_CONFERENCE;
2290
2291
2292/**
2293 * Conference types for the conference_invite event.
2294 */
2295typedef enum TOX_CONFERENCE_TYPE {
2296
2297 /**
2298 * Text-only conferences that must be accepted with the tox_conference_join function.
2299 */
2300 TOX_CONFERENCE_TYPE_TEXT,
2301
2302 /**
2303 * Video conference. The function to accept these is in toxav.
2304 */
2305 TOX_CONFERENCE_TYPE_AV,
2306
2307} TOX_CONFERENCE_TYPE;
2308
2309
2310/**
2311 * The invitation will remain valid until the inviting friend goes offline
2312 * or exits the conference.
2279 * 2313 *
2280 * :: Group chat message sending and receiving 2314 * @param friend_number The friend who invited us.
2315 * @param type The conference type (text only or audio/video).
2316 * @param cookie A piece of data of variable length required to join the
2317 * conference.
2318 * @param length The length of the cookie.
2319 */
2320typedef void tox_conference_invite_cb(Tox *tox, uint32_t friend_number, TOX_CONFERENCE_TYPE type, const uint8_t *cookie,
2321 size_t length, void *user_data);
2322
2323
2324/**
2325 * Set the callback for the `conference_invite` event. Pass NULL to unset.
2281 * 2326 *
2282 ******************************************************************************/ 2327 * This event is triggered when the client is invited to join a conference.
2328 */
2329void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback, void *user_data);
2330
2331/**
2332 * TODO
2333 */
2334typedef void tox_conference_message_cb(Tox *tox, uint32_t group_number, uint32_t peer_number, TOX_MESSAGE_TYPE type,
2335 const uint8_t *message, size_t length, void *user_data);
2336
2337
2338/**
2339 * Set the callback for the `conference_message` event. Pass NULL to unset.
2340 *
2341 * Set the callback for group messages.
2342 */
2343void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback, void *user_data);
2344
2345/**
2346 * TODO
2347 */
2348typedef void tox_conference_title_cb(Tox *tox, uint32_t group_number, uint32_t peer_number, const uint8_t *title,
2349 size_t length, void *user_data);
2350
2351
2352/**
2353 * Set the callback for the `conference_title` event. Pass NULL to unset.
2354 *
2355 * Set callback function for title changes.
2356 *
2357 * if peer_number == UINT32_MAX, then author is unknown (e.g. initial joining the group)
2358 */
2359void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback, void *user_data);
2360
2361typedef enum TOX_CONFERENCE_CHANGE {
2362
2363 /**
2364 * TODO: Generate doc
2365 */
2366 TOX_CONFERENCE_CHANGE_PEER_ADD,
2367
2368 /**
2369 * TODO: Generate doc
2370 */
2371 TOX_CONFERENCE_CHANGE_PEER_DEL,
2372
2373 /**
2374 * TODO: Generate doc
2375 */
2376 TOX_CONFERENCE_CHANGE_PEER_NAME,
2377
2378} TOX_CONFERENCE_CHANGE;
2379
2380
2381/**
2382 * TODO
2383 */
2384typedef void tox_conference_namelist_change_cb(Tox *tox, uint32_t group_number, uint32_t peer_number,
2385 TOX_CONFERENCE_CHANGE change, void *user_data);
2386
2387
2388/**
2389 * Set the callback for the `conference_namelist_change` event. Pass NULL to unset.
2390 *
2391 * Set callback function for peer name list changes.
2392 *
2393 * It gets called every time the name list changes(new peer/name, deleted peer)
2394 */
2395void tox_callback_conference_namelist_change(Tox *tox, tox_conference_namelist_change_cb *callback, void *user_data);
2396
2397/**
2398 * Creates a new groupchat.
2399 *
2400 * @return the group number.
2401 */
2402uint32_t tox_conference_new(Tox *tox, TOX_ERR_CONFERENCE *error);
2403
2404/**
2405 * Delete a groupchat.
2406 *
2407 * @return true on success.
2408 */
2409bool tox_conference_delete(Tox *tox, uint32_t group_number, TOX_ERR_CONFERENCE *error);
2283 2410
2411/**
2412 * Return the number of peers in the group chat.
2413 */
2414uint32_t tox_conference_peer_count(const Tox *tox, uint32_t group_number, TOX_ERR_CONFERENCE *error);
2284 2415
2416size_t tox_conference_peer_get_name_size(const Tox *tox, uint32_t group_number, uint32_t peer_number,
2417 TOX_ERR_CONFERENCE *error);
2418
2419/**
2420 * Copy the name of peer_number who is in group_number to name.
2421 * name must be at least TOX_MAX_NAME_LENGTH long.
2422 *
2423 * return length of name if success
2424 * return -1 if failure
2425 */
2426bool tox_conference_peer_get_name(const Tox *tox, uint32_t group_number, uint32_t peer_number, uint8_t *name,
2427 TOX_ERR_CONFERENCE *error);
2428
2429/**
2430 * Copy the public key of peer_number who is in group_number to public_key.
2431 * public_key must be TOX_PUBLIC_KEY_SIZE long.
2432 *
2433 * returns 0 on success
2434 * returns -1 on failure
2435 */
2436bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t group_number, uint32_t peer_number,
2437 uint8_t *public_key, TOX_ERR_CONFERENCE *error);
2438
2439/**
2440 * Check if the current peer_number corresponds to ours.
2441 *
2442 * return 1 if the peer_number corresponds to ours.
2443 * return 0 on failure.
2444 */
2445bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t group_number, uint32_t peer_number);
2446
2447/**
2448 * invite friend_number to group_number
2449 * return 0 on success
2450 * return -1 on failure
2451 */
2452bool tox_conference_invite(Tox *tox, uint32_t friend_number, uint32_t group_number, TOX_ERR_CONFERENCE *error);
2453
2454/**
2455 * Join a group (you need to have been invited first.) using cookie of length obtained
2456 * in the group invite callback.
2457 *
2458 * returns group number on success
2459 * returns -1 on failure.
2460 */
2461uint32_t tox_conference_join(Tox *tox, uint32_t friend_number, const uint8_t *cookie, size_t length,
2462 TOX_ERR_CONFERENCE *error);
2463
2464/**
2465 * send a group message
2466 * return 0 on success
2467 * return -1 on failure
2468 */
2469bool tox_conference_send_message(Tox *tox, uint32_t group_number, TOX_MESSAGE_TYPE type, const uint8_t *message,
2470 size_t length, TOX_ERR_CONFERENCE *error);
2471
2472size_t tox_conference_get_title_size(const Tox *tox, uint32_t group_number, TOX_ERR_CONFERENCE *error);
2473
2474/**
2475 * Get group title from group_number and put it in title.
2476 * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes.
2477 *
2478 * return length of copied title if success.
2479 * return -1 if failure.
2480 */
2481bool tox_conference_get_title(const Tox *tox, uint32_t group_number, uint8_t *title, TOX_ERR_CONFERENCE *error);
2482
2483/**
2484 * set the group's title, limited to MAX_NAME_LENGTH
2485 * return 0 on success
2486 * return -1 on failure
2487 */
2488bool tox_conference_set_title(Tox *tox, uint32_t group_number, const uint8_t *title, size_t length,
2489 TOX_ERR_CONFERENCE *error);
2490
2491/**
2492 * Return the number of chats in the instance m.
2493 * You should use this to determine how much memory to allocate
2494 * for copy_chatlist.
2495 */
2496size_t tox_conference_get_chatlist_size(const Tox *tox);
2497
2498/**
2499 * Copy a list of valid chat IDs into the array out_list.
2500 * If out_list is NULL, returns 0.
2501 * Otherwise, returns the number of elements copied.
2502 * If the array was too small, the contents
2503 * of out_list will be truncated to list_size.
2504 */
2505void tox_conference_get_chatlist(const Tox *tox, uint32_t *chatlist);
2506
2507/**
2508 * return the type of groupchat (TOX_CONFERENCE_TYPE) that group_number is.
2509 *
2510 * return -1 on failure.
2511 * return type on success.
2512 */
2513TOX_CONFERENCE_TYPE tox_conference_get_type(const Tox *tox, uint32_t group_number, TOX_ERR_CONFERENCE *error);
2285 2514
2286 2515
2287/******************************************************************************* 2516/*******************************************************************************
@@ -2459,8 +2688,6 @@ uint16_t tox_self_get_udp_port(const Tox *tox, TOX_ERR_GET_PORT *error);
2459 */ 2688 */
2460uint16_t tox_self_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error); 2689uint16_t tox_self_get_tcp_port(const Tox *tox, TOX_ERR_GET_PORT *error);
2461 2690
2462#include "tox_group.h"
2463
2464#ifdef __cplusplus 2691#ifdef __cplusplus
2465} 2692}
2466#endif 2693#endif
diff --git a/toxcore/tox_group.c b/toxcore/tox_group.c
index 62c84b22..445ce9de 100644
--- a/toxcore/tox_group.c
+++ b/toxcore/tox_group.c
@@ -32,6 +32,8 @@ typedef struct Messenger Tox;
32#include "Messenger.h" 32#include "Messenger.h"
33#include "group.h" 33#include "group.h"
34 34
35#define SET_ERROR_PARAMETER(param, x) {if(param) {*param = x;}}
36
35/**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/ 37/**********GROUP CHAT FUNCTIONS: WARNING Group chats will be rewritten so this might change ************/
36 38
37/* Set the callback for group invites. 39/* Set the callback for group invites.
@@ -40,33 +42,26 @@ typedef struct Messenger Tox;
40 * 42 *
41 * data of length is what needs to be passed to join_groupchat(). 43 * data of length is what needs to be passed to join_groupchat().
42 */ 44 */
43void tox_callback_group_invite(Tox *tox, void (*function)(Messenger *tox, int32_t, uint8_t, const uint8_t *, uint16_t, 45void tox_callback_conference_invite(Tox *tox, tox_conference_invite_cb *callback, void *user_data)
44 void *), void *userdata)
45{ 46{
46 Messenger *m = tox; 47 Messenger *m = tox;
47 g_callback_group_invite(m->group_chat_object, function, userdata); 48 g_callback_group_invite(
49 m->group_chat_object,
50 (void (*)(Messenger * m, uint32_t, int, const uint8_t *, size_t, void *))callback,
51 user_data);
48} 52}
49 53
50/* Set the callback for group messages. 54/* Set the callback for group messages.
51 * 55 *
52 * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * message, uint16_t length, void *userdata) 56 * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * message, uint16_t length, void *userdata)
53 */ 57 */
54void tox_callback_group_message(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint16_t, void *), 58void tox_callback_conference_message(Tox *tox, tox_conference_message_cb *callback, void *user_data)
55 void *userdata)
56{
57 Messenger *m = tox;
58 g_callback_group_message(m->group_chat_object, function, userdata);
59}
60
61/* Set the callback for group actions.
62 *
63 * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * action, uint16_t length, void *userdata)
64 */
65void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint16_t, void *),
66 void *userdata)
67{ 59{
68 Messenger *m = tox; 60 Messenger *m = tox;
69 g_callback_group_action(m->group_chat_object, function, userdata); 61 g_callback_group_message(
62 m->group_chat_object,
63 (void (*)(Messenger * m, uint32_t, uint32_t, int, const uint8_t *, size_t, void *))callback,
64 user_data);
70} 65}
71 66
72/* Set callback function for title changes. 67/* Set callback function for title changes.
@@ -74,11 +69,10 @@ void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, i
74 * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * title, uint8_t length, void *userdata) 69 * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * title, uint8_t length, void *userdata)
75 * if peernumber == -1, then author is unknown (e.g. initial joining the group) 70 * if peernumber == -1, then author is unknown (e.g. initial joining the group)
76 */ 71 */
77void tox_callback_group_title(Tox *tox, void (*function)(Messenger *tox, int, int, const uint8_t *, uint8_t, 72void tox_callback_conference_title(Tox *tox, tox_conference_title_cb *callback, void *user_data)
78 void *), void *userdata)
79{ 73{
80 Messenger *m = tox; 74 Messenger *m = tox;
81 g_callback_group_title(m->group_chat_object, function, userdata); 75 g_callback_group_title(m->group_chat_object, callback, user_data);
82} 76}
83 77
84/* Set callback function for peer name list changes. 78/* Set callback function for peer name list changes.
@@ -86,10 +80,13 @@ void tox_callback_group_title(Tox *tox, void (*function)(Messenger *tox, int, in
86 * It gets called every time the name list changes(new peer/name, deleted peer) 80 * It gets called every time the name list changes(new peer/name, deleted peer)
87 * Function(Tox *tox, int groupnumber, void *userdata) 81 * Function(Tox *tox, int groupnumber, void *userdata)
88 */ 82 */
89void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t, void *), void *userdata) 83void tox_callback_conference_namelist_change(Tox *tox, tox_conference_namelist_change_cb *callback, void *user_data)
90{ 84{
91 Messenger *m = tox; 85 Messenger *m = tox;
92 g_callback_group_namelistchange(m->group_chat_object, function, userdata); 86 g_callback_group_namelistchange(
87 m->group_chat_object,
88 (void (*)(struct Messenger *, int, int, uint8_t, void *))callback,
89 user_data);
93} 90}
94 91
95/* Creates a new groupchat and puts it in the chats array. 92/* Creates a new groupchat and puts it in the chats array.
@@ -97,10 +94,18 @@ void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int
97 * return group number on success. 94 * return group number on success.
98 * return -1 on failure. 95 * return -1 on failure.
99 */ 96 */
100int tox_add_groupchat(Tox *tox) 97uint32_t tox_conference_new(Tox *tox, TOX_ERR_CONFERENCE *error)
101{ 98{
102 Messenger *m = tox; 99 Messenger *m = tox;
103 return add_groupchat(m->group_chat_object, GROUPCHAT_TYPE_TEXT); 100 int res = add_groupchat(m->group_chat_object, GROUPCHAT_TYPE_TEXT);
101
102 if (res == -1) {
103 SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_FAILURE);
104 return 0;
105 }
106
107 SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_OK);
108 return res;
104} 109}
105 110
106/* Delete a groupchat from the chats array. 111/* Delete a groupchat from the chats array.
@@ -108,10 +113,33 @@ int tox_add_groupchat(Tox *tox)
108 * return 0 on success. 113 * return 0 on success.
109 * return -1 if failure. 114 * return -1 if failure.
110 */ 115 */
111int tox_del_groupchat(Tox *tox, int groupnumber) 116bool tox_conference_delete(Tox *tox, uint32_t group_number, TOX_ERR_CONFERENCE *error)
112{ 117{
113 Messenger *m = tox; 118 Messenger *m = tox;
114 return del_groupchat(m->group_chat_object, groupnumber); 119 int res = del_groupchat(m->group_chat_object, group_number);
120
121 if (res == -1) {
122 SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_FAILURE);
123 return false;
124 }
125
126 SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_OK);
127 return true;
128}
129
130size_t tox_conference_peer_get_name_size(
131 const Tox *tox, uint32_t group_number, uint32_t peer_number, TOX_ERR_CONFERENCE *error)
132{
133 const Messenger *m = tox;
134 int res = group_peername_size(m->group_chat_object, group_number, peer_number);
135
136 if (res == -1) {
137 SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_FAILURE);
138 return 0;
139 }
140
141 SET_ERROR_PARAMETER(error, TOX_ERR_CONFERENCE_OK);
142 return res;
115} 143}
116 144
117/* Copy the name of peernumber who is in groupnumber to name. 145/* Copy the name of peernumber who is in groupnumber to name.
@@ -120,10 +148,11 @@ int tox_del_groupchat(Tox *tox, int groupnumber)
120 * return length of name if success 148 * return length of name if success
121 * return -1 if failure 149 * return -1 if failure
122 */ 150 */
123int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name) 151bool tox_conference_peer_get_name(const Tox *tox, uint32_t group_number, uint32_t peer_number, uint8_t *name,
152 TOX_ERR_CONFERENCE *error)
124{ 153{
125 const Messenger *m = tox; 154 const Messenger *m = tox;
126 return group_peername(m->group_chat_object, groupnumber, peernumber, name); 155 return group_peername(m->group_chat_object, group_number, peer_number, name);
127} 156}
128 157
129/* Copy the public key of peernumber who is in groupnumber to public_key. 158/* Copy the public key of peernumber who is in groupnumber to public_key.
@@ -132,20 +161,21 @@ int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t
132 * returns 0 on success 161 * returns 0 on success
133 * returns -1 on failure 162 * returns -1 on failure
134 */ 163 */
135int tox_group_peer_pubkey(const Tox *tox, int groupnumber, int peernumber, uint8_t *public_key) 164bool tox_conference_peer_get_public_key(const Tox *tox, uint32_t group_number, uint32_t peer_number,
165 uint8_t *public_key, TOX_ERR_CONFERENCE *error)
136{ 166{
137 const Messenger *m = tox; 167 const Messenger *m = tox;
138 return group_peer_pubkey(m->group_chat_object, groupnumber, peernumber, public_key); 168 return group_peer_pubkey(m->group_chat_object, group_number, peer_number, public_key);
139} 169}
140 170
141/* invite friendnumber to groupnumber 171/* invite friendnumber to groupnumber
142 * return 0 on success 172 * return 0 on success
143 * return -1 on failure 173 * return -1 on failure
144 */ 174 */
145int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber) 175bool tox_conference_invite(Tox *tox, uint32_t friendnumber, uint32_t group_number, TOX_ERR_CONFERENCE *error)
146{ 176{
147 Messenger *m = tox; 177 Messenger *m = tox;
148 return invite_friend(m->group_chat_object, friendnumber, groupnumber); 178 return invite_friend(m->group_chat_object, friendnumber, group_number);
149} 179}
150 180
151/* Join a group (you need to have been invited first.) using data of length obtained 181/* Join a group (you need to have been invited first.) using data of length obtained
@@ -154,7 +184,8 @@ int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber)
154 * returns group number on success 184 * returns group number on success
155 * returns -1 on failure. 185 * returns -1 on failure.
156 */ 186 */
157int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length) 187uint32_t tox_conference_join(Tox *tox, uint32_t friendnumber, const uint8_t *data, size_t length,
188 TOX_ERR_CONFERENCE *error)
158{ 189{
159 Messenger *m = tox; 190 Messenger *m = tox;
160 return join_groupchat(m->group_chat_object, friendnumber, GROUPCHAT_TYPE_TEXT, data, length); 191 return join_groupchat(m->group_chat_object, friendnumber, GROUPCHAT_TYPE_TEXT, data, length);
@@ -164,42 +195,45 @@ int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint
164 * return 0 on success 195 * return 0 on success
165 * return -1 on failure 196 * return -1 on failure
166 */ 197 */
167int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint16_t length) 198bool tox_conference_send_message(Tox *tox, uint32_t groupnumber, TOX_MESSAGE_TYPE type, const uint8_t *message,
199 size_t length, TOX_ERR_CONFERENCE *error)
168{ 200{
169 Messenger *m = tox; 201 Messenger *m = tox;
170 return group_message_send(m->group_chat_object, groupnumber, message, length);
171}
172 202
173/* send a group action 203 if (type == TOX_MESSAGE_TYPE_NORMAL) {
174 * return 0 on success 204 return group_message_send(m->group_chat_object, groupnumber, message, length);
175 * return -1 on failure 205 } else {
176 */ 206 return group_action_send(m->group_chat_object, groupnumber, message, length);
177int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length) 207 }
178{
179 Messenger *m = tox;
180 return group_action_send(m->group_chat_object, groupnumber, action, length);
181} 208}
182 209
183/* set the group's title, limited to MAX_NAME_LENGTH 210/* set the group's title, limited to MAX_NAME_LENGTH
184 * return 0 on success 211 * return 0 on success
185 * return -1 on failure 212 * return -1 on failure
186 */ 213 */
187int tox_group_set_title(Tox *tox, int groupnumber, const uint8_t *title, uint8_t length) 214bool tox_conference_set_title(Tox *tox, uint32_t groupnumber, const uint8_t *title, size_t length,
215 TOX_ERR_CONFERENCE *error)
188{ 216{
189 Messenger *m = tox; 217 Messenger *m = tox;
190 return group_title_send(m->group_chat_object, groupnumber, title, length); 218 return group_title_send(m->group_chat_object, groupnumber, title, length);
191} 219}
192 220
221size_t tox_conference_get_title_size(const Tox *tox, uint32_t groupnumber, TOX_ERR_CONFERENCE *error)
222{
223 const Messenger *m = tox;
224 return group_title_get_size(m->group_chat_object, groupnumber);
225}
226
193/* Get group title from groupnumber and put it in title. 227/* Get group title from groupnumber and put it in title.
194 * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes. 228 * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes.
195 * 229 *
196 * return length of copied title if success. 230 * return length of copied title if success.
197 * return -1 if failure. 231 * return -1 if failure.
198 */ 232 */
199int tox_group_get_title(Tox *tox, int groupnumber, uint8_t *title, uint32_t max_length) 233bool tox_conference_get_title(const Tox *tox, uint32_t groupnumber, uint8_t *title, TOX_ERR_CONFERENCE *error)
200{ 234{
201 Messenger *m = tox; 235 const Messenger *m = tox;
202 return group_title_get(m->group_chat_object, groupnumber, title, max_length); 236 return group_title_get(m->group_chat_object, groupnumber, title);
203} 237}
204 238
205/* Check if the current peernumber corresponds to ours. 239/* Check if the current peernumber corresponds to ours.
@@ -207,7 +241,7 @@ int tox_group_get_title(Tox *tox, int groupnumber, uint8_t *title, uint32_t max_
207 * return 1 if the peernumber corresponds to ours. 241 * return 1 if the peernumber corresponds to ours.
208 * return 0 on failure. 242 * return 0 on failure.
209 */ 243 */
210unsigned int tox_group_peernumber_is_ours(const Tox *tox, int groupnumber, int peernumber) 244bool tox_conference_peer_number_is_ours(const Tox *tox, uint32_t groupnumber, uint32_t peernumber)
211{ 245{
212 const Messenger *m = tox; 246 const Messenger *m = tox;
213 return group_peernumber_is_ours(m->group_chat_object, groupnumber, peernumber); 247 return group_peernumber_is_ours(m->group_chat_object, groupnumber, peernumber);
@@ -216,33 +250,16 @@ unsigned int tox_group_peernumber_is_ours(const Tox *tox, int groupnumber, int p
216/* Return the number of peers in the group chat on success. 250/* Return the number of peers in the group chat on success.
217 * return -1 on failure 251 * return -1 on failure
218 */ 252 */
219int tox_group_number_peers(const Tox *tox, int groupnumber) 253uint32_t tox_conference_peer_count(const Tox *tox, uint32_t groupnumber, TOX_ERR_CONFERENCE *error)
220{ 254{
221 const Messenger *m = tox; 255 const Messenger *m = tox;
222 return group_number_peers(m->group_chat_object, groupnumber); 256 return group_number_peers(m->group_chat_object, groupnumber);
223} 257}
224 258
225/* List all the peers in the group chat.
226 *
227 * Copies the names of the peers to the name[length][MAX_NICK_BYTES] array.
228 *
229 * Copies the lengths of the names to lengths[length]
230 *
231 * returns the number of peers on success.
232 *
233 * return -1 on failure.
234 */
235int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[],
236 uint16_t length)
237{
238 const Messenger *m = tox;
239 return group_names(m->group_chat_object, groupnumber, names, lengths, length);
240}
241
242/* Return the number of chats in the instance m. 259/* Return the number of chats in the instance m.
243 * You should use this to determine how much memory to allocate 260 * You should use this to determine how much memory to allocate
244 * for copy_chatlist. */ 261 * for copy_chatlist. */
245uint32_t tox_count_chatlist(const Tox *tox) 262size_t tox_conference_get_chatlist_size(const Tox *tox)
246{ 263{
247 const Messenger *m = tox; 264 const Messenger *m = tox;
248 return count_chatlist(m->group_chat_object); 265 return count_chatlist(m->group_chat_object);
@@ -253,10 +270,11 @@ uint32_t tox_count_chatlist(const Tox *tox)
253 * Otherwise, returns the number of elements copied. 270 * Otherwise, returns the number of elements copied.
254 * If the array was too small, the contents 271 * If the array was too small, the contents
255 * of out_list will be truncated to list_size. */ 272 * of out_list will be truncated to list_size. */
256uint32_t tox_get_chatlist(const Tox *tox, int32_t *out_list, uint32_t list_size) 273void tox_conference_get_chatlist(const Tox *tox, uint32_t *out_list)
257{ 274{
258 const Messenger *m = tox; 275 const Messenger *m = tox;
259 return copy_chatlist(m->group_chat_object, out_list, list_size); 276 size_t list_size = tox_conference_get_chatlist_size(tox);
277 copy_chatlist(m->group_chat_object, out_list, list_size);
260} 278}
261 279
262/* return the type of groupchat (TOX_GROUPCHAT_TYPE_) that groupnumber is. 280/* return the type of groupchat (TOX_GROUPCHAT_TYPE_) that groupnumber is.
@@ -264,7 +282,7 @@ uint32_t tox_get_chatlist(const Tox *tox, int32_t *out_list, uint32_t list_size)
264 * return -1 on failure. 282 * return -1 on failure.
265 * return type on success. 283 * return type on success.
266 */ 284 */
267int tox_group_get_type(const Tox *tox, int groupnumber) 285TOX_CONFERENCE_TYPE tox_conference_get_type(const Tox *tox, uint32_t groupnumber, TOX_ERR_CONFERENCE *error)
268{ 286{
269 const Messenger *m = tox; 287 const Messenger *m = tox;
270 return group_get_type(m->group_chat_object, groupnumber); 288 return group_get_type(m->group_chat_object, groupnumber);
diff --git a/toxcore/tox_group.h b/toxcore/tox_group.h
deleted file mode 100644
index 51beb570..00000000
--- a/toxcore/tox_group.h
+++ /dev/null
@@ -1,179 +0,0 @@
1#ifndef TOX_GROUP_H
2#define TOX_GROUP_H
3
4#include "tox.h"
5
6/**********GROUP CHAT FUNCTIONS ************/
7
8/* Group chat types for tox_callback_group_invite function.
9 *
10 * TOX_GROUPCHAT_TYPE_TEXT groupchats must be accepted with the tox_join_groupchat() function.
11 * The function to accept TOX_GROUPCHAT_TYPE_AV is in toxav.
12 */
13enum {
14 TOX_GROUPCHAT_TYPE_TEXT,
15 TOX_GROUPCHAT_TYPE_AV
16};
17
18/* Set the callback for group invites.
19 *
20 * Function(Tox *tox, int32_t friendnumber, uint8_t type, const uint8_t *data, uint16_t length, void *userdata)
21 *
22 * data of length is what needs to be passed to join_groupchat().
23 *
24 * for what type means see the enum right above this comment.
25 */
26void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, const uint8_t *, uint16_t,
27 void *), void *userdata);
28
29/* Set the callback for group messages.
30 *
31 * Function(Tox *tox, int groupnumber, int peernumber, const uint8_t * message, uint16_t length, void *userdata)
32 */
33void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *),
34 void *userdata);
35
36/* Set the callback for group actions.
37 *
38 * Function(Tox *tox, int groupnumber, int peernumber, const uint8_t * action, uint16_t length, void *userdata)
39 */
40void tox_callback_group_action(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *),
41 void *userdata);
42
43/* Set callback function for title changes.
44 *
45 * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * title, uint8_t length, void *userdata)
46 * if peernumber == -1, then author is unknown (e.g. initial joining the group)
47 */
48void tox_callback_group_title(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint8_t,
49 void *), void *userdata);
50
51/* Set callback function for peer name list changes.
52 *
53 * It gets called every time the name list changes(new peer/name, deleted peer)
54 * Function(Tox *tox, int groupnumber, int peernumber, TOX_CHAT_CHANGE change, void *userdata)
55 */
56typedef enum {
57 TOX_CHAT_CHANGE_PEER_ADD,
58 TOX_CHAT_CHANGE_PEER_DEL,
59 TOX_CHAT_CHANGE_PEER_NAME,
60} TOX_CHAT_CHANGE;
61
62void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t, void *),
63 void *userdata);
64
65/* Creates a new groupchat and puts it in the chats array.
66 *
67 * return group number on success.
68 * return -1 on failure.
69 */
70int tox_add_groupchat(Tox *tox);
71
72/* Delete a groupchat from the chats array.
73 *
74 * return 0 on success.
75 * return -1 if failure.
76 */
77int tox_del_groupchat(Tox *tox, int groupnumber);
78
79/* Copy the name of peernumber who is in groupnumber to name.
80 * name must be at least TOX_MAX_NAME_LENGTH long.
81 *
82 * return length of name if success
83 * return -1 if failure
84 */
85int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name);
86
87/* Copy the public key of peernumber who is in groupnumber to public_key.
88 * public_key must be TOX_PUBLIC_KEY_SIZE long.
89 *
90 * returns 0 on success
91 * returns -1 on failure
92 */
93int tox_group_peer_pubkey(const Tox *tox, int groupnumber, int peernumber, uint8_t *public_key);
94
95/* invite friendnumber to groupnumber
96 * return 0 on success
97 * return -1 on failure
98 */
99int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber);
100
101/* Join a group (you need to have been invited first.) using data of length obtained
102 * in the group invite callback.
103 *
104 * returns group number on success
105 * returns -1 on failure.
106 */
107int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length);
108
109/* send a group message
110 * return 0 on success
111 * return -1 on failure
112 */
113int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint16_t length);
114
115/* send a group action
116 * return 0 on success
117 * return -1 on failure
118 */
119int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length);
120
121/* set the group's title, limited to MAX_NAME_LENGTH
122 * return 0 on success
123 * return -1 on failure
124 */
125int tox_group_set_title(Tox *tox, int groupnumber, const uint8_t *title, uint8_t length);
126
127/* Get group title from groupnumber and put it in title.
128 * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes.
129 *
130 * return length of copied title if success.
131 * return -1 if failure.
132 */
133int tox_group_get_title(Tox *tox, int groupnumber, uint8_t *title, uint32_t max_length);
134
135/* Check if the current peernumber corresponds to ours.
136 *
137 * return 1 if the peernumber corresponds to ours.
138 * return 0 on failure.
139 */
140unsigned int tox_group_peernumber_is_ours(const Tox *tox, int groupnumber, int peernumber);
141
142/* Return the number of peers in the group chat on success.
143 * return -1 on failure
144 */
145int tox_group_number_peers(const Tox *tox, int groupnumber);
146
147/* List all the peers in the group chat.
148 *
149 * Copies the names of the peers to the name[length][TOX_MAX_NAME_LENGTH] array.
150 *
151 * Copies the lengths of the names to lengths[length]
152 *
153 * returns the number of peers on success.
154 *
155 * return -1 on failure.
156 */
157int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[],
158 uint16_t length);
159
160/* Return the number of chats in the instance m.
161 * You should use this to determine how much memory to allocate
162 * for copy_chatlist. */
163uint32_t tox_count_chatlist(const Tox *tox);
164
165/* Copy a list of valid chat IDs into the array out_list.
166 * If out_list is NULL, returns 0.
167 * Otherwise, returns the number of elements copied.
168 * If the array was too small, the contents
169 * of out_list will be truncated to list_size. */
170uint32_t tox_get_chatlist(const Tox *tox, int32_t *out_list, uint32_t list_size);
171
172/* return the type of groupchat (TOX_GROUPCHAT_TYPE_) that groupnumber is.
173 *
174 * return -1 on failure.
175 * return type on success.
176 */
177int tox_group_get_type(const Tox *tox, int groupnumber);
178
179#endif /* TOX_GROUP_H */