Skip to content

Commit c9ca400

Browse files
committed
refactor: Align group message sending with other send functions.
None of the others use out parameters. Also no toxcore function uses out parameters for anything other than arrays and errors. This would be a first, for no good reason.
1 parent 6c6c0b1 commit c9ca400

File tree

6 files changed

+35
-34
lines changed

6 files changed

+35
-34
lines changed

auto_tests/group_message_test.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,9 @@ static void group_message_test(AutoTox *autotoxes)
395395
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
396396

397397
if (state1->peer_joined && !state1->message_sent) {
398-
tox_group_send_message(tox1, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)TEST_MESSAGE,
399-
TEST_MESSAGE_LEN, &state1->pseudo_msg_id, &err_send);
398+
state1->pseudo_msg_id = tox_group_send_message(
399+
tox1, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)TEST_MESSAGE,
400+
TEST_MESSAGE_LEN, &err_send);
400401
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
401402
state1->message_sent = true;
402403
}
@@ -419,7 +420,7 @@ static void group_message_test(AutoTox *autotoxes)
419420

420421
// tox1 sends group a message which should not be seen by tox0's message handler
421422
tox_group_send_message(tox1, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)IGNORE_MESSAGE,
422-
IGNORE_MESSAGE_LEN, nullptr, &err_send);
423+
IGNORE_MESSAGE_LEN, &err_send);
423424

424425
iterate_all_wait(autotoxes, NUM_GROUP_TOXES, ITERATION_INTERVAL);
425426

@@ -506,7 +507,7 @@ static void group_message_test(AutoTox *autotoxes)
506507

507508
memcpy(m + 2, &checksum, sizeof(uint16_t));
508509

509-
tox_group_send_message(tox0, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)m, message_size, nullptr, &err_send);
510+
tox_group_send_message(tox0, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)m, message_size, &err_send);
510511

511512
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
512513
}
@@ -528,7 +529,7 @@ static void group_message_test(AutoTox *autotoxes)
528529

529530
memcpy(m, &i, sizeof(uint16_t));
530531

531-
tox_group_send_message(tox0, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)m, 2, nullptr, &err_send);
532+
tox_group_send_message(tox0, group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)m, 2, &err_send);
532533
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
533534
}
534535

auto_tests/group_moderation_test.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,38 +334,38 @@ static void voice_state_message_test(AutoTox *autotox, Tox_Group_Voice_State voi
334334
ck_assert(sq_err == TOX_ERR_GROUP_SELF_QUERY_OK);
335335

336336
Tox_Err_Group_Send_Message msg_err;
337-
bool send_ret = tox_group_send_message(autotox->tox, state->group_number, TOX_MESSAGE_TYPE_NORMAL,
338-
(const uint8_t *)"test", 4, nullptr, &msg_err);
337+
tox_group_send_message(autotox->tox, state->group_number, TOX_MESSAGE_TYPE_NORMAL,
338+
(const uint8_t *)"test", 4, &msg_err);
339339

340340
switch (self_role) {
341341
case TOX_GROUP_ROLE_OBSERVER: {
342-
ck_assert(!send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
342+
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
343343
break;
344344
}
345345

346346
case TOX_GROUP_ROLE_USER: {
347347
if (voice_state != TOX_GROUP_VOICE_STATE_ALL) {
348-
ck_assert_msg(!send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS,
349-
"%d, %d", send_ret, msg_err);
348+
ck_assert_msg(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS,
349+
"%d", msg_err);
350350
} else {
351-
ck_assert(send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
351+
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
352352
}
353353

354354
break;
355355
}
356356

357357
case TOX_GROUP_ROLE_MODERATOR: {
358358
if (voice_state != TOX_GROUP_VOICE_STATE_FOUNDER) {
359-
ck_assert(send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
359+
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
360360
} else {
361-
ck_assert(!send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
361+
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
362362
}
363363

364364
break;
365365
}
366366

367367
case TOX_GROUP_ROLE_FOUNDER: {
368-
ck_assert(send_ret && msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
368+
ck_assert(msg_err == TOX_ERR_GROUP_SEND_MESSAGE_OK);
369369
break;
370370
}
371371
}

auto_tests/group_tcp_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static void group_tcp_test(AutoTox *autotoxes)
206206

207207
Tox_Err_Group_Send_Message merr;
208208
tox_group_send_message(autotoxes[0].tox, groupnumber, TOX_MESSAGE_TYPE_NORMAL,
209-
(const uint8_t *)CODEWORD, CODEWORD_LEN, nullptr, &merr);
209+
(const uint8_t *)CODEWORD, CODEWORD_LEN, &merr);
210210
ck_assert(merr == TOX_ERR_GROUP_SEND_MESSAGE_OK);
211211

212212
while (!state1->got_second_code) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0030bf6448655c3299a8f0552cae1f78340db9cec33e2e479aad497ec3c03de4 /usr/local/bin/tox-bootstrapd
1+
0ac3f502265ed3c2a4fb2971d1f7b92ad20f900b8daa64b828fd5994c3d4af9d /usr/local/bin/tox-bootstrapd

toxcore/tox.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,8 +3849,9 @@ bool tox_group_get_password(const Tox *tox, uint32_t group_number, uint8_t *pass
38493849
return true;
38503850
}
38513851

3852-
bool tox_group_send_message(const Tox *tox, uint32_t group_number, Tox_Message_Type type, const uint8_t *message,
3853-
size_t length, uint32_t *message_id, Tox_Err_Group_Send_Message *error)
3852+
Tox_Group_Message_Id tox_group_send_message(
3853+
const Tox *tox, uint32_t group_number, Tox_Message_Type type, const uint8_t *message,
3854+
size_t length, Tox_Err_Group_Send_Message *error)
38543855
{
38553856
assert(tox != nullptr);
38563857

@@ -3860,54 +3861,55 @@ bool tox_group_send_message(const Tox *tox, uint32_t group_number, Tox_Message_T
38603861
if (chat == nullptr) {
38613862
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_MESSAGE_GROUP_NOT_FOUND);
38623863
tox_unlock(tox);
3863-
return false;
3864+
return -1;
38643865
}
38653866

38663867
if (chat->connection_state == CS_DISCONNECTED) {
38673868
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_MESSAGE_DISCONNECTED);
38683869
tox_unlock(tox);
3869-
return false;
3870+
return -1;
38703871
}
38713872

3872-
const int ret = gc_send_message(chat, message, length, type, message_id);
3873+
uint32_t message_id = 0;
3874+
const int ret = gc_send_message(chat, message, length, type, &message_id);
38733875
tox_unlock(tox);
38743876

38753877
switch (ret) {
38763878
case 0: {
38773879
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_MESSAGE_OK);
3878-
return true;
3880+
return message_id;
38793881
}
38803882

38813883
case -1: {
38823884
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_MESSAGE_TOO_LONG);
3883-
return false;
3885+
return -1;
38843886
}
38853887

38863888
case -2: {
38873889
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_MESSAGE_EMPTY);
3888-
return false;
3890+
return -1;
38893891
}
38903892

38913893
case -3: {
38923894
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_MESSAGE_BAD_TYPE);
3893-
return false;
3895+
return -1;
38943896
}
38953897

38963898
case -4: {
38973899
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_MESSAGE_PERMISSIONS);
3898-
return false;
3900+
return -1;
38993901
}
39003902

39013903
case -5: {
39023904
SET_ERROR_PARAMETER(error, TOX_ERR_GROUP_SEND_MESSAGE_FAIL_SEND);
3903-
return false;
3905+
return -1;
39043906
}
39053907
}
39063908

39073909
/* can't happen */
39083910
LOGGER_FATAL(tox->m->log, "impossible return value: %d", ret);
39093911

3910-
return false;
3912+
return -1;
39113913
}
39123914

39133915
bool tox_group_send_private_message(const Tox *tox, uint32_t group_number, uint32_t peer_id, Tox_Message_Type type,

toxcore/tox.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4619,15 +4619,13 @@ const char *tox_err_group_send_message_to_string(Tox_Err_Group_Send_Message valu
46194619
* @param message A non-NULL pointer to the first element of a byte array
46204620
* containing the message text.
46214621
* @param length Length of the message to be sent.
4622-
* @param message_id A pointer to a Tox_Group_Message_Id. The message_id of this message will be returned
4623-
* unless the parameter is NULL, in which case the returned parameter value will be undefined.
4624-
* If this function returns false the returned parameter `message_id` value will also be undefined.
46254622
*
4626-
* @return true on success.
4623+
* @return The message_id of this message. If this function has an error, the
4624+
* returned message ID value will be undefined.
46274625
*/
4628-
bool tox_group_send_message(
4626+
Tox_Group_Message_Id tox_group_send_message(
46294627
const Tox *tox, Tox_Group_Number group_number, Tox_Message_Type type,
4630-
const uint8_t message[], size_t length, Tox_Group_Message_Id *message_id,
4628+
const uint8_t message[], size_t length,
46314629
Tox_Err_Group_Send_Message *error);
46324630

46334631
typedef enum Tox_Err_Group_Send_Private_Message {

0 commit comments

Comments
 (0)