diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 922b8523..09061ad4 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -424,9 +424,11 @@ chatwin_outgoing_msg(ProfChatWin* chatwin, const char* const message, const char win_print_outgoing((ProfWin*)chatwin, enc_char, id, replace_id, display_message); } - // save last id and message for LMC in case if it's not LMC message - if (id && !replace_id) { - _chatwin_set_last_message(chatwin, id, display_message); + // Save last id and message for LMC + // Note: if the same message is to be corrected several times, the id of the original message is used in each case + // https://xmpp.org/extensions/xep-0308.html#rules + if (id) { + _chatwin_set_last_message(chatwin, replace_id ?: id, display_message); } } @@ -625,9 +627,13 @@ chatwin_db_history(ProfChatWin* chatwin, const gchar* start_time, const gchar* e static void _chatwin_set_last_message(ProfChatWin* chatwin, const char* const id, const char* const message) { - free(chatwin->last_message); - chatwin->last_message = strdup(message); + if (message && chatwin->last_message != message) { + free(chatwin->last_message); + chatwin->last_message = strdup(message); + } - free(chatwin->last_msg_id); - chatwin->last_msg_id = strdup(id); + if (id && chatwin->last_msg_id != id) { + free(chatwin->last_msg_id); + chatwin->last_msg_id = strdup(id); + } } diff --git a/tests/functionaltests/test_message.c b/tests/functionaltests/test_message.c index e622d7ff..d73f3bb4 100644 --- a/tests/functionaltests/test_message.c +++ b/tests/functionaltests/test_message.c @@ -27,6 +27,9 @@ message_send(void **state) assert_true(prof_output_regex("me: .+Hi there")); } +// TODO: `/message correct` XEP-0308 compliance (whether each correction links to the original message ID) +// https://xmpp.org/extensions/xep-0308.html#rules + void message_receive_console(void **state) {