diff options
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 6 | ||||
-rw-r--r-- | toxcore/Messenger.h | 5 | ||||
-rw-r--r-- | toxcore/group.c | 40 | ||||
-rw-r--r-- | toxcore/group.h | 6 | ||||
-rw-r--r-- | toxcore/tox.api.h | 5 | ||||
-rw-r--r-- | toxcore/tox.h | 6 |
6 files changed, 46 insertions, 22 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 455494bc..36dadbcf 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -488,7 +488,8 @@ int m_friend_exists(const Messenger *m, int32_t friendnumber) | |||
488 | int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, const uint8_t *message, uint32_t length, | 488 | int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, const uint8_t *message, uint32_t length, |
489 | uint32_t *message_id) | 489 | uint32_t *message_id) |
490 | { | 490 | { |
491 | if (type > MESSAGE_ACTION) { | 491 | /* MESSAGE_LAST itself is incorrect value */ |
492 | if (type >= MESSAGE_LAST) { | ||
492 | return -5; | 493 | return -5; |
493 | } | 494 | } |
494 | 495 | ||
@@ -2213,7 +2214,8 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le | |||
2213 | } | 2214 | } |
2214 | 2215 | ||
2215 | case PACKET_ID_MESSAGE: // fall-through | 2216 | case PACKET_ID_MESSAGE: // fall-through |
2216 | case PACKET_ID_ACTION: { | 2217 | case PACKET_ID_ACTION: |
2218 | case PACKET_ID_CORRECTION: { | ||
2217 | if (data_length == 0) { | 2219 | if (data_length == 0) { |
2218 | break; | 2220 | break; |
2219 | } | 2221 | } |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 350fe564..a261a507 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -42,7 +42,9 @@ | |||
42 | 42 | ||
43 | enum { | 43 | enum { |
44 | MESSAGE_NORMAL, | 44 | MESSAGE_NORMAL, |
45 | MESSAGE_ACTION | 45 | MESSAGE_ACTION, |
46 | MESSAGE_CORRECTION, | ||
47 | MESSAGE_LAST | ||
46 | }; | 48 | }; |
47 | 49 | ||
48 | /* NOTE: Packet ids below 24 must never be used. */ | 50 | /* NOTE: Packet ids below 24 must never be used. */ |
@@ -54,6 +56,7 @@ enum { | |||
54 | #define PACKET_ID_TYPING 51 | 56 | #define PACKET_ID_TYPING 51 |
55 | #define PACKET_ID_MESSAGE 64 | 57 | #define PACKET_ID_MESSAGE 64 |
56 | #define PACKET_ID_ACTION (PACKET_ID_MESSAGE + MESSAGE_ACTION) /* 65 */ | 58 | #define PACKET_ID_ACTION (PACKET_ID_MESSAGE + MESSAGE_ACTION) /* 65 */ |
59 | #define PACKET_ID_CORRECTION (PACKET_ID_MESSAGE + MESSAGE_CORRECTION) /* 66 */ | ||
57 | #define PACKET_ID_MSI 69 | 60 | #define PACKET_ID_MSI 69 |
58 | #define PACKET_ID_FILE_SENDREQUEST 80 | 61 | #define PACKET_ID_FILE_SENDREQUEST 80 |
59 | #define PACKET_ID_FILE_CONTROL 81 | 62 | #define PACKET_ID_FILE_CONTROL 81 |
diff --git a/toxcore/group.c b/toxcore/group.c index 0f2639c3..d0a1154e 100644 --- a/toxcore/group.c +++ b/toxcore/group.c | |||
@@ -1956,6 +1956,21 @@ int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *ac | |||
1956 | return ret; | 1956 | return ret; |
1957 | } | 1957 | } |
1958 | 1958 | ||
1959 | /* send a group correction message | ||
1960 | * return 0 on success | ||
1961 | * see: send_message_group() for error codes. | ||
1962 | */ | ||
1963 | int group_correction_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length) | ||
1964 | { | ||
1965 | int ret = send_message_group(g_c, groupnumber, PACKET_ID_CORRECTION, action, length); | ||
1966 | |||
1967 | if (ret > 0) { | ||
1968 | return 0; | ||
1969 | } | ||
1970 | |||
1971 | return ret; | ||
1972 | } | ||
1973 | |||
1959 | /* High level function to send custom lossy packets. | 1974 | /* High level function to send custom lossy packets. |
1960 | * | 1975 | * |
1961 | * return -1 on failure. | 1976 | * return -1 on failure. |
@@ -2083,24 +2098,9 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const | |||
2083 | } | 2098 | } |
2084 | break; | 2099 | break; |
2085 | 2100 | ||
2086 | case PACKET_ID_MESSAGE: { | 2101 | case PACKET_ID_MESSAGE: |
2087 | if (msg_data_len == 0) { | 2102 | case PACKET_ID_ACTION: |
2088 | return; | 2103 | case PACKET_ID_CORRECTION: { |
2089 | } | ||
2090 | |||
2091 | VLA(uint8_t, newmsg, msg_data_len + 1); | ||
2092 | memcpy(newmsg, msg_data, msg_data_len); | ||
2093 | newmsg[msg_data_len] = 0; | ||
2094 | |||
2095 | // TODO(irungentoo): | ||
2096 | if (g_c->message_callback) { | ||
2097 | g_c->message_callback(g_c->m, groupnumber, index, 0, newmsg, msg_data_len, userdata); | ||
2098 | } | ||
2099 | |||
2100 | break; | ||
2101 | } | ||
2102 | |||
2103 | case PACKET_ID_ACTION: { | ||
2104 | if (msg_data_len == 0) { | 2104 | if (msg_data_len == 0) { |
2105 | return; | 2105 | return; |
2106 | } | 2106 | } |
@@ -2111,7 +2111,9 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const | |||
2111 | 2111 | ||
2112 | // TODO(irungentoo): | 2112 | // TODO(irungentoo): |
2113 | if (g_c->message_callback) { | 2113 | if (g_c->message_callback) { |
2114 | g_c->message_callback(g_c->m, groupnumber, index, 1, newmsg, msg_data_len, userdata); | 2114 | uint8_t chat_message_id = message_id - PACKET_ID_MESSAGE; |
2115 | g_c->message_callback(g_c->m, groupnumber, index, chat_message_id, | ||
2116 | newmsg, msg_data_len, userdata); | ||
2115 | } | 2117 | } |
2116 | 2118 | ||
2117 | break; | 2119 | break; |
diff --git a/toxcore/group.h b/toxcore/group.h index 2e014da3..6c0baebf 100644 --- a/toxcore/group.h +++ b/toxcore/group.h | |||
@@ -238,6 +238,12 @@ int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *m | |||
238 | */ | 238 | */ |
239 | int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length); | 239 | int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length); |
240 | 240 | ||
241 | /* send a group correction message | ||
242 | * return 0 on success | ||
243 | * see: send_message_group() for error codes. | ||
244 | */ | ||
245 | int group_correction_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length); | ||
246 | |||
241 | /* set the group's title, limited to MAX_NAME_LENGTH | 247 | /* set the group's title, limited to MAX_NAME_LENGTH |
242 | * return 0 on success | 248 | * return 0 on success |
243 | * return -1 if groupnumber is invalid. | 249 | * return -1 if groupnumber is invalid. |
diff --git a/toxcore/tox.api.h b/toxcore/tox.api.h index 63959207..7f3d8d4c 100644 --- a/toxcore/tox.api.h +++ b/toxcore/tox.api.h | |||
@@ -338,6 +338,11 @@ enum class MESSAGE_TYPE { | |||
338 | * on IRC. | 338 | * on IRC. |
339 | */ | 339 | */ |
340 | ACTION, | 340 | ACTION, |
341 | /** | ||
342 | * Correction of the last message. With empty message body can be used to mark | ||
343 | * last message as deleted. | ||
344 | */ | ||
345 | CORRECTION, | ||
341 | } | 346 | } |
342 | 347 | ||
343 | 348 | ||
diff --git a/toxcore/tox.h b/toxcore/tox.h index 567ce7e5..f4f3d066 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -371,6 +371,12 @@ typedef enum TOX_MESSAGE_TYPE { | |||
371 | */ | 371 | */ |
372 | TOX_MESSAGE_TYPE_ACTION, | 372 | TOX_MESSAGE_TYPE_ACTION, |
373 | 373 | ||
374 | /** | ||
375 | * Correction of the last message. With empty message body can be used to mark | ||
376 | * last message as deleted. | ||
377 | */ | ||
378 | TOX_MESSAGE_TYPE_CORRECTION, | ||
379 | |||
374 | } TOX_MESSAGE_TYPE; | 380 | } TOX_MESSAGE_TYPE; |
375 | 381 | ||
376 | 382 | ||