diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/group.c | 39 | ||||
-rw-r--r-- | toxcore/group.h | 2 | ||||
-rw-r--r-- | toxcore/tox.c | 5 |
3 files changed, 43 insertions, 3 deletions
diff --git a/toxcore/group.c b/toxcore/group.c index 24f0b72e..0b77e013 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -893,6 +893,17 @@ void g_callback_group_message(Group_Chats *g_c, void (*function)(Messenger *m, i | |||
893 | g_c->message_callback_userdata = userdata; | 893 | g_c->message_callback_userdata = userdata; |
894 | } | 894 | } |
895 | 895 | ||
896 | /* Set the callback for group actions. | ||
897 | * | ||
898 | * Function(Group_Chats *g_c, int groupnumber, int friendgroupnumber, uint8_t * message, uint16_t length, void *userdata) | ||
899 | */ | ||
900 | void g_callback_group_action(Group_Chats *g_c, void (*function)(Messenger *m, int, int, const uint8_t *, uint16_t, | ||
901 | void *), void *userdata) | ||
902 | { | ||
903 | g_c->action_callback = function; | ||
904 | g_c->action_callback_userdata = userdata; | ||
905 | } | ||
906 | |||
896 | /* Set callback function for peer name list changes. | 907 | /* Set callback function for peer name list changes. |
897 | * | 908 | * |
898 | * It gets called every time the name list changes(new peer/name, deleted peer) | 909 | * It gets called every time the name list changes(new peer/name, deleted peer) |
@@ -1390,6 +1401,19 @@ int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *m | |||
1390 | } | 1401 | } |
1391 | } | 1402 | } |
1392 | 1403 | ||
1404 | /* send a group action | ||
1405 | * return 0 on success | ||
1406 | * return -1 on failure | ||
1407 | */ | ||
1408 | int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length) | ||
1409 | { | ||
1410 | if (send_message_group(g_c, groupnumber, PACKET_ID_ACTION, action, length)) { | ||
1411 | return 0; | ||
1412 | } else { | ||
1413 | return -1; | ||
1414 | } | ||
1415 | } | ||
1416 | |||
1393 | static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, | 1417 | static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const uint8_t *data, uint16_t length, |
1394 | int close_index) | 1418 | int close_index) |
1395 | { | 1419 | { |
@@ -1485,6 +1509,21 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const | |||
1485 | break; | 1509 | break; |
1486 | } | 1510 | } |
1487 | 1511 | ||
1512 | case PACKET_ID_ACTION: { | ||
1513 | if (msg_data_len == 0) | ||
1514 | return; | ||
1515 | |||
1516 | uint8_t newmsg[msg_data_len + 1]; | ||
1517 | memcpy(newmsg, msg_data, msg_data_len); | ||
1518 | newmsg[msg_data_len] = 0; | ||
1519 | |||
1520 | //TODO | ||
1521 | if (g_c->action_callback) | ||
1522 | g_c->action_callback(g_c->m, groupnumber, index, newmsg, msg_data_len, g_c->action_callback_userdata); | ||
1523 | |||
1524 | break; | ||
1525 | } | ||
1526 | |||
1488 | default: | 1527 | default: |
1489 | return; | 1528 | return; |
1490 | } | 1529 | } |
diff --git a/toxcore/group.h b/toxcore/group.h index 3764bf94..74abfa66 100644 --- a/toxcore/group.h +++ b/toxcore/group.h | |||
@@ -98,6 +98,8 @@ typedef struct { | |||
98 | void *invite_callback_userdata; | 98 | void *invite_callback_userdata; |
99 | void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); | 99 | void (*message_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); |
100 | void *message_callback_userdata; | 100 | void *message_callback_userdata; |
101 | void (*action_callback)(Messenger *m, int, int, const uint8_t *, uint16_t, void *); | ||
102 | void *action_callback_userdata; | ||
101 | void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *); | 103 | void (*peer_namelistchange)(Messenger *m, int, int, uint8_t, void *); |
102 | void *group_namelistchange_userdata; | 104 | void *group_namelistchange_userdata; |
103 | } Group_Chats; | 105 | } Group_Chats; |
diff --git a/toxcore/tox.c b/toxcore/tox.c index 19146744..9eef6157 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c | |||
@@ -581,7 +581,7 @@ void tox_callback_group_action(Tox *tox, void (*function)(Messenger *tox, int, i | |||
581 | void *userdata) | 581 | void *userdata) |
582 | { | 582 | { |
583 | Messenger *m = tox; | 583 | Messenger *m = tox; |
584 | //m_callback_group_action(m, function, userdata); | 584 | g_callback_group_action(m->group_chat_object, function, userdata); |
585 | } | 585 | } |
586 | 586 | ||
587 | /* Set callback function for peer name list changes. | 587 | /* Set callback function for peer name list changes. |
@@ -668,8 +668,7 @@ int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, ui | |||
668 | int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length) | 668 | int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length) |
669 | { | 669 | { |
670 | Messenger *m = tox; | 670 | Messenger *m = tox; |
671 | //return group_action_send(m, groupnumber, action, length); | 671 | return group_action_send(m->group_chat_object, groupnumber, action, length); |
672 | return -1; | ||
673 | } | 672 | } |
674 | 673 | ||
675 | /* Check if the current peernumber corresponds to ours. | 674 | /* Check if the current peernumber corresponds to ours. |