From 99bfb9a4f2b15d3b5a9fe3878df2eb5e55c428aa Mon Sep 17 00:00:00 2001 From: Diadlo Date: Fri, 2 Feb 2018 15:00:06 +0300 Subject: [PATCH] Revert "Add correction message type" This reverts commit e16d3894c5979fcfe1c57bf7dadc455ce690baf9 and commit c5976e37eaadf663dc3d0c18376ea023355048f3. --- toxcore/Messenger.c | 6 ++---- toxcore/Messenger.h | 5 +---- toxcore/group.c | 40 +++++++++++++++++++--------------------- toxcore/group.h | 6 ------ toxcore/tox.api.h | 5 ----- toxcore/tox.c | 4 +--- toxcore/tox.h | 6 ------ 7 files changed, 23 insertions(+), 49 deletions(-) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index c665a1f866..73fab888ab 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -489,8 +489,7 @@ 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) { - /* MESSAGE_LAST itself is incorrect value */ - if (type >= MESSAGE_LAST) { + if (type > MESSAGE_ACTION) { return -5; } @@ -2216,8 +2215,7 @@ 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_CORRECTION: { + case PACKET_ID_ACTION: { if (data_length == 0) { break; } diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 26977036b6..6bf1bce80b 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h @@ -46,9 +46,7 @@ enum { MESSAGE_NORMAL, - MESSAGE_ACTION, - MESSAGE_CORRECTION, - MESSAGE_LAST + MESSAGE_ACTION }; /* NOTE: Packet ids below 24 must never be used. */ @@ -60,7 +58,6 @@ 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 diff --git a/toxcore/group.c b/toxcore/group.c index c929d9957b..3f14e8ceeb 100644 --- a/toxcore/group.c +++ b/toxcore/group.c @@ -1956,21 +1956,6 @@ 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. @@ -2098,9 +2083,24 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const } break; - case PACKET_ID_MESSAGE: - case PACKET_ID_ACTION: - case PACKET_ID_CORRECTION: { + case PACKET_ID_MESSAGE: { + 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, 0, newmsg, msg_data_len, userdata); + } + + break; + } + + case PACKET_ID_ACTION: { if (msg_data_len == 0) { return; } @@ -2111,9 +2111,7 @@ static void handle_message_packet_group(Group_Chats *g_c, int groupnumber, const // TODO(irungentoo): if (g_c->message_callback) { - 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); + g_c->message_callback(g_c->m, groupnumber, index, 1, newmsg, msg_data_len, userdata); } break; diff --git a/toxcore/group.h b/toxcore/group.h index 6c0baebffb..2e014da36d 100644 --- a/toxcore/group.h +++ b/toxcore/group.h @@ -238,12 +238,6 @@ 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. diff --git a/toxcore/tox.api.h b/toxcore/tox.api.h index 7f3d8d4cff..6395920750 100644 --- a/toxcore/tox.api.h +++ b/toxcore/tox.api.h @@ -338,11 +338,6 @@ 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, } diff --git a/toxcore/tox.c b/toxcore/tox.c index 7dd4a7b599..c3bcb65218 100644 --- a/toxcore/tox.c +++ b/toxcore/tox.c @@ -1300,10 +1300,8 @@ bool tox_conference_send_message(Tox *tox, uint32_t conference_number, TOX_MESSA if (type == TOX_MESSAGE_TYPE_NORMAL) { ret = group_message_send((Group_Chats *)m->conferences_object, conference_number, message, length); - } else if (type == TOX_MESSAGE_TYPE_ACTION) { + } else { ret = group_action_send((Group_Chats *)m->conferences_object, conference_number, message, length); - } else if (type == TOX_MESSAGE_TYPE_CORRECTION) { - ret = group_correction_send((Group_Chats *)m->conferences_object, conference_number, message, length); } switch (ret) { diff --git a/toxcore/tox.h b/toxcore/tox.h index f4f3d06639..567ce7e5d9 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -371,12 +371,6 @@ 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;