Add correction message type

This commit is contained in:
Diadlo 2018-01-15 01:42:30 +03:00 committed by iphydf
parent da739a9438
commit e16d3894c5
6 changed files with 46 additions and 22 deletions

View File

@ -488,7 +488,8 @@ int m_friend_exists(const Messenger *m, int32_t friendnumber)
int m_send_message_generic(Messenger *m, int32_t friendnumber, uint8_t type, const uint8_t *message, uint32_t length,
uint32_t *message_id)
{
if (type > MESSAGE_ACTION) {
/* MESSAGE_LAST itself is incorrect value */
if (type >= MESSAGE_LAST) {
return -5;
}
@ -2213,7 +2214,8 @@ static int m_handle_packet(void *object, int i, const uint8_t *temp, uint16_t le
}
case PACKET_ID_MESSAGE: // fall-through
case PACKET_ID_ACTION: {
case PACKET_ID_ACTION:
case PACKET_ID_CORRECTION: {
if (data_length == 0) {
break;
}

View File

@ -42,7 +42,9 @@
enum {
MESSAGE_NORMAL,
MESSAGE_ACTION
MESSAGE_ACTION,
MESSAGE_CORRECTION,
MESSAGE_LAST
};
/* NOTE: Packet ids below 24 must never be used. */
@ -54,6 +56,7 @@ enum {
#define PACKET_ID_TYPING 51
#define PACKET_ID_MESSAGE 64
#define PACKET_ID_ACTION (PACKET_ID_MESSAGE + MESSAGE_ACTION) /* 65 */
#define PACKET_ID_CORRECTION (PACKET_ID_MESSAGE + MESSAGE_CORRECTION) /* 66 */
#define PACKET_ID_MSI 69
#define PACKET_ID_FILE_SENDREQUEST 80
#define PACKET_ID_FILE_CONTROL 81

View File

@ -1956,6 +1956,21 @@ int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *ac
return ret;
}
/* send a group correction message
* return 0 on success
* see: send_message_group() for error codes.
*/
int group_correction_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length)
{
int ret = send_message_group(g_c, groupnumber, PACKET_ID_CORRECTION, action, length);
if (ret > 0) {
return 0;
}
return ret;
}
/* High level function to send custom lossy packets.
*
* return -1 on failure.
@ -2083,7 +2098,9 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const
}
break;
case PACKET_ID_MESSAGE: {
case PACKET_ID_MESSAGE:
case PACKET_ID_ACTION:
case PACKET_ID_CORRECTION: {
if (msg_data_len == 0) {
return;
}
@ -2094,24 +2111,9 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const
// TODO(irungentoo):
if (g_c->message_callback) {
g_c->message_callback(g_c->m, groupnumber, index, 0, newmsg, msg_data_len, userdata);
}
break;
}
case PACKET_ID_ACTION: {
if (msg_data_len == 0) {
return;
}
VLA(uint8_t, newmsg, msg_data_len + 1);
memcpy(newmsg, msg_data, msg_data_len);
newmsg[msg_data_len] = 0;
// TODO(irungentoo):
if (g_c->message_callback) {
g_c->message_callback(g_c->m, groupnumber, index, 1, newmsg, msg_data_len, userdata);
uint8_t chat_message_id = message_id - PACKET_ID_MESSAGE;
g_c->message_callback(g_c->m, groupnumber, index, chat_message_id,
newmsg, msg_data_len, userdata);
}
break;

View File

@ -238,6 +238,12 @@ int group_message_send(const Group_Chats *g_c, int groupnumber, const uint8_t *m
*/
int group_action_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length);
/* send a group correction message
* return 0 on success
* see: send_message_group() for error codes.
*/
int group_correction_send(const Group_Chats *g_c, int groupnumber, const uint8_t *action, uint16_t length);
/* set the group's title, limited to MAX_NAME_LENGTH
* return 0 on success
* return -1 if groupnumber is invalid.

View File

@ -338,6 +338,11 @@ enum class MESSAGE_TYPE {
* on IRC.
*/
ACTION,
/**
* Correction of the last message. With empty message body can be used to mark
* last message as deleted.
*/
CORRECTION,
}

View File

@ -371,6 +371,12 @@ typedef enum TOX_MESSAGE_TYPE {
*/
TOX_MESSAGE_TYPE_ACTION,
/**
* Correction of the last message. With empty message body can be used to mark
* last message as deleted.
*/
TOX_MESSAGE_TYPE_CORRECTION,
} TOX_MESSAGE_TYPE;