From 6bc440c6f7e8c2c40d2d45f5c0decc15821abc8b Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 8 Jun 2021 19:42:41 +0200 Subject: Use utf-8 safe functions in _mucwin_print_mention() get_mentions() correctly counts utf-8 chars. So the positions of mentions we get from there are correct. But in _mucwin_print_mention() we set position equal to byte. We need to use utf-8 safe functions here. Regards https://github.com/profanity-im/profanity/issues/1231 --- src/ui/mucwin.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index bd67b53f..54db7a38 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -389,7 +389,8 @@ _mucwin_print_mention(ProfWin* window, const char* const message, const char* co while (curr) { pos = GPOINTER_TO_INT(curr->data); - char* before_str = g_strndup(message + last_pos, pos - last_pos); + char *before_str = g_utf8_substring(message, last_pos, last_pos + pos - last_pos); + if (strncmp(before_str, "/me ", 4) == 0) { win_print_them(window, THEME_ROOMMENTION, ch, flags, ""); win_append_highlight(window, THEME_ROOMMENTION, "*%s ", from); @@ -399,16 +400,22 @@ _mucwin_print_mention(ProfWin* window, const char* const message, const char* co win_append_highlight(window, THEME_ROOMMENTION, "%s", before_str); } g_free(before_str); - char* mynick_str = g_strndup(message + pos, strlen(mynick)); + + glong mynick_len = g_utf8_strlen(mynick, -1); + char* mynick_str = g_utf8_substring(message, pos, pos + mynick_len); win_append_highlight(window, THEME_ROOMMENTION_TERM, "%s", mynick_str); g_free(mynick_str); - last_pos = pos + strlen(mynick); + last_pos = pos + mynick_len; curr = g_slist_next(curr); } - if (last_pos < strlen(message)) { - win_appendln_highlight(window, THEME_ROOMMENTION, "%s", &message[last_pos]); + + glong message_len = g_utf8_strlen(message, -1); + if (last_pos < message_len) { + char* rest = g_utf8_substring(message, last_pos, last_pos + message_len); + win_appendln_highlight(window, THEME_ROOMMENTION, "%s", rest); + g_free(rest); } else { win_appendln_highlight(window, THEME_ROOMMENTION, ""); } -- cgit 1.4.1-2-gfad0 From f20f629bb4e07241a5095fb86960ae6b646ff7c7 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 8 Jun 2021 20:34:24 +0200 Subject: Fix multiple mentions in one line `jubalh: jubalh jubalh` resulted in `20:32:34 - testuser1: jubalh20:32:34 - testuser1: : jubalh20:32:34 - testuser1: jubalh` Print date/nick only once at beginning of line. --- src/ui/mucwin.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index 54db7a38..54778acb 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -396,7 +396,10 @@ _mucwin_print_mention(ProfWin* window, const char* const message, const char* co win_append_highlight(window, THEME_ROOMMENTION, "*%s ", from); win_append_highlight(window, THEME_ROOMMENTION, "%s", before_str + 4); } else { - win_print_them(window, THEME_ROOMMENTION, ch, flags, from); + // print time and nick only once at beginning of the line + if (last_pos == 0) { + win_print_them(window, THEME_ROOMMENTION, ch, flags, from); + } win_append_highlight(window, THEME_ROOMMENTION, "%s", before_str); } g_free(before_str); -- cgit 1.4.1-2-gfad0