]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-chat.c
Updated Polish translation
[empathy.git] / libempathy-gtk / empathy-chat.c
index 52806e07c57a2cf6cdfedcaf8a593570fb4ff026..4db9e455c4a31a98c4b7e3c38a658588021ba124 100644 (file)
 
 #include <telepathy-glib/account-manager.h>
 #include <telepathy-glib/util.h>
+#ifdef ENABLE_TPL
+#include <telepathy-logger/log-manager.h>
+#else
 
 #include <libempathy/empathy-log-manager.h>
+#endif /* ENABLE_TPL */
 #include <libempathy/empathy-contact-list.h>
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-dispatcher.h>
 #include "empathy-contact-list-store.h"
 #include "empathy-contact-list-view.h"
 #include "empathy-contact-menu.h"
+#include "empathy-search-bar.h"
 #include "empathy-theme-manager.h"
 #include "empathy-smiley-manager.h"
 #include "empathy-ui-utils.h"
+#include "empathy-string-parser.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
 #include <libempathy/empathy-debug.h>
@@ -71,7 +77,11 @@ typedef struct {
        EmpathyContact    *remote_contact;
        gboolean           show_contacts;
 
+#ifdef ENABLE_TPL
+       TplLogManager     *log_manager;
+#else
        EmpathyLogManager *log_manager;
+#endif /* ENABLE_TPL */
        TpAccountManager  *account_manager;
        GList             *input_history;
        GList             *input_history_current;
@@ -93,6 +103,35 @@ typedef struct {
        GtkWidget         *label_topic;
        GtkWidget         *contact_list_view;
        GtkWidget         *info_bar_vbox;
+       GtkWidget         *search_bar;
+
+       guint              unread_messages;
+       /* TRUE if the pending messages can be displayed. This is to avoid to show
+        * pending messages *before* messages from logs. (#603980) */
+       gboolean           can_show_pending;
+
+       /* FIXME: retrieving_backlogs flag is a workaround for Bug#610994 and should
+        * be differently handled since it introduces another race condition, which
+        * is really hard to occur, but still possible.
+        *
+        * With the current workaround (which has the race above), we need to be
+        * sure to ACK any pending messages only when the retrieval of backlogs is
+        * finished, that's why using retrieving_backlogs flag.
+        * empathy_chat_messages_read () will check this variable and not ACK
+        * anything when TRUE. It will be set TRUE at chat_constructed () and set
+        * back to FALSE when the backlog has been retrieved and the pending
+        * messages actually showed to the user.
+        *
+        * Race condition introduced with this workaround:
+        * Scenario: a message is pending, the user is notified and selects the tab.
+        * the tab with a pending message is focused before the messages are properly
+        * shown (since the preparation of the window is slower AND async WRT the
+        * tab showing), which means the user won't see any new messages (rare but
+        * possible), if he/she will change tab focus before the messages are
+        * properly shown, the tab will be set as 'seen' and the user won't be
+        * notified again about the already notified pending messages when the
+        * messages in tab will be properly shown */
+       gboolean           retrieving_backlogs;
 } EmpathyChatPriv;
 
 typedef struct {
@@ -203,6 +242,43 @@ chat_connect_channel_reconnected (EmpathyDispatchOperation *dispatch,
        }
 }
 
+static void
+reconnected_connection_ready_cb (TpConnection *connection,
+                       const GError *error,
+                       gpointer user_data)
+{
+       EmpathyChat *chat = user_data;
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
+       if (error != NULL) {
+               DEBUG ("connection is not ready: %s", error->message);
+               goto out;
+       }
+
+       DEBUG ("Account reconnected, request a new Text channel");
+
+       switch (priv->handle_type) {
+               case TP_HANDLE_TYPE_CONTACT:
+                       empathy_dispatcher_chat_with_contact_id (
+                               connection, priv->id,
+                               chat_connect_channel_reconnected,
+                               chat);
+                       break;
+               case TP_HANDLE_TYPE_ROOM:
+                       empathy_dispatcher_join_muc (connection,
+                               priv->id,
+                               chat_connect_channel_reconnected,
+                               chat);
+                       break;
+               default:
+                       g_assert_not_reached ();
+                       break;
+       }
+
+out:
+       g_object_unref (chat);
+}
+
 static void
 chat_new_connection_cb (TpAccount   *account,
                        guint        old_status,
@@ -215,32 +291,19 @@ chat_new_connection_cb (TpAccount   *account,
        EmpathyChatPriv *priv = GET_PRIV (chat);
        TpConnection *connection;
 
-       connection = tp_account_get_connection (account);
+       if (new_status != TP_CONNECTION_STATUS_CONNECTED)
+               return;
 
-       if (!priv->tp_chat && account == priv->account &&
-           priv->handle_type != TP_HANDLE_TYPE_NONE &&
-           !EMP_STR_EMPTY (priv->id)) {
+       connection = tp_account_get_connection (account);
 
-               DEBUG ("Account reconnected, request a new Text channel");
+       if (priv->tp_chat != NULL || account != priv->account ||
+           priv->handle_type == TP_HANDLE_TYPE_NONE ||
+           EMP_STR_EMPTY (priv->id))
+               return;
 
-               switch (priv->handle_type) {
-                       case TP_HANDLE_TYPE_CONTACT:
-                               empathy_dispatcher_chat_with_contact_id (
-                                       connection, priv->id,
-                                       chat_connect_channel_reconnected,
-                                       chat);
-                               break;
-                       case TP_HANDLE_TYPE_ROOM:
-                               empathy_dispatcher_join_muc (connection,
-                                       priv->id,
-                                       chat_connect_channel_reconnected,
-                                       chat);
-                               break;
-                       default:
-                               g_assert_not_reached ();
-                               break;
-               }
-       }
+       g_object_ref (chat);
+       tp_connection_call_when_ready (connection, reconnected_connection_ready_cb,
+                                  chat);
 }
 
 static void
@@ -589,7 +652,7 @@ chat_command_join_cb (EmpathyDispatchOperation *dispatch,
        if (error != NULL) {
                DEBUG ("Error: %s", error->message);
                empathy_chat_view_append_event (chat->view,
-                       _("Failed to join chatroom"));
+                       _("Failed to join chat room"));
        }
 }
 
@@ -666,13 +729,24 @@ static void
 chat_command_join (EmpathyChat *chat,
                   GStrv        strv)
 {
+       guint i = 0;
        EmpathyChatPriv *priv = GET_PRIV (chat);
-       TpConnection *connection;
 
-       connection = empathy_tp_chat_get_connection (priv->tp_chat);
-       empathy_dispatcher_join_muc (connection, strv[1],
-                                    chat_command_join_cb,
-                                    chat);
+       GStrv rooms = g_strsplit_set (strv[1], ", ", -1);
+
+       while (rooms[i] != NULL) {
+               /* ignore empty strings */
+               if (!EMP_STR_EMPTY (rooms[i])) {
+                       TpConnection *connection;
+
+                       connection = empathy_tp_chat_get_connection (priv->tp_chat);
+                       empathy_dispatcher_join_muc (connection, rooms[i],
+                                                    chat_command_join_cb,
+                                                    chat);
+               }
+               i++;
+       }
+       g_strfreev (rooms);
 }
 
 static void
@@ -770,36 +844,36 @@ typedef struct {
 
 static ChatCommandItem commands[] = {
        {"clear", 1, 1, chat_command_clear,
-        N_("/clear, clear all messages from the current conversation")},
+        N_("/clear: clear all messages from the current conversation")},
 
        {"topic", 2, 2, chat_command_topic,
-        N_("/topic <topic>, set the topic of the current conversation")},
+        N_("/topic <topic>: set the topic of the current conversation")},
 
        {"join", 2, 2, chat_command_join,
-        N_("/join <chatroom id>, join a new chatroom")},
+        N_("/join <chat room ID>: join a new chat room")},
 
        {"j", 2, 2, chat_command_join,
-        N_("/j <chatroom id>, join a new chatroom")},
+        N_("/j <chat room ID>: join a new chat room")},
 
        {"query", 2, 3, chat_command_query,
-        N_("/query <contact id> [<message>], open a private chat")},
+        N_("/query <contact ID> [<message>]: open a private chat")},
 
        {"msg", 3, 3, chat_command_msg,
-        N_("/msg <contact id> <message>, open a private chat")},
+        N_("/msg <contact ID> <message>: open a private chat")},
 
        {"nick", 2, 2, chat_command_nick,
-        N_("/nick <nickname>, change your nickname on current server")},
+        N_("/nick <nickname>: change your nickname on the current server")},
 
        {"me", 2, 2, chat_command_me,
-        N_("/me <message>, send an ACTION message to the current conversation")},
+        N_("/me <message>: send an ACTION message to the current conversation")},
 
        {"say", 2, 2, chat_command_say,
-        N_("/say <message>, send <message> to the current conversation. "
+        N_("/say <message>: send <message> to the current conversation. "
            "This is used to send a message starting with a '/'. For example: "
-           "\"/say /join is used to join a new chatroom\"")},
+           "\"/say /join is used to join a new chat room\"")},
 
        {"help", 1, 2, chat_command_help,
-        N_("/help [<command>], show all supported commands. "
+        N_("/help [<command>]: show all supported commands. "
            "If <command> is defined, show its usage.")},
 };
 
@@ -959,7 +1033,7 @@ chat_send (EmpathyChat  *chat,
 
                if (!second_slash) {
                        empathy_chat_view_append_event (chat->view,
-                               _("Unknown command, see /help for the available"
+                               _("Unknown command; see /help for the available"
                                  " commands"));
                        return;
                }
@@ -1074,6 +1148,7 @@ chat_message_received (EmpathyChat *chat, EmpathyMessage *message)
                               TP_CHANNEL_CHAT_STATE_ACTIVE,
                               chat);
 
+       priv->unread_messages++;
        g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
 }
 
@@ -1083,7 +1158,6 @@ chat_message_received_cb (EmpathyTpChat  *tp_chat,
                          EmpathyChat    *chat)
 {
        chat_message_received (chat, message);
-       empathy_tp_chat_acknowledge_message (tp_chat, message);
 }
 
 static void
@@ -1139,7 +1213,12 @@ chat_property_changed_cb (EmpathyTpChat *tp_chat,
                if (EMP_STR_EMPTY (priv->subject)) {
                        gtk_widget_hide (priv->hbox_topic);
                } else {
-                       gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->subject);
+                       gchar *markup_text;
+
+                       markup_text = empathy_add_link_markup (priv->subject);
+                       gtk_label_set_markup (GTK_LABEL (priv->label_topic), markup_text);
+                       g_free (markup_text);
+
                        gtk_widget_show (priv->hbox_topic);
                }
                if (priv->block_events_timeout_id == 0) {
@@ -1240,6 +1319,13 @@ chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
        }
 }
 
+static gboolean
+empathy_isspace_cb (gunichar c,
+                gpointer data)
+{
+       return g_unichar_isspace (c);
+}
+
 static gboolean
 chat_input_key_press_event_cb (GtkWidget   *widget,
                               GdkEventKey *event,
@@ -1321,6 +1407,9 @@ chat_input_key_press_event_cb (GtkWidget   *widget,
                gtk_adjustment_set_value (adj, val);
                return TRUE;
        }
+       if (event->keyval == GDK_Escape) {
+               empathy_search_bar_hide (EMPATHY_SEARCH_BAR (priv->search_bar));
+       }
        if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
            event->keyval == GDK_Tab) {
                GtkTextBuffer *buffer;
@@ -1334,7 +1423,9 @@ chat_input_key_press_event_cb (GtkWidget   *widget,
 
                /* Get the start of the nick to complete. */
                gtk_text_buffer_get_iter_at_mark (buffer, &start, gtk_text_buffer_get_insert (buffer));
-               gtk_text_iter_backward_word_start (&start);
+               if (gtk_text_iter_backward_find_char (&start, &empathy_isspace_cb, NULL, NULL)) {
+                       gtk_text_iter_set_offset (&start, gtk_text_iter_get_offset (&start) + 1);
+               }
                is_start_of_buffer = gtk_text_iter_is_start (&start);
 
                list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
@@ -1351,6 +1442,8 @@ chat_input_key_press_event_cb (GtkWidget   *widget,
                        guint        len;
                        const gchar *text;
                        gchar       *complete_char = NULL;
+                       GString     *message = NULL;
+                       GList       *l;
 
                        gtk_text_buffer_delete (buffer, &start, &current);
 
@@ -1366,6 +1459,18 @@ chat_input_key_press_event_cb (GtkWidget   *widget,
                                text = empathy_contact_get_name (completed_list->data);
                        } else {
                                text = completed;
+
+                               /* Print all hits to the scrollback view, so the
+                                * user knows what possibilities he has.
+                                * Fixes #599779
+                                * */
+                                message = g_string_new ("");
+                                for (l = completed_list; l != NULL; l = l->next) {
+                                       g_string_append (message, empathy_contact_get_name (l->data));
+                                       g_string_append (message, " - ");
+                                }
+                                empathy_chat_view_append_event (chat->view, message->str);
+                                g_string_free (message, TRUE);
                        }
 
                        gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
@@ -1640,31 +1745,128 @@ chat_input_populate_popup_cb (GtkTextView *view,
        }
 }
 
+
+#ifdef ENABLE_TPL
+static gboolean
+chat_log_filter (TplLogEntry *log,
+                gpointer user_data)
+#else
 static gboolean
 chat_log_filter (EmpathyMessage *message,
                 gpointer user_data)
+#endif /* ENABLE_TPL */
 {
-       EmpathyChat *chat = (EmpathyChat *) user_data;
+       EmpathyChat *chat = user_data;
+#ifdef ENABLE_TPL
+       EmpathyMessage *message;
+#endif /* ENABLE_TPL */
        EmpathyChatPriv *priv = GET_PRIV (chat);
        const GList *pending;
 
+#ifdef ENABLE_TPL
+       g_return_val_if_fail (TPL_IS_LOG_ENTRY (log), FALSE);
+#else
+       g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE);
+#endif /* ENABLE_TPL */
+       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
+
        pending = empathy_tp_chat_get_pending_messages (priv->tp_chat);
+#ifdef ENABLE_TPL
+       message = empathy_message_from_tpl_log_entry (log);
+#endif /* ENABLE_TPL */
 
        for (; pending; pending = g_list_next (pending)) {
                if (empathy_message_equal (message, pending->data)) {
                        return FALSE;
                }
        }
-
+#ifdef ENABLE_TPL
+       g_object_unref (message);
+#endif
        return TRUE;
 }
 
+
+static void
+show_pending_messages (EmpathyChat *chat) {
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       const GList *messages, *l;
+
+       g_return_if_fail (EMPATHY_IS_CHAT (chat));
+
+       if (chat->view == NULL || priv->tp_chat == NULL)
+               return;
+
+       if (!priv->can_show_pending)
+               return;
+
+       messages = empathy_tp_chat_get_pending_messages (priv->tp_chat);
+
+       for (l = messages; l != NULL ; l = g_list_next (l)) {
+               EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
+               chat_message_received (chat, message);
+       }
+}
+
+
+#ifdef ENABLE_TPL
+static void
+got_filtered_messages_cb (GObject *manager,
+               GAsyncResult *result,
+               gpointer user_data)
+{
+       GList *l;
+       GList *messages;
+       EmpathyChat *chat = EMPATHY_CHAT (user_data);
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       GError *error = NULL;
+
+       messages = tpl_log_manager_get_filtered_messages_async_finish (result, &error);
+
+       if (error != NULL) {
+               DEBUG ("%s. Aborting.", error->message);
+               empathy_chat_view_append_event (chat->view,
+                       _("Failed to retrieve recent logs"));
+               g_error_free (error);
+               goto out;
+       }
+
+       for (l = messages; l; l = g_list_next (l)) {
+               EmpathyMessage *message;
+               g_assert (TPL_IS_LOG_ENTRY (l->data));
+
+               message = empathy_message_from_tpl_log_entry (l->data);
+               g_object_unref (l->data);
+
+               empathy_chat_view_append_message (chat->view, message);
+               g_object_unref (message);
+       }
+       g_list_free (messages);
+
+out:
+       /* in case of TPL error, skip backlog and show pending messages */
+       priv->can_show_pending = TRUE;
+       show_pending_messages (chat);
+
+       /* FIXME: See Bug#610994, we are forcing the ACK of the queue. See comments
+        * about it in EmpathyChatPriv definition */
+       priv->retrieving_backlogs = FALSE;
+       empathy_chat_messages_read (chat);
+
+       /* Turn back on scrolling */
+       empathy_chat_view_scroll (chat->view, TRUE);
+}
+#endif /* ENABLE_TPL */
+
+
 static void
 chat_add_logs (EmpathyChat *chat)
 {
        EmpathyChatPriv *priv = GET_PRIV (chat);
        gboolean         is_chatroom;
+#ifndef ENABLE_TPL
        GList           *messages, *l;
+#endif /* ENABLE_TPL */
 
        if (!priv->id) {
                return;
@@ -1676,6 +1878,7 @@ chat_add_logs (EmpathyChat *chat)
        /* Add messages from last conversation */
        is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
 
+#ifndef ENABLE_TPL
        messages = empathy_log_manager_get_filtered_messages (priv->log_manager,
                                                              priv->account,
                                                              priv->id,
@@ -1693,6 +1896,18 @@ chat_add_logs (EmpathyChat *chat)
 
        /* Turn back on scrolling */
        empathy_chat_view_scroll (chat->view, TRUE);
+#else
+       priv->retrieving_backlogs = TRUE;
+       tpl_log_manager_get_filtered_messages_async (priv->log_manager,
+                                                             priv->account,
+                                                             priv->id,
+                                                             is_chatroom,
+                                                             5,
+                                                             chat_log_filter,
+                                                             chat,
+                                                             got_filtered_messages_cb,
+                                                             (gpointer) chat);
+#endif /* ENABLE_TPL */
 }
 
 static gint
@@ -1844,18 +2059,20 @@ chat_reset_size_request (gpointer widget)
 }
 
 static void
-chat_update_contacts_visibility (EmpathyChat *chat)
+chat_update_contacts_visibility (EmpathyChat *chat,
+                        gboolean show)
 {
        EmpathyChatPriv *priv = GET_PRIV (chat);
-       gboolean show;
        GtkAllocation allocation;
 
-       show = priv->remote_contact == NULL && priv->show_contacts;
-
        if (!priv->scrolled_window_contacts) {
                return;
        }
 
+       if (priv->remote_contact != NULL) {
+               show = FALSE;
+       }
+
        if (show && priv->contact_list_view == NULL) {
                EmpathyContactListStore *store;
                gint                     min_width;
@@ -1906,7 +2123,7 @@ empathy_chat_set_show_contacts (EmpathyChat *chat,
 
        priv->show_contacts = show;
 
-       chat_update_contacts_visibility (chat);
+       chat_update_contacts_visibility (chat, show);
 
        g_object_notify (G_OBJECT (chat), "show-contacts");
 }
@@ -1936,7 +2153,7 @@ chat_remote_contact_changed_cb (EmpathyChat *chat)
                g_object_get (channel, "handle-type", &priv->handle_type, NULL);
        }
 
-       chat_update_contacts_visibility (chat);
+       chat_update_contacts_visibility (chat, priv->show_contacts);
 
        g_object_notify (G_OBJECT (chat), "remote-contact");
        g_object_notify (G_OBJECT (chat), "id");
@@ -1961,24 +2178,19 @@ chat_destroy_cb (EmpathyTpChat *tp_chat,
 
        empathy_chat_view_append_event (chat->view, _("Disconnected"));
        gtk_widget_set_sensitive (chat->input_text_view, FALSE);
-       empathy_chat_set_show_contacts (chat, FALSE);
-}
-
-static void
-show_pending_messages (EmpathyChat *chat) {
-       EmpathyChatPriv *priv = GET_PRIV (chat);
-       const GList *messages, *l;
 
-       if (chat->view == NULL || priv->tp_chat == NULL)
-               return;
-
-       messages = empathy_tp_chat_get_pending_messages (priv->tp_chat);
+       chat_update_contacts_visibility (chat, FALSE);
+}
 
-       for (l = messages; l != NULL ; l = g_list_next (l)) {
-               EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
-               chat_message_received (chat, message);
-       }
-       empathy_tp_chat_acknowledge_messages (priv->tp_chat, messages);
+static gboolean
+chat_hpaned_pos_changed_cb (GtkWidget* hpaned, gpointer user_data)
+{
+       gint hpaned_pos;
+       hpaned_pos = gtk_paned_get_position (GTK_PANED(hpaned));
+       empathy_conf_set_int (empathy_conf_get (),
+                             EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS,
+                             hpaned_pos);
+       return TRUE;
 }
 
 static void
@@ -1989,6 +2201,7 @@ chat_create_ui (EmpathyChat *chat)
        GList           *list = NULL;
        gchar           *filename;
        GtkTextBuffer   *buffer;
+       gint              paned_pos;
 
        filename = empathy_file_lookup ("empathy-chat.ui",
                                        "libempathy-gtk");
@@ -2052,11 +2265,30 @@ chat_create_ui (EmpathyChat *chat)
                           chat->input_text_view);
        gtk_widget_show (chat->input_text_view);
 
+       /* Add the (invisible) search bar */
+       priv->search_bar = empathy_search_bar_new (chat->view);
+       gtk_box_pack_start (GTK_BOX(priv->vbox_left),
+                           priv->search_bar,
+                           FALSE, FALSE, 0);
+       gtk_box_reorder_child (GTK_BOX(priv->vbox_left), priv->search_bar, 1);
+
        /* Initialy hide the topic, will be shown if not empty */
        gtk_widget_hide (priv->hbox_topic);
 
+       g_signal_connect (priv->hpaned, "notify::position",
+                         G_CALLBACK (chat_hpaned_pos_changed_cb),
+                         NULL);
+
+        /* Load the paned position */
+       if (empathy_conf_get_int (empathy_conf_get (),
+                                EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS,
+                                &paned_pos)
+               && paned_pos)
+               gtk_paned_set_position (GTK_PANED(priv->hpaned), paned_pos);
+
        /* Set widget focus order */
-       list = g_list_append (NULL, priv->scrolled_window_input);
+       list = g_list_append (NULL, priv->search_bar);
+       list = g_list_append (list, priv->scrolled_window_input);
        gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
        g_list_free (list);
 
@@ -2158,7 +2390,7 @@ chat_finalize (GObject *object)
                        chat_members_changed_cb, chat);
                g_signal_handlers_disconnect_by_func (priv->tp_chat,
                        chat_remote_contact_changed_cb, chat);
-               empathy_tp_chat_close (priv->tp_chat);
+               empathy_tp_chat_leave (priv->tp_chat);
                g_object_unref (priv->tp_chat);
        }
        if (priv->account) {
@@ -2184,9 +2416,16 @@ static void
 chat_constructed (GObject *object)
 {
        EmpathyChat *chat = EMPATHY_CHAT (object);
+       EmpathyChatPriv *priv = GET_PRIV (chat);
 
-       chat_add_logs (chat);
+       if (priv->handle_type != TP_HANDLE_TYPE_ROOM)
+               chat_add_logs (chat);
+#ifndef ENABLE_TPL
+       /* When async API are involved, pending message are shown at the end of the
+        * callbacks' chain fired by chat_add_logs */
+       priv->can_show_pending = TRUE;
        show_pending_messages (chat);
+#endif /* ENABLE_TPL */
 }
 
 static void
@@ -2329,7 +2568,11 @@ empathy_chat_init (EmpathyChat *chat)
                EMPATHY_TYPE_CHAT, EmpathyChatPriv);
 
        chat->priv = priv;
+#ifndef ENABLE_TPL
        priv->log_manager = empathy_log_manager_dup_singleton ();
+#else
+       priv->log_manager = tpl_log_manager_dup_singleton ();
+#endif /* ENABLE_TPL */
        priv->contacts_width = -1;
        priv->input_history = NULL;
        priv->input_history_current = NULL;
@@ -2778,6 +3021,18 @@ empathy_chat_paste (EmpathyChat *chat)
        gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
 }
 
+void
+empathy_chat_find (EmpathyChat *chat)
+{
+       EmpathyChatPriv *priv;
+
+       g_return_if_fail (EMPATHY_IS_CHAT (chat));
+
+       priv = GET_PRIV (chat);
+
+       empathy_search_bar_show (EMPATHY_SEARCH_BAR (priv->search_bar));
+}
+
 void
 empathy_chat_correct_word (EmpathyChat  *chat,
                          GtkTextIter *start,
@@ -2807,3 +3062,31 @@ empathy_chat_is_room (EmpathyChat *chat)
        return (priv->handle_type == TP_HANDLE_TYPE_ROOM);
 }
 
+guint
+empathy_chat_get_nb_unread_messages (EmpathyChat *self)
+{
+       EmpathyChatPriv *priv = GET_PRIV (self);
+
+       g_return_val_if_fail (EMPATHY_IS_CHAT (self), 0);
+
+       return priv->unread_messages;
+}
+
+/* called when the messages have been read by user */
+void
+empathy_chat_messages_read (EmpathyChat *self)
+{
+       EmpathyChatPriv *priv = GET_PRIV (self);
+
+       g_return_if_fail (EMPATHY_IS_CHAT (self));
+
+       /* FIXME: See Bug#610994, See comments about it in EmpathyChatPriv
+        * definition. If we are still retrieving the backlogs, do not ACK */
+       if (priv->retrieving_backlogs)
+               return;
+
+       if (priv->tp_chat != NULL ) {
+                       empathy_tp_chat_acknowledge_all_messages (priv->tp_chat);
+       }
+       priv->unread_messages = 0;
+}