fix(chatwin): Fix LMC autocompletion to suggest corrected message content
All checks were successful
CI / Check spelling (pull_request) Successful in 18s
CI / Check coding style (pull_request) Successful in 33s
CI / Linux (debian) (pull_request) Successful in 9m45s
CI / Linux (ubuntu) (pull_request) Successful in 10m0s
CI / Linux (arch) (pull_request) Successful in 16m48s

- Modified chatwin_outgoing_msg to call _chatwin_set_last_message for corrected messages, using replace_id per XEP-0308.
- Updated _chatwin_set_last_message to skip redundant and invalid free/strdup for same pointers.
- Added null checks in _chatwin_set_last_message for safety.
- Fixes autocompletion suggesting original message content instead of corrected content.

Fixes #24
This commit is contained in:
2025-09-02 00:29:13 +02:00
parent 51d2355d97
commit 2808def933
2 changed files with 16 additions and 7 deletions

View File

@@ -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);
}
}

View File

@@ -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)
{