[polari/wip/fmuellner/log-highlighting: 5/6] room: Change should_highlight() parameters



commit 8b1bf3abd727d8cf300eee21f7e54ab19c4cb47f
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Jul 9 02:21:54 2016 +0200

    room: Change should_highlight() parameters
    
    The should_highlight() method currently takes a TpMessage parameter,
    which we get from the channel when a message is sent or received.
    We don't get TpMessages from the logger though, so change method to
    take sender and message text separately as strings instead, to make
    it usable for log messages as well.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768613

 src/chatView.js       |    2 +-
 src/lib/polari-room.c |   15 ++++-----------
 src/lib/polari-room.h |    3 ++-
 src/roomList.js       |    3 ++-
 4 files changed, 9 insertions(+), 14 deletions(-)
---
diff --git a/src/chatView.js b/src/chatView.js
index e144658..a8099e8 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -1145,7 +1145,7 @@ const ChatView = new Lang.Class({
             timestamp = tpMessage.get_received_timestamp();
         message.timestamp = timestamp;
 
-        message.shouldHighlight = this._room.should_highlight_message(tpMessage);
+        message.shouldHighlight = this._room.should_highlight_message(message.nick, text);
 
         this._ensureNewLine();
 
diff --git a/src/lib/polari-room.c b/src/lib/polari-room.c
index aebe8e0..3495409 100644
--- a/src/lib/polari-room.c
+++ b/src/lib/polari-room.c
@@ -162,12 +162,10 @@ match_self_nick (PolariRoom *room,
 
 gboolean
 polari_room_should_highlight_message (PolariRoom *room,
-                                      TpMessage *message)
+                                      const char *sender,
+                                      const char *message)
 {
   PolariRoomPrivate *priv;
-  TpContact *sender;
-  char *text;
-  gboolean result = FALSE;
 
   g_return_val_if_fail (POLARI_IS_ROOM (room), FALSE);
 
@@ -176,15 +174,10 @@ polari_room_should_highlight_message (PolariRoom *room,
   if (priv->type != TP_HANDLE_TYPE_ROOM)
     return FALSE;
 
-  sender = tp_signalled_message_get_sender (message);
-  if (match_self_nick (room, tp_contact_get_alias (sender)))
+  if (match_self_nick (room, sender))
     return FALSE;
 
-  text = tp_message_to_text (message, NULL);
-  result = match_self_nick (room, text);
-  g_free (text);
-
-  return result;
+  return match_self_nick (room, message);
 }
 
 void
diff --git a/src/lib/polari-room.h b/src/lib/polari-room.h
index d2ece55..4db0b56 100644
--- a/src/lib/polari-room.h
+++ b/src/lib/polari-room.h
@@ -29,7 +29,8 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (PolariRoom, polari_room, POLARI, ROOM, GObject)
 
 gboolean polari_room_should_highlight_message (PolariRoom *room,
-                                               TpMessage *message);
+                                               const char *sender,
+                                               const char *message);
 
 void  polari_room_set_topic (PolariRoom *room, const char *topic);
 
diff --git a/src/roomList.js b/src/roomList.js
index cd79d68..f807238 100644
--- a/src/roomList.js
+++ b/src/roomList.js
@@ -80,7 +80,8 @@ const RoomRow = new Lang.Class({
             pending = room.channel.dup_pending_messages();
             if (room.channel.has_interface(Tp.IFACE_CHANNEL_INTERFACE_GROUP))
                 numPendingHighlights = pending.filter(function(m) {
-                    return room.should_highlight_message(m);
+                    let [text, ] = m.to_text();
+                    return room.should_highlight_message(m.sender.alias, text);
                 }).length;
             else
                 numPendingHighlights = pending.length;


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