[polari] room: Make highlighting a bit smarter



commit cc7042fa268c0bad3b5f39db3e6c3ac42c8617bb
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Oct 17 22:41:15 2013 +0200

    room: Make highlighting a bit smarter
    
    Not everyone is paying close attention to nick changes (or doesn't use
    tab completion for mentions), so we should be more forgiving when matching
    messages. In particular users may be connected with multiple clients, or
    get '_' automatically appended to their nick after reconnecting - handle
    these cases by stripping all non-alphanumeric characters from the matched
    nick. This still doesn't handle cases like 'nick-away', 'nick|lunch' etc.,
    but it is a clear improvement over the current behavior.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=710408

 src/lib/polari-room.c |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 44 insertions(+), 1 deletions(-)
---
diff --git a/src/lib/polari-room.c b/src/lib/polari-room.c
index 38fbe55..12611b4 100644
--- a/src/lib/polari-room.c
+++ b/src/lib/polari-room.c
@@ -28,6 +28,9 @@ struct _PolariRoomPrivate {
   char  *display_name;
   char  *topic;
 
+  char *self_nick;
+
+  guint self_contact_notify_id;
   guint identifier_notify_id;
   guint group_contacts_changed_id;
 
@@ -96,7 +99,7 @@ polari_room_should_highlight_message (PolariRoom *room,
     return FALSE;
 
   text = tp_message_to_text (message, NULL);
-  result = strstr(text, tp_contact_get_alias (self)) != NULL;
+  result = strstr(text, priv->self_nick) != NULL;
   g_free (text);
 
   return result;
@@ -190,6 +193,31 @@ polari_room_compare (PolariRoom *room,
 }
 
 static void
+update_self_nick (PolariRoom *room)
+{
+  TpConnection *conn;
+  TpContact *self;
+  const char *nick;
+  int len;
+
+  PolariRoomPrivate *priv = room->priv;
+
+  g_clear_pointer (&priv->self_nick, g_free);
+
+  conn = tp_channel_get_connection (room->priv->channel);
+  self = tp_connection_get_self_contact (conn);
+
+  nick = tp_contact_get_alias (self);
+  len = strlen (nick);
+  do
+    if (g_ascii_isalnum (nick[len - 1]))
+        break;
+  while (--len > 0);
+
+  priv->self_nick = g_strndup (nick, len);
+}
+
+static void
 update_identifier (PolariRoom *room)
 {
   PolariRoomPrivate *priv = room->priv;
@@ -228,6 +256,14 @@ update_icon (PolariRoom *room)
 }
 
 static void
+on_self_contact_notify (GObject    *object,
+                        GParamSpec *pspec,
+                        gpointer    user_data)
+{
+  update_self_nick (POLARI_ROOM (user_data));
+}
+
+static void
 on_identifier_notify (GObject    *object,
                       GParamSpec *pspec,
                       gpointer    user_data)
@@ -349,6 +385,8 @@ polari_room_set_channel (PolariRoom *room,
     {
       g_signal_handler_disconnect (priv->channel, priv->identifier_notify_id);
       g_signal_handler_disconnect (priv->channel, priv->group_contacts_changed_id);
+      g_signal_handler_disconnect (tp_channel_get_connection (priv->channel),
+                                   priv->self_contact_notify_id);
 
       tp_proxy_signal_connection_disconnect (priv->properties_changed_id);
 
@@ -368,6 +406,10 @@ polari_room_set_channel (PolariRoom *room,
                                      room, NULL, NULL);
 
 
+      priv->self_contact_notify_id =
+        g_signal_connect (tp_channel_get_connection (channel),
+                          "notify::self-contact",
+                          G_CALLBACK (on_self_contact_notify), room);
       priv->identifier_notify_id =
         g_signal_connect (channel, "notify::identifier",
                           G_CALLBACK (on_identifier_notify), room);
@@ -383,6 +425,7 @@ polari_room_set_channel (PolariRoom *room,
 
     g_object_freeze_notify (G_OBJECT (room));
 
+    update_self_nick (room);
     update_identifier (room);
     update_icon (room);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]