[polari] room: Be more strict when highlighting messages
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] room: Be more strict when highlighting messages
- Date: Mon, 21 Sep 2015 21:27:06 +0000 (UTC)
commit 2d06b9ee1dff5d50cf1c9192ca8aef4e65be16b1
Author: Florian Müllner <fmuellner gnome org>
Date: Thu Sep 17 13:49:45 2015 +0200
room: Be more strict when highlighting messages
We currently highlight a messages if it contains the nick we match on,
regardless of where the match occurs. While this simplistic approach
works well enough for most nicks, it results in an annoying amount of
false positives for nicks that commonly appear in words. So tighten our
matching to not match when alphanumeric characters proceed or follow the
nick.
https://bugzilla.gnome.org/show_bug.cgi?id=755166
src/lib/polari-room.c | 23 ++++++++++++++++++++---
1 files changed, 20 insertions(+), 3 deletions(-)
---
diff --git a/src/lib/polari-room.c b/src/lib/polari-room.c
index f286356..180d05e 100644
--- a/src/lib/polari-room.c
+++ b/src/lib/polari-room.c
@@ -123,8 +123,9 @@ polari_room_should_highlight_message (PolariRoom *room,
PolariRoomPrivate *priv;
TpConnection *conn;
TpContact *self;
- char *text;
- gboolean result;
+ char *text, *match;
+ gboolean result = FALSE;
+ int len;
g_return_val_if_fail (POLARI_IS_ROOM (room), FALSE);
@@ -142,7 +143,23 @@ polari_room_should_highlight_message (PolariRoom *room,
return FALSE;
text = tp_message_to_text (message, NULL);
- result = strstr(text, priv->self_nick) != NULL;
+ len = strlen (priv->self_nick);
+ match = strstr (text, priv->self_nick);
+
+ while (match != NULL)
+ {
+ gboolean starts_word, ends_word;
+
+ /* assume ASCII nicknames, so no complex pango-style breaks */
+ starts_word = (match == text || g_ascii_isspace (*(match - 1)));
+ ends_word = !g_ascii_isalnum (*(match + len));
+
+ result = starts_word && ends_word;
+ if (result)
+ break;
+ match = strstr (match + len, priv->self_nick);
+ }
+
g_free (text);
return result;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]