]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-chat.c
Disconnect all signals from tp_chat when the UI is destroyed
[empathy.git] / libempathy-gtk / empathy-chat.c
index af35b033467109b8c6972490614af5083f83c5a7..985eaa4cf6f3dc57a8e8682a276d55e0a734974f 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
  * Copyright (C) 2002-2007 Imendio AB
- * Copyright (C) 2007 Collabora Ltd.
+ * Copyright (C) 2007-2008 Collabora Ltd.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License as
  *          Xavier Claessens <xclaesse@gmail.com>
  */
 
-#include "config.h"
+#include <config.h>
 
 #include <string.h>
 #include <stdlib.h>
 
 #include <gdk/gdkkeysyms.h>
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 
-#include <libempathy/empathy-contact-manager.h>
+#include <telepathy-glib/util.h>
+
+#include <libempathy/empathy-account-manager.h>
 #include <libempathy/empathy-log-manager.h>
-#include <libempathy/empathy-debug.h>
+#include <libempathy/empathy-contact-list.h>
 #include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-conf.h>
-#include <libempathy/empathy-marshal.h>
+#include <libempathy/empathy-dispatcher.h>
 
 #include "empathy-chat.h"
-#include "empathy-chat-window.h"
-#include "empathy-geometry.h"
-#include "empathy-preferences.h"
+#include "empathy-conf.h"
 #include "empathy-spell.h"
 #include "empathy-spell-dialog.h"
+#include "empathy-contact-list-store.h"
+#include "empathy-contact-list-view.h"
+#include "empathy-contact-menu.h"
+#include "empathy-theme-manager.h"
+#include "empathy-smiley-manager.h"
 #include "empathy-ui-utils.h"
 
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CHAT, EmpathyChatPriv))
-
-#define DEBUG_DOMAIN "Chat"
+#define DEBUG_FLAG EMPATHY_DEBUG_CHAT
+#include <libempathy/empathy-debug.h>
 
 #define CHAT_DIR_CREATE_MODE  (S_IRUSR | S_IWUSR | S_IXUSR)
 #define CHAT_FILE_CREATE_MODE (S_IRUSR | S_IWUSR)
-
 #define IS_ENTER(v) (v == GDK_Return || v == GDK_ISO_Enter || v == GDK_KP_Enter)
-
 #define MAX_INPUT_HEIGHT 150
-
 #define COMPOSING_STOP_TIMEOUT 5
 
-struct _EmpathyChatPriv {
-       EmpathyContactManager *manager;
-       EmpathyLogManager     *log_manager;
-       EmpathyTpChat         *tp_chat;
-       EmpathyChatWindow      *window;
-       GtkTooltips           *tooltips;
-       guint                  composing_stop_timeout_id;
-       gboolean               sensitive;
-       gchar                 *id;
-       GSList                *sent_messages;
-       gint                   sent_messages_index;
-       GList                 *compositors;
-       guint                  scroll_idle_id;
-       gboolean               first_tp_chat;
-       EmpathyTime            last_log_timestamp;
-       /* Used to automatically shrink a window that has temporarily
-        * grown due to long input. 
-        */
-       gint                   padding_height;
-       gint                   default_window_height;
-       gint                   last_input_height;
-       gboolean               vscroll_visible;
-};
-
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChat)
 typedef struct {
-       EmpathyChat  *chat;
-       gchar       *word;
-
-       GtkTextIter  start;
-       GtkTextIter  end;
-} EmpathyChatSpell;
-
-static void             empathy_chat_class_init           (EmpathyChatClass              *klass);
-static void             empathy_chat_init                 (EmpathyChat                   *chat);
-static void             chat_finalize                     (GObject                       *object);
-static void             chat_destroy_cb                   (EmpathyTpChat                 *tp_chat,
-                                                          EmpathyChat                   *chat);
-static void             chat_send                         (EmpathyChat                   *chat,
-                                                          const gchar                   *msg);
-static void             chat_input_text_view_send         (EmpathyChat                   *chat);
-static void             chat_message_received_cb          (EmpathyTpChat                 *tp_chat,
-                                                          EmpathyMessage                *message,
-                                                          EmpathyChat                   *chat);
-static void             chat_send_error_cb                (EmpathyTpChat                 *tp_chat,
-                                                          EmpathyMessage                *message,
-                                                          TelepathyChannelTextSendError  error_code,
-                                                          EmpathyChat                   *chat);
-void                    chat_sent_message_add             (EmpathyChat                   *chat,
-                                                          const gchar                   *str);
-const gchar *           chat_sent_message_get_next        (EmpathyChat                   *chat);
-const gchar *           chat_sent_message_get_last        (EmpathyChat                   *chat);
-static gboolean         chat_input_key_press_event_cb     (GtkWidget                     *widget,
-                                                          GdkEventKey                   *event,
-                                                          EmpathyChat                   *chat);
-static void             chat_input_text_buffer_changed_cb (GtkTextBuffer                 *buffer,
-                                                          EmpathyChat                   *chat);
-static gboolean         chat_text_view_focus_in_event_cb  (GtkWidget                     *widget,
-                                                          GdkEvent                      *event,
-                                                          EmpathyChat                   *chat);
-static void             chat_text_view_scroll_hide_cb     (GtkWidget                     *widget,
-                                                          EmpathyChat                   *chat);
-static void             chat_text_view_size_allocate_cb   (GtkWidget                     *widget,
-                                                          GtkAllocation                 *allocation,
-                                                          EmpathyChat                   *chat);
-static void             chat_text_view_realize_cb         (GtkWidget                     *widget,
-                                                          EmpathyChat                   *chat);
-static void             chat_text_populate_popup_cb       (GtkTextView                   *view,
-                                                          GtkMenu                       *menu,
-                                                          EmpathyChat                   *chat);
-static void             chat_text_check_word_spelling_cb  (GtkMenuItem                   *menuitem,
-                                                          EmpathyChatSpell              *chat_spell);
-static EmpathyChatSpell *chat_spell_new                   (EmpathyChat                   *chat,
-                                                          const gchar                   *word,
-                                                          GtkTextIter                    start,
-                                                          GtkTextIter                    end);
-static void             chat_spell_free                   (EmpathyChatSpell              *chat_spell);
-static void             chat_composing_start              (EmpathyChat                   *chat);
-static void             chat_composing_stop               (EmpathyChat                   *chat);
-static void             chat_composing_remove_timeout     (EmpathyChat                   *chat);
-static gboolean         chat_composing_stop_timeout_cb    (EmpathyChat                   *chat);
-static void             chat_state_changed_cb             (EmpathyTpChat                 *tp_chat,
-                                                          EmpathyContact                *contact,
-                                                          TelepathyChannelChatState      state,
-                                                          EmpathyChat                   *chat);
-static void             chat_add_logs                     (EmpathyChat                   *chat);
-static gboolean         chat_scroll_down_idle_func        (EmpathyChat                   *chat);
+       EmpathyTpChat     *tp_chat;
+       McAccount         *account;
+       gchar             *id;
+       gchar             *name;
+       gchar             *subject;
+       EmpathyContact    *remote_contact;
+
+       EmpathyLogManager *log_manager;
+       EmpathyAccountManager *account_manager;
+       GSList            *sent_messages;
+       gint               sent_messages_index;
+       GList             *compositors;
+       GCompletion       *completion;
+       guint              composing_stop_timeout_id;
+       guint              block_events_timeout_id;
+       TpHandleType       handle_type;
+       gint               contacts_width;
+       gboolean           has_input_vscroll;
+
+       GtkWidget         *widget;
+       GtkWidget         *hpaned;
+       GtkWidget         *vbox_left;
+       GtkWidget         *scrolled_window_chat;
+       GtkWidget         *scrolled_window_input;
+       GtkWidget         *scrolled_window_contacts;
+       GtkWidget         *hbox_topic;
+       GtkWidget         *label_topic;
+       GtkWidget         *contact_list_view;
+} EmpathyChatPriv;
 
 enum {
        COMPOSING,
        NEW_MESSAGE,
-       NAME_CHANGED,
-       STATUS_CHANGED,
        LAST_SIGNAL
 };
 
+enum {
+       PROP_0,
+       PROP_TP_CHAT,
+       PROP_ACCOUNT,
+       PROP_ID,
+       PROP_NAME,
+       PROP_SUBJECT,
+       PROP_REMOTE_CONTACT,
+};
+
 static guint signals[LAST_SIGNAL] = { 0 };
 
-G_DEFINE_TYPE (EmpathyChat, empathy_chat, G_TYPE_OBJECT);
+G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BIN);
 
 static void
-empathy_chat_class_init (EmpathyChatClass *klass)
+chat_get_property (GObject    *object,
+                  guint       param_id,
+                  GValue     *value,
+                  GParamSpec *pspec)
 {
-       GObjectClass *object_class;
-
-       object_class = G_OBJECT_CLASS (klass);
-
-       object_class->finalize = chat_finalize;
-
-       signals[COMPOSING] =
-               g_signal_new ("composing",
-                             G_OBJECT_CLASS_TYPE (object_class),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__BOOLEAN,
-                             G_TYPE_NONE,
-                             1, G_TYPE_BOOLEAN);
-
-       signals[NEW_MESSAGE] =
-               g_signal_new ("new-message",
-                             G_OBJECT_CLASS_TYPE (object_class),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             empathy_marshal_VOID__OBJECT_BOOLEAN,
-                             G_TYPE_NONE,
-                             2, EMPATHY_TYPE_MESSAGE, G_TYPE_BOOLEAN);
-
-       signals[NAME_CHANGED] =
-               g_signal_new ("name-changed",
-                             G_OBJECT_CLASS_TYPE (object_class),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__POINTER,
-                             G_TYPE_NONE,
-                             1, G_TYPE_POINTER);
-
-       signals[STATUS_CHANGED] =
-               g_signal_new ("status-changed",
-                             G_OBJECT_CLASS_TYPE (object_class),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__VOID,
-                             G_TYPE_NONE,
-                             0);
+       EmpathyChat *chat = EMPATHY_CHAT (object);
+       EmpathyChatPriv *priv = GET_PRIV (object);
 
-       g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
+       switch (param_id) {
+       case PROP_TP_CHAT:
+               g_value_set_object (value, priv->tp_chat);
+               break;
+       case PROP_ACCOUNT:
+               g_value_set_object (value, priv->account);
+               break;
+       case PROP_NAME:
+               g_value_set_string (value, empathy_chat_get_name (chat));
+               break;
+       case PROP_ID:
+               g_value_set_string (value, priv->id);
+               break;
+       case PROP_SUBJECT:
+               g_value_set_string (value, priv->subject);
+               break;
+       case PROP_REMOTE_CONTACT:
+               g_value_set_object (value, priv->remote_contact);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+               break;
+       };
 }
 
 static void
-empathy_chat_init (EmpathyChat *chat)
+chat_set_property (GObject      *object,
+                  guint         param_id,
+                  const GValue *value,
+                  GParamSpec   *pspec)
 {
-       EmpathyChatPriv *priv;
-       GtkTextBuffer  *buffer;
-
-       chat->view = empathy_chat_view_new ();
-       chat->input_text_view = gtk_text_view_new ();
-
-       chat->is_first_char = TRUE;
-
-       g_object_set (chat->input_text_view,
-                     "pixels-above-lines", 2,
-                     "pixels-below-lines", 2,
-                     "pixels-inside-wrap", 1,
-                     "right-margin", 2,
-                     "left-margin", 2,
-                     "wrap-mode", GTK_WRAP_WORD_CHAR,
-                     NULL);
-
-       priv = GET_PRIV (chat);
-
-       priv->manager = empathy_contact_manager_new ();
-       priv->log_manager = empathy_log_manager_new ();
-       priv->tooltips = g_object_ref_sink (gtk_tooltips_new ());
-       priv->default_window_height = -1;
-       priv->vscroll_visible = FALSE;
-       priv->sensitive = TRUE;
-       priv->sent_messages = NULL;
-       priv->sent_messages_index = -1;
-       priv->first_tp_chat = TRUE;
-
-       g_signal_connect (chat->input_text_view,
-                         "key_press_event",
-                         G_CALLBACK (chat_input_key_press_event_cb),
-                         chat);
-
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
-       g_signal_connect (buffer,
-                         "changed",
-                         G_CALLBACK (chat_input_text_buffer_changed_cb),
-                         chat);
-       g_signal_connect (chat->view,
-                         "focus_in_event",
-                         G_CALLBACK (chat_text_view_focus_in_event_cb),
-                         chat);
-
-       g_signal_connect (chat->input_text_view,
-                         "size_allocate",
-                         G_CALLBACK (chat_text_view_size_allocate_cb),
-                         chat);
-
-       g_signal_connect (chat->input_text_view,
-                         "realize",
-                         G_CALLBACK (chat_text_view_realize_cb),
-                         chat);
-
-       g_signal_connect (GTK_TEXT_VIEW (chat->input_text_view),
-                         "populate_popup",
-                         G_CALLBACK (chat_text_populate_popup_cb),
-                         chat);
+       EmpathyChat *chat = EMPATHY_CHAT (object);
 
-       /* create misspelt words identification tag */
-       gtk_text_buffer_create_tag (buffer,
-                                   "misspelled",
-                                   "underline", PANGO_UNDERLINE_ERROR,
-                                   NULL);
+       switch (param_id) {
+       case PROP_TP_CHAT:
+               empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value)));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+               break;
+       };
 }
 
 static void
-chat_finalize (GObject *object)
+chat_connect_channel_reconnected (EmpathyDispatchOperation *dispatch,
+                                 const GError             *error,
+                                 gpointer                  user_data)
 {
-       EmpathyChat     *chat;
-       EmpathyChatPriv *priv;
+       EmpathyChat *chat = EMPATHY_CHAT (user_data);
+       EmpathyTpChat *tpchat;
 
-       chat = EMPATHY_CHAT (object);
-       priv = GET_PRIV (chat);
-
-       empathy_debug (DEBUG_DOMAIN, "Finalized: %p", object);
-
-       g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
-       g_slist_free (priv->sent_messages);
-
-       g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
-       g_list_free (priv->compositors);
-
-       chat_composing_remove_timeout (chat);
-       g_object_unref (chat->account);
-       g_object_unref (priv->manager);
-       g_object_unref (priv->log_manager);
-       g_object_unref (priv->tooltips);
-
-       if (priv->tp_chat) {
-               g_object_unref (priv->tp_chat);
-       }
-
-       if (priv->scroll_idle_id) {
-               g_source_remove (priv->scroll_idle_id);
+       if (error != NULL) {
+               empathy_chat_view_append_event (chat->view,
+                       _("Failed to reconnect this chat"));
+               return;
        }
 
-       g_free (priv->id);
+       tpchat = EMPATHY_TP_CHAT (
+               empathy_dispatch_operation_get_channel_wrapper (dispatch));
 
-       G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
+       if (empathy_dispatch_operation_claim (dispatch)) {
+               empathy_chat_set_tp_chat (chat, tpchat);
+       }
 }
 
 static void
-chat_destroy_cb (EmpathyTpChat *tp_chat,
-                EmpathyChat    *chat)
+chat_new_connection_cb (EmpathyAccountManager *manager,
+                       TpConnection *connection,
+                       EmpathyChat *chat)
 {
-       EmpathyChatPriv *priv;
-
-       priv = GET_PRIV (chat);
-
-       if (priv->tp_chat) {
-               g_object_unref (priv->tp_chat);
-               priv->tp_chat = NULL;
-       }
-       priv->sensitive = FALSE;
-
-       empathy_chat_view_append_event (chat->view, _("Disconnected"));
-       gtk_widget_set_sensitive (chat->input_text_view, FALSE);
-
-       if (EMPATHY_CHAT_GET_CLASS (chat)->set_tp_chat) {
-               EMPATHY_CHAT_GET_CLASS (chat)->set_tp_chat (chat, NULL);
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       McAccount *account;
+
+       account = empathy_account_manager_get_account (manager, connection);
+       if (!priv->tp_chat && empathy_account_equal (account, priv->account) &&
+           priv->handle_type != TP_HANDLE_TYPE_NONE &&
+           !EMP_STR_EMPTY (priv->id)) {
+               
+               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;
+               }
        }
 }
 
 static void
-chat_send (EmpathyChat  *chat,
-          const gchar *msg)
+chat_composing_remove_timeout (EmpathyChat *chat)
 {
        EmpathyChatPriv *priv;
-       EmpathyMessage  *message;
 
        priv = GET_PRIV (chat);
 
-       if (G_STR_EMPTY (msg)) {
-               return;
-       }
-
-       chat_sent_message_add (chat, msg);
-
-       if (g_str_has_prefix (msg, "/clear")) {
-               empathy_chat_view_clear (chat->view);
-               return;
+       if (priv->composing_stop_timeout_id) {
+               g_source_remove (priv->composing_stop_timeout_id);
+               priv->composing_stop_timeout_id = 0;
        }
-
-       /* FIXME: add here something to let group/privrate chat handle
-        *        some special messages */
-
-       message = empathy_message_new (msg);
-
-       empathy_tp_chat_send (priv->tp_chat, message);
-
-       g_object_unref (message);
 }
 
-static void
-chat_input_text_view_send (EmpathyChat *chat)
+static gboolean
+chat_composing_stop_timeout_cb (EmpathyChat *chat)
 {
        EmpathyChatPriv *priv;
-       GtkTextBuffer  *buffer;
-       GtkTextIter     start, end;
-       gchar          *msg;
 
        priv = GET_PRIV (chat);
 
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
-
-       gtk_text_buffer_get_bounds (buffer, &start, &end);
-       msg = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
-
-       /* clear the input field */
-       gtk_text_buffer_set_text (buffer, "", -1);
-
-       chat_send (chat, msg);
-
-       g_free (msg);
+       priv->composing_stop_timeout_id = 0;
+       empathy_tp_chat_set_state (priv->tp_chat,
+                                  TP_CHANNEL_CHAT_STATE_PAUSED);
 
-       chat->is_first_char = TRUE;
+       return FALSE;
 }
 
 static void
-chat_message_received_cb (EmpathyTpChat  *tp_chat,
-                         EmpathyMessage *message,
-                         EmpathyChat    *chat)
+chat_composing_start (EmpathyChat *chat)
 {
        EmpathyChatPriv *priv;
-       EmpathyContact  *sender;
-       EmpathyTime      timestamp;
 
        priv = GET_PRIV (chat);
 
-       timestamp = empathy_message_get_timestamp (message);
-       if (timestamp <= priv->last_log_timestamp) {
-               /* Do not take care of messages anterior of the last
-                * logged message. Some Jabber chatroom sends messages
-                * received before we joined the room, this avoid
-                * displaying those messages if we already logged them
-                * last time we joined that room. */
-               empathy_debug (DEBUG_DOMAIN, "Skipping message because it is "
-                              "anterior of last logged message.");
-               return;
-       }
-
-       sender = empathy_message_get_sender (message);
-       empathy_debug (DEBUG_DOMAIN, "Appending message ('%s')",
-                     empathy_contact_get_name (sender));
-
-       empathy_log_manager_add_message (priv->log_manager,
-                                        empathy_chat_get_id (chat),
-                                        empathy_chat_is_group_chat (chat),
-                                        message);
-
-       empathy_chat_view_append_message (chat->view, message);
-
-       if (empathy_chat_should_play_sound (chat)) {
-               // FIXME: empathy_sound_play (EMPATHY_SOUND_CHAT);
+       if (priv->composing_stop_timeout_id) {
+               /* Just restart the timeout */
+               chat_composing_remove_timeout (chat);
+       } else {
+               empathy_tp_chat_set_state (priv->tp_chat,
+                                          TP_CHANNEL_CHAT_STATE_COMPOSING);
        }
 
-       g_signal_emit (chat, signals[NEW_MESSAGE], 0, message, FALSE);
+       priv->composing_stop_timeout_id = g_timeout_add_seconds (
+               COMPOSING_STOP_TIMEOUT,
+               (GSourceFunc) chat_composing_stop_timeout_cb,
+               chat);
 }
 
 static void
-chat_send_error_cb (EmpathyTpChat                 *tp_chat,
-                   EmpathyMessage                *message,
-                   TelepathyChannelTextSendError  error_code,
-                   EmpathyChat                   *chat)
+chat_composing_stop (EmpathyChat *chat)
 {
-       const gchar *error;
-       gchar       *str;
+       EmpathyChatPriv *priv;
 
-       switch (error_code) {
-       case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
-               error = _("offline");
-               break;
-       case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
-               error = _("invalid contact");
-               break;
-       case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
-               error = _("permission denied");
-               break;
-       case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
-               error = _("too long message");
-               break;
-       case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
-               error = _("not implemented");
-               break;
-       default:
-               error = _("unknown");
-               break;
-       }
+       priv = GET_PRIV (chat);
 
-       str = g_strdup_printf (_("Error sending message '%s': %s"),
-                              empathy_message_get_body (message),
-                              error);
-       empathy_chat_view_append_event (chat->view, str);
-       g_free (str);
+       chat_composing_remove_timeout (chat);
+       empathy_tp_chat_set_state (priv->tp_chat,
+                                  TP_CHANNEL_CHAT_STATE_ACTIVE);
 }
 
-void 
+static void 
 chat_sent_message_add (EmpathyChat  *chat,
                       const gchar *str)
 {
@@ -511,7 +321,7 @@ chat_sent_message_add (EmpathyChat  *chat,
        priv->sent_messages_index = -1;
 }
 
-const gchar *
+static const gchar *
 chat_sent_message_get_next (EmpathyChat *chat)
 {
        EmpathyChatPriv *priv;
@@ -520,8 +330,7 @@ chat_sent_message_get_next (EmpathyChat *chat)
        priv = GET_PRIV (chat);
 
        if (!priv->sent_messages) {
-               empathy_debug (DEBUG_DOMAIN, 
-                             "No sent messages, next message is NULL");
+               DEBUG ("No sent messages, next message is NULL");
                return NULL;
        }
 
@@ -531,14 +340,12 @@ chat_sent_message_get_next (EmpathyChat *chat)
                priv->sent_messages_index++;
        }
        
-       empathy_debug (DEBUG_DOMAIN, 
-                     "Returning next message index:%d",
-                     priv->sent_messages_index);
+       DEBUG ("Returning next message index:%d", priv->sent_messages_index);
 
        return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
 }
 
-const gchar *
+static const gchar *
 chat_sent_message_get_last (EmpathyChat *chat)
 {
        EmpathyChatPriv *priv;
@@ -548,8 +355,7 @@ chat_sent_message_get_last (EmpathyChat *chat)
        priv = GET_PRIV (chat);
        
        if (!priv->sent_messages) {
-               empathy_debug (DEBUG_DOMAIN, 
-                             "No sent messages, last message is NULL");
+               DEBUG ("No sent messages, last message is NULL");
                return NULL;
        }
 
@@ -557,108 +363,234 @@ chat_sent_message_get_last (EmpathyChat *chat)
                priv->sent_messages_index--;
        }
 
-       empathy_debug (DEBUG_DOMAIN, 
-                     "Returning last message index:%d",
-                     priv->sent_messages_index);
+       DEBUG ("Returning last message index:%d", priv->sent_messages_index);
 
        return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
 }
 
-static gboolean
-chat_input_key_press_event_cb (GtkWidget   *widget,
-                              GdkEventKey *event,
-                              EmpathyChat  *chat)
+static void
+chat_send (EmpathyChat  *chat,
+          const gchar *msg)
 {
        EmpathyChatPriv *priv;
-       GtkAdjustment  *adj;
-       gdouble         val;
-       GtkWidget      *text_view_sw;
-
-       priv = GET_PRIV (chat);
+       EmpathyMessage  *message;
 
-       if (event->keyval == GDK_Tab && !(event->state & GDK_CONTROL_MASK)) {
-               return TRUE;
+       if (EMP_STR_EMPTY (msg)) {
+               return;
        }
 
-       /* Catch ctrl+up/down so we can traverse messages we sent */
-       if ((event->state & GDK_CONTROL_MASK) && 
-           (event->keyval == GDK_Up || 
-            event->keyval == GDK_Down)) {
-               GtkTextBuffer *buffer;
-               const gchar   *str;
+       priv = GET_PRIV (chat);
 
-               buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
+       chat_sent_message_add (chat, msg);
 
-               if (event->keyval == GDK_Up) {
-                       str = chat_sent_message_get_next (chat);
-               } else {
-                       str = chat_sent_message_get_last (chat);
-               }
-
-               g_signal_handlers_block_by_func (buffer, 
-                                                chat_input_text_buffer_changed_cb,
-                                                chat);
-               gtk_text_buffer_set_text (buffer, str ? str : "", -1);
-               g_signal_handlers_unblock_by_func (buffer, 
-                                                  chat_input_text_buffer_changed_cb,
-                                                  chat);
+       if (g_str_has_prefix (msg, "/clear")) {
+               empathy_chat_view_clear (chat->view);
+               return;
+       }
 
-               return TRUE;    
+       /* Blacklist messages begining by '/', except for "/me" and "/say"
+        * because they are handled in EmpathyMessage */
+       if (msg[0] == '/' &&
+           !g_str_has_prefix (msg, "/me") &&
+           !g_str_has_prefix (msg, "/say")) {
+               empathy_chat_view_append_event (chat->view,
+                       _("Unsupported command"));
+               return;
        }
 
-       /* Catch enter but not ctrl/shift-enter */
-       if (IS_ENTER (event->keyval) && !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
-               GtkTextView *view;
+       /* We can send the message */
+       message = empathy_message_new (msg);
+       empathy_tp_chat_send (priv->tp_chat, message);
+       g_object_unref (message);
+}
 
-               /* This is to make sure that kinput2 gets the enter. And if
-                * it's handled there we shouldn't send on it. This is because
-                * kinput2 uses Enter to commit letters. See:
-                * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=104299
-                */
+static void
+chat_input_text_view_send (EmpathyChat *chat)
+{
+       EmpathyChatPriv *priv;
+       GtkTextBuffer  *buffer;
+       GtkTextIter     start, end;
+       gchar          *msg;
 
-               view = GTK_TEXT_VIEW (chat->input_text_view);
-               if (gtk_im_context_filter_keypress (view->im_context, event)) {
-                       GTK_TEXT_VIEW (chat->input_text_view)->need_im_reset = TRUE;
-                       return TRUE;
-               }
+       priv = GET_PRIV (chat);
 
-               chat_input_text_view_send (chat);
-               return TRUE;
+       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
+
+       gtk_text_buffer_get_bounds (buffer, &start, &end);
+       msg = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+
+       /* clear the input field */
+       gtk_text_buffer_set_text (buffer, "", -1);
+
+       chat_send (chat, msg);
+       g_free (msg);
+}
+
+static void
+chat_state_changed_cb (EmpathyTpChat      *tp_chat,
+                      EmpathyContact     *contact,
+                      TpChannelChatState  state,
+                      EmpathyChat        *chat)
+{
+       EmpathyChatPriv *priv;
+       GList          *l;
+       gboolean        was_composing;
+
+       priv = GET_PRIV (chat);
+
+       if (empathy_contact_is_user (contact)) {
+               /* We don't care about our own chat state */
+               return;
        }
 
-       text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
+       was_composing = (priv->compositors != NULL);
 
-       if (IS_ENTER (event->keyval) && (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
-               /* Newline for shift-enter. */
-               return FALSE;
+       /* Find the contact in the list. After that l is the list elem or NULL */
+       for (l = priv->compositors; l; l = l->next) {
+               if (contact == l->data) {
+                       break;
+               }
        }
-       else if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
-                event->keyval == GDK_Page_Up) {
-               adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
-               gtk_adjustment_set_value (adj, adj->value - adj->page_size);
 
-               return TRUE;
+       switch (state) {
+       case TP_CHANNEL_CHAT_STATE_GONE:
+       case TP_CHANNEL_CHAT_STATE_INACTIVE:
+       case TP_CHANNEL_CHAT_STATE_PAUSED:
+       case TP_CHANNEL_CHAT_STATE_ACTIVE:
+               /* Contact is not composing */
+               if (l) {
+                       priv->compositors = g_list_remove_link (priv->compositors, l);
+                       g_object_unref (l->data);
+                       g_list_free1 (l);
+               }
+               break;
+       case TP_CHANNEL_CHAT_STATE_COMPOSING:
+               /* Contact is composing */
+               if (!l) {
+                       priv->compositors = g_list_prepend (priv->compositors,
+                                                           g_object_ref (contact));
+               }
+               break;
+       default:
+               g_assert_not_reached ();
        }
-       else if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
-                event->keyval == GDK_Page_Down) {
-               adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
-               val = MIN (adj->value + adj->page_size, adj->upper - adj->page_size);
-               gtk_adjustment_set_value (adj, val);
 
-               return TRUE;
+       DEBUG ("Was composing: %s now composing: %s",
+               was_composing ? "yes" : "no",
+               priv->compositors ? "yes" : "no");
+
+       if ((was_composing && !priv->compositors) ||
+           (!was_composing && priv->compositors)) {
+               /* Composing state changed */
+               g_signal_emit (chat, signals[COMPOSING], 0,
+                              priv->compositors != NULL);
        }
+}
 
-       return FALSE;
+static void
+chat_message_received (EmpathyChat *chat, EmpathyMessage *message)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       EmpathyContact  *sender;
+
+       sender = empathy_message_get_sender (message);
+
+       DEBUG ("Appending new message from %s (%d)",
+               empathy_contact_get_name (sender),
+               empathy_contact_get_handle (sender));
+
+       empathy_chat_view_append_message (chat->view, message);
+
+       /* We received a message so the contact is no longer composing */
+       chat_state_changed_cb (priv->tp_chat, sender,
+                              TP_CHANNEL_CHAT_STATE_ACTIVE,
+                              chat);
+
+       g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
 }
 
-static gboolean
-chat_text_view_focus_in_event_cb (GtkWidget  *widget,
-                                 GdkEvent   *event,
-                                 EmpathyChat *chat)
+static void
+chat_message_received_cb (EmpathyTpChat  *tp_chat,
+                         EmpathyMessage *message,
+                         EmpathyChat    *chat)
 {
-       gtk_widget_grab_focus (chat->input_text_view);
+       chat_message_received (chat, message);
+       empathy_tp_chat_acknowledge_message (tp_chat, message);
+}
 
-       return TRUE;
+static void
+chat_send_error_cb (EmpathyTpChat          *tp_chat,
+                   EmpathyMessage         *message,
+                   TpChannelTextSendError  error_code,
+                   EmpathyChat            *chat)
+{
+       const gchar *error;
+       gchar       *str;
+
+       switch (error_code) {
+       case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
+               error = _("offline");
+               break;
+       case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
+               error = _("invalid contact");
+               break;
+       case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
+               error = _("permission denied");
+               break;
+       case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
+               error = _("too long message");
+               break;
+       case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
+               error = _("not implemented");
+               break;
+       default:
+               error = _("unknown");
+               break;
+       }
+
+       str = g_strdup_printf (_("Error sending message '%s': %s"),
+                              empathy_message_get_body (message),
+                              error);
+       empathy_chat_view_append_event (chat->view, str);
+       g_free (str);
+}
+
+static void
+chat_property_changed_cb (EmpathyTpChat *tp_chat,
+                         const gchar   *name,
+                         GValue        *value,
+                         EmpathyChat   *chat)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
+       if (!tp_strdiff (name, "subject")) {
+               g_free (priv->subject);
+               priv->subject = g_value_dup_string (value);
+               g_object_notify (G_OBJECT (chat), "subject");
+
+               if (EMP_STR_EMPTY (priv->subject)) {
+                       gtk_widget_hide (priv->hbox_topic);
+               } else {
+                       gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->subject);
+                       gtk_widget_show (priv->hbox_topic);
+               }
+               if (priv->block_events_timeout_id == 0) {
+                       gchar *str;
+
+                       if (!EMP_STR_EMPTY (priv->subject)) {
+                               str = g_strdup_printf (_("Topic set to: %s"), priv->subject);
+                       } else {
+                               str = g_strdup (_("No topic defined"));
+                       }
+                       empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
+                       g_free (str);
+               }
+       }
+       else if (!tp_strdiff (name, "name")) {
+               g_free (priv->name);
+               priv->name = g_value_dup_string (value);
+               g_object_notify (G_OBJECT (chat), "name");
+       }
 }
 
 static void
@@ -682,28 +614,6 @@ chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
                              EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
                              &spell_checker);
 
-       if (chat->is_first_char) {
-               GtkRequisition  req;
-               gint            window_height;
-               GtkWidget      *dialog;
-               GtkAllocation  *allocation;
-
-               /* Save the window's size */
-               dialog = empathy_chat_window_get_dialog (priv->window);
-               gtk_window_get_size (GTK_WINDOW (dialog),
-                                    NULL, &window_height);
-
-               gtk_widget_size_request (chat->input_text_view, &req);
-
-               allocation = &GTK_WIDGET (chat->view)->allocation;
-
-               priv->default_window_height = window_height;
-               priv->last_input_height = req.height;
-               priv->padding_height = window_height - req.height - allocation->height;
-
-               chat->is_first_char = FALSE;
-       }
-
        gtk_text_buffer_get_start_iter (buffer, &start);
 
        if (!spell_checker) {
@@ -742,8 +652,8 @@ chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
 
                str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
 
-               /* spell check string */
-               if (!empathy_chat_get_is_command (str)) {
+               /* spell check string if not a command */
+               if (str[0] != '/') {
                        correct = empathy_spell_check (str);
                } else {
                        correct = TRUE;
@@ -762,614 +672,978 @@ chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
        }
 }
 
-typedef struct {
-       GtkWidget *window;
-       gint       width;
-       gint       height;
-} ChangeSizeData;
-
 static gboolean
-chat_change_size_in_idle_cb (ChangeSizeData *data)
-{
-       gtk_window_resize (GTK_WINDOW (data->window),
-                          data->width, data->height);
-
-       return FALSE;
-}
-
-static void
-chat_text_view_scroll_hide_cb (GtkWidget  *widget,
+chat_input_key_press_event_cb (GtkWidget   *widget,
+                              GdkEventKey *event,
                               EmpathyChat *chat)
 {
        EmpathyChatPriv *priv;
-       GtkWidget      *sw;
+       GtkAdjustment  *adj;
+       gdouble         val;
+       GtkWidget      *text_view_sw;
 
        priv = GET_PRIV (chat);
 
-       priv->vscroll_visible = FALSE;
-       g_signal_handlers_disconnect_by_func (widget, chat_text_view_scroll_hide_cb, chat);
+       /* Catch ctrl+up/down so we can traverse messages we sent */
+       if ((event->state & GDK_CONTROL_MASK) && 
+           (event->keyval == GDK_Up || 
+            event->keyval == GDK_Down)) {
+               GtkTextBuffer *buffer;
+               const gchar   *str;
 
-       sw = gtk_widget_get_parent (chat->input_text_view);
-       gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
-                                       GTK_POLICY_NEVER,
-                                       GTK_POLICY_NEVER);
-       g_object_set (sw, "height-request", -1, NULL);
-}
+               buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
 
-static void
-chat_text_view_size_allocate_cb (GtkWidget     *widget,
-                                GtkAllocation *allocation,
-                                EmpathyChat    *chat)
-{
-       EmpathyChatPriv *priv;
-       gint            width;
-       GtkWidget      *dialog;
-       ChangeSizeData *data;
-       gint            window_height;
-       gint            new_height;
-       GtkAllocation  *view_allocation;
-       gint            current_height;
-       gint            diff;
-       GtkWidget      *sw;
+               if (event->keyval == GDK_Up) {
+                       str = chat_sent_message_get_next (chat);
+               } else {
+                       str = chat_sent_message_get_last (chat);
+               }
 
-       priv = GET_PRIV (chat);
+               g_signal_handlers_block_by_func (buffer, 
+                                                chat_input_text_buffer_changed_cb,
+                                                chat);
+               gtk_text_buffer_set_text (buffer, str ? str : "", -1);
+               g_signal_handlers_unblock_by_func (buffer, 
+                                                  chat_input_text_buffer_changed_cb,
+                                                  chat);
 
-       if (priv->default_window_height <= 0) {
-               return;
+               return TRUE;    
        }
 
-       sw = gtk_widget_get_parent (widget);
-       if (sw->allocation.height >= MAX_INPUT_HEIGHT && !priv->vscroll_visible) {
-               GtkWidget *vscroll;
+       /* Catch enter but not ctrl/shift-enter */
+       if (IS_ENTER (event->keyval) &&
+           !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
+               GtkTextView *view;
 
-               priv->vscroll_visible = TRUE;
-               gtk_widget_set_size_request (sw, sw->allocation.width, MAX_INPUT_HEIGHT);
-               gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
-                                               GTK_POLICY_NEVER,
-                                               GTK_POLICY_AUTOMATIC);
-               vscroll = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (sw));
-               g_signal_connect (vscroll, "hide",
-                                 G_CALLBACK (chat_text_view_scroll_hide_cb),
-                                 chat);
+               /* This is to make sure that kinput2 gets the enter. And if
+                * it's handled there we shouldn't send on it. This is because
+                * kinput2 uses Enter to commit letters. See:
+                * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=104299
+                */
+
+               view = GTK_TEXT_VIEW (chat->input_text_view);
+               if (gtk_im_context_filter_keypress (view->im_context, event)) {
+                       GTK_TEXT_VIEW (chat->input_text_view)->need_im_reset = TRUE;
+                       return TRUE;
+               }
+
+               chat_input_text_view_send (chat);
+               return TRUE;
        }
 
-       if (priv->last_input_height <= allocation->height) {
-               priv->last_input_height = allocation->height;
-               return;
+       text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
+
+       if (IS_ENTER (event->keyval) &&
+           (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
+               /* Newline for shift/control-enter. */
+               return FALSE;
+       }
+       if (!(event->state & GDK_CONTROL_MASK) &&
+           event->keyval == GDK_Page_Up) {
+               adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
+               gtk_adjustment_set_value (adj, adj->value - adj->page_size);
+               return TRUE;
+       }
+       if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
+           event->keyval == GDK_Page_Down) {
+               adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
+               val = MIN (adj->value + adj->page_size, adj->upper - adj->page_size);
+               gtk_adjustment_set_value (adj, val);
+               return TRUE;
        }
+       if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
+           event->keyval == GDK_Tab) {
+               GtkTextBuffer *buffer;
+               GtkTextIter    start, current;
+               gchar         *nick, *completed;
+               GList         *list, *completed_list;
+               gboolean       is_start_of_buffer;
+
+               buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (EMPATHY_CHAT (chat)->input_text_view));
+               gtk_text_buffer_get_iter_at_mark (buffer, &current, gtk_text_buffer_get_insert (buffer));
+
+               /* 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);
+               is_start_of_buffer = gtk_text_iter_is_start (&start);
+
+               list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
+               g_completion_add_items (priv->completion, list);
+
+               nick = gtk_text_buffer_get_text (buffer, &start, &current, FALSE);
+               completed_list = g_completion_complete (priv->completion,
+                                                       nick,
+                                                       &completed);
+
+               g_free (nick);
+
+               if (completed) {
+                       guint        len;
+                       const gchar *text;
+                       gchar       *complete_char = NULL;
+
+                       gtk_text_buffer_delete (buffer, &start, &current);
+
+                       len = g_list_length (completed_list);
+
+                       if (len == 1) {
+                               /* If we only have one hit, use that text
+                                * instead of the text in completed since the
+                                * completed text will use the typed string
+                                * which might be cased all wrong.
+                                * Fixes #120876
+                                * */
+                               text = empathy_contact_get_name (completed_list->data);
+                       } else {
+                               text = completed;
+                       }
 
-       diff = priv->last_input_height - allocation->height;
-       priv->last_input_height = allocation->height;
+                       gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
+
+                       if (len == 1 && is_start_of_buffer &&
+                           empathy_conf_get_string (empathy_conf_get (),
+                                                    EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR,
+                                                    &complete_char) &&
+                           complete_char != NULL) {
+                               gtk_text_buffer_insert_at_cursor (buffer,
+                                                                 complete_char,
+                                                                 strlen (complete_char));
+                               gtk_text_buffer_insert_at_cursor (buffer, " ", 1);
+                               g_free (complete_char);
+                       }
 
-       view_allocation = &GTK_WIDGET (chat->view)->allocation;
+                       g_free (completed);
+               }
 
-       dialog = empathy_chat_window_get_dialog (priv->window);
-       gtk_window_get_size (GTK_WINDOW (dialog), NULL, &current_height);
+               g_completion_clear_items (priv->completion);
 
-       new_height = view_allocation->height + priv->padding_height + allocation->height - diff;
+               g_list_foreach (list, (GFunc) g_object_unref, NULL);
+               g_list_free (list);
 
-       if (new_height <= priv->default_window_height) {
-               window_height = priv->default_window_height;
-       } else {
-               window_height = new_height;
+               return TRUE;
        }
 
-       if (current_height <= window_height) {
-               return;
-       }
+       return FALSE;
+}
+
+static gboolean
+chat_text_view_focus_in_event_cb (GtkWidget  *widget,
+                                 GdkEvent   *event,
+                                 EmpathyChat *chat)
+{
+       gtk_widget_grab_focus (chat->input_text_view);
+
+       return TRUE;
+}
+
+static gboolean
+chat_input_set_size_request_idle (gpointer sw)
+{
+       gtk_widget_set_size_request (sw, -1, MAX_INPUT_HEIGHT);
+
+       return FALSE;
+}
 
-       /* Restore the window's size */
-       gtk_window_get_size (GTK_WINDOW (dialog), &width, NULL);
+static void
+chat_input_size_request_cb (GtkWidget      *widget,
+                           GtkRequisition *requisition,
+                           EmpathyChat    *chat)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       GtkWidget       *sw;
 
-       data = g_new0 (ChangeSizeData, 1);
-       data->window = dialog;
-       data->width  = width;
-       data->height = window_height;
+       sw = gtk_widget_get_parent (widget);
+       if (requisition->height >= MAX_INPUT_HEIGHT && !priv->has_input_vscroll) {
+               g_idle_add (chat_input_set_size_request_idle, sw);
+               gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+                                               GTK_POLICY_NEVER,
+                                               GTK_POLICY_ALWAYS);
+               priv->has_input_vscroll = TRUE;
+       }
 
-       g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
-                        (GSourceFunc) chat_change_size_in_idle_cb,
-                        data, g_free);
+       if (requisition->height < MAX_INPUT_HEIGHT && priv->has_input_vscroll) {
+               gtk_widget_set_size_request (sw, -1, -1);
+               gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+                                               GTK_POLICY_NEVER,
+                                               GTK_POLICY_NEVER);
+               priv->has_input_vscroll = FALSE;
+       }
 }
 
 static void
-chat_text_view_realize_cb (GtkWidget  *widget,
-                          EmpathyChat *chat)
+chat_input_realize_cb (GtkWidget   *widget,
+                      EmpathyChat *chat)
 {
-       empathy_debug (DEBUG_DOMAIN, "Setting focus to the input text view");
+       DEBUG ("Setting focus to the input text view");
        gtk_widget_grab_focus (widget);
 }
 
 static void
-chat_insert_smiley_activate_cb (GtkWidget   *menuitem,
-                               EmpathyChat *chat)
+chat_insert_smiley_activate_cb (EmpathySmileyManager *manager,
+                               EmpathySmiley        *smiley,
+                               gpointer              user_data)
 {
+       EmpathyChat   *chat = EMPATHY_CHAT (user_data);
        GtkTextBuffer *buffer;
        GtkTextIter    iter;
-       const gchar   *smiley;
-
-       smiley = g_object_get_data (G_OBJECT (menuitem), "smiley_text");
 
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
 
        gtk_text_buffer_get_end_iter (buffer, &iter);
-       gtk_text_buffer_insert (buffer, &iter, smiley, -1);
+       gtk_text_buffer_insert (buffer, &iter, smiley->str, -1);
 
        gtk_text_buffer_get_end_iter (buffer, &iter);
        gtk_text_buffer_insert (buffer, &iter, " ", -1);
 }
 
-static void
-chat_text_populate_popup_cb (GtkTextView *view,
-                            GtkMenu     *menu,
-                            EmpathyChat  *chat)
+typedef struct {
+       EmpathyChat  *chat;
+       gchar       *word;
+
+       GtkTextIter  start;
+       GtkTextIter  end;
+} EmpathyChatSpell;
+
+static EmpathyChatSpell *
+chat_spell_new (EmpathyChat  *chat,
+               const gchar *word,
+               GtkTextIter  start,
+               GtkTextIter  end)
 {
-       EmpathyChatPriv  *priv;
-       GtkTextBuffer   *buffer;
-       GtkTextTagTable *table;
-       GtkTextTag      *tag;
-       gint             x, y;
-       GtkTextIter      iter, start, end;
-       GtkWidget       *item;
-       gchar           *str = NULL;
        EmpathyChatSpell *chat_spell;
-       GtkWidget       *smiley_menu;
+
+       chat_spell = g_slice_new0 (EmpathyChatSpell);
+
+       chat_spell->chat = g_object_ref (chat);
+       chat_spell->word = g_strdup (word);
+       chat_spell->start = start;
+       chat_spell->end = end;
+
+       return chat_spell;
+}
+
+static void
+chat_spell_free (EmpathyChatSpell *chat_spell)
+{
+       g_object_unref (chat_spell->chat);
+       g_free (chat_spell->word);
+       g_slice_free (EmpathyChatSpell, chat_spell);
+}
+
+static void
+chat_text_check_word_spelling_cb (GtkMenuItem     *menuitem,
+                                 EmpathyChatSpell *chat_spell)
+{
+       empathy_spell_dialog_show (chat_spell->chat,
+                                 &chat_spell->start,
+                                 &chat_spell->end,
+                                 chat_spell->word);
+}
+
+static void
+chat_text_send_cb (GtkMenuItem *menuitem,
+                  EmpathyChat *chat)
+{
+       chat_input_text_view_send (chat);
+}
+
+static void
+chat_input_populate_popup_cb (GtkTextView *view,
+                             GtkMenu     *menu,
+                             EmpathyChat *chat)
+{
+       EmpathyChatPriv      *priv;
+       GtkTextBuffer        *buffer;
+       GtkTextTagTable      *table;
+       GtkTextTag           *tag;
+       gint                  x, y;
+       GtkTextIter           iter, start, end;
+       GtkWidget            *item;
+       gchar                *str = NULL;
+       EmpathyChatSpell      *chat_spell;
+       EmpathySmileyManager *smiley_manager;
+       GtkWidget            *smiley_menu;
+       GtkWidget            *image;
 
        priv = GET_PRIV (chat);
+       buffer = gtk_text_view_get_buffer (view);
 
        /* Add the emoticon menu. */
        item = gtk_separator_menu_item_new ();
        gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
        gtk_widget_show (item);
 
-       item = gtk_menu_item_new_with_mnemonic (_("Insert Smiley"));
+       item = gtk_image_menu_item_new_with_mnemonic (_("Insert Smiley"));
+       image = gtk_image_new_from_icon_name ("face-smile",
+                                             GTK_ICON_SIZE_MENU);
+       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
        gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
        gtk_widget_show (item);
 
-       smiley_menu = empathy_chat_view_get_smiley_menu (
-               G_CALLBACK (chat_insert_smiley_activate_cb),
-               chat,
-               priv->tooltips);
+       smiley_manager = empathy_smiley_manager_dup_singleton ();
+       smiley_menu = empathy_smiley_menu_new (smiley_manager,
+                                              chat_insert_smiley_activate_cb,
+                                              chat);
        gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), smiley_menu);
+       g_object_unref (smiley_manager);
+
+       /* Add the Send menu item. */
+       gtk_text_buffer_get_bounds (buffer, &start, &end);
+       str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+       if (!EMP_STR_EMPTY (str)) {
+               item = gtk_menu_item_new_with_mnemonic (_("_Send"));
+               g_signal_connect (G_OBJECT (item), "activate",
+                                 G_CALLBACK (chat_text_send_cb), chat);
+               gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
+               gtk_widget_show (item);
+       }
+       str = NULL;
 
        /* Add the spell check menu item. */
-       buffer = gtk_text_view_get_buffer (view);
        table = gtk_text_buffer_get_tag_table (buffer);
-
        tag = gtk_text_tag_table_lookup (table, "misspelled");
-
        gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
-
        gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
                                               GTK_TEXT_WINDOW_WIDGET,
                                               x, y,
                                               &x, &y);
-
        gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
-
        start = end = iter;
-
        if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
            gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
 
                str = gtk_text_buffer_get_text (buffer,
                                                &start, &end, FALSE);
        }
-
-       if (G_STR_EMPTY (str)) {
-               return;
+       if (!EMP_STR_EMPTY (str)) {
+               chat_spell = chat_spell_new (chat, str, start, end);
+               g_object_set_data_full (G_OBJECT (menu),
+                                       "chat_spell", chat_spell,
+                                       (GDestroyNotify) chat_spell_free);
+
+               item = gtk_separator_menu_item_new ();
+               gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
+               gtk_widget_show (item);
+
+               item = gtk_image_menu_item_new_with_mnemonic (_("_Check Word Spelling..."));
+               image = gtk_image_new_from_icon_name (GTK_STOCK_SPELL_CHECK,
+                                                     GTK_ICON_SIZE_MENU);
+               gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+               g_signal_connect (item,
+                                 "activate",
+                                 G_CALLBACK (chat_text_check_word_spelling_cb),
+                                 chat_spell);
+               gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
+               gtk_widget_show (item);
        }
+}
 
-       chat_spell = chat_spell_new (chat, str, start, end);
+static gboolean
+chat_log_filter (EmpathyMessage *message,
+                gpointer user_data)
+{
+       EmpathyChat *chat = (EmpathyChat *) user_data;
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       const GList *pending;
 
-       g_object_set_data_full (G_OBJECT (menu),
-                               "chat_spell", chat_spell,
-                               (GDestroyNotify) chat_spell_free);
+       pending = empathy_tp_chat_get_pending_messages (priv->tp_chat);
 
-       item = gtk_separator_menu_item_new ();
-       gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
-       gtk_widget_show (item);
+       for (; pending; pending = g_list_next (pending)) {
+               if (empathy_message_equal (message, pending->data)) {
+                       return FALSE;
+               }
+       }
 
-       item = gtk_menu_item_new_with_mnemonic (_("_Check Word Spelling..."));
-       g_signal_connect (item,
-                         "activate",
-                         G_CALLBACK (chat_text_check_word_spelling_cb),
-                         chat_spell);
-       gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
-       gtk_widget_show (item);
+       return TRUE;
 }
 
 static void
-chat_text_check_word_spelling_cb (GtkMenuItem     *menuitem,
-                                 EmpathyChatSpell *chat_spell)
+chat_add_logs (EmpathyChat *chat)
 {
-       empathy_spell_dialog_show (chat_spell->chat,
-                                 chat_spell->start,
-                                 chat_spell->end,
-                                 chat_spell->word);
-}
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       gboolean         is_chatroom;
+       GList           *messages, *l;
 
-static EmpathyChatSpell *
-chat_spell_new (EmpathyChat  *chat,
-               const gchar *word,
-               GtkTextIter  start,
-               GtkTextIter  end)
-{
-       EmpathyChatSpell *chat_spell;
+       if (!priv->id) {
+               return;
+       }
 
-       chat_spell = g_new0 (EmpathyChatSpell, 1);
+       /* Turn off scrolling temporarily */
+       empathy_chat_view_scroll (chat->view, FALSE);
 
-       chat_spell->chat = g_object_ref (chat);
-       chat_spell->word = g_strdup (word);
-       chat_spell->start = start;
-       chat_spell->end = end;
+       /* Add messages from last conversation */
+       is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
+
+       messages = empathy_log_manager_get_filtered_messages (priv->log_manager,
+                                                             priv->account,
+                                                             priv->id,
+                                                             is_chatroom,
+                                                             5,
+                                                             chat_log_filter,
+                                                             chat);
+
+       for (l = messages; l; l = g_list_next (l)) {
+               empathy_chat_view_append_message (chat->view, l->data);
+               g_object_unref (l->data);
+       }
 
-       return chat_spell;
-}
+       g_list_free (messages);
 
-static void
-chat_spell_free (EmpathyChatSpell *chat_spell)
-{
-       g_object_unref (chat_spell->chat);
-       g_free (chat_spell->word);
-       g_free (chat_spell);
+       /* Turn back on scrolling */
+       empathy_chat_view_scroll (chat->view, TRUE);
 }
 
-static void
-chat_composing_start (EmpathyChat *chat)
+static gint
+chat_contacts_completion_func (const gchar *s1,
+                              const gchar *s2,
+                              gsize        n)
 {
-       EmpathyChatPriv *priv;
+       gchar *tmp, *nick1, *nick2;
+       gint   ret;
 
-       priv = GET_PRIV (chat);
-
-       if (priv->composing_stop_timeout_id) {
-               /* Just restart the timeout */
-               chat_composing_remove_timeout (chat);
-       } else {
-               empathy_tp_chat_set_state (priv->tp_chat,
-                                          TP_CHANNEL_CHAT_STATE_COMPOSING);
+       if (s1 == s2) {
+               return 0;
+       }
+       if (!s1 || !s2) {
+               return s1 ? -1 : +1;
        }
 
-       priv->composing_stop_timeout_id = g_timeout_add (
-               1000 * COMPOSING_STOP_TIMEOUT,
-               (GSourceFunc) chat_composing_stop_timeout_cb,
-               chat);
-}
+       tmp = g_utf8_normalize (s1, -1, G_NORMALIZE_DEFAULT);
+       nick1 = g_utf8_casefold (tmp, -1);
+       g_free (tmp);
 
-static void
-chat_composing_stop (EmpathyChat *chat)
-{
-       EmpathyChatPriv *priv;
+       tmp = g_utf8_normalize (s2, -1, G_NORMALIZE_DEFAULT);
+       nick2 = g_utf8_casefold (tmp, -1);
+       g_free (tmp);
 
-       priv = GET_PRIV (chat);
+       ret = strncmp (nick1, nick2, n);
 
-       chat_composing_remove_timeout (chat);
-       empathy_tp_chat_set_state (priv->tp_chat,
-                                  TP_CHANNEL_CHAT_STATE_ACTIVE);
+       g_free (nick1);
+       g_free (nick2);
+
+       return ret;
 }
 
 static void
-chat_composing_remove_timeout (EmpathyChat *chat)
+chat_members_changed_cb (EmpathyTpChat  *tp_chat,
+                        EmpathyContact *contact,
+                        EmpathyContact *actor,
+                        guint           reason,
+                        gchar          *message,
+                        gboolean        is_member,
+                        EmpathyChat    *chat)
 {
-       EmpathyChatPriv *priv;
+       EmpathyChatPriv *priv = GET_PRIV (chat);
 
-       priv = GET_PRIV (chat);
+       if (priv->block_events_timeout_id == 0) {
+               gchar *str;
 
-       if (priv->composing_stop_timeout_id) {
-               g_source_remove (priv->composing_stop_timeout_id);
-               priv->composing_stop_timeout_id = 0;
+               if (is_member) {
+                       str = g_strdup_printf (_("%s has joined the room"),
+                                              empathy_contact_get_name (contact));
+               } else {
+                       str = g_strdup_printf (_("%s has left the room"),
+                                              empathy_contact_get_name (contact));
+               }
+               empathy_chat_view_append_event (chat->view, str);
+               g_free (str);
        }
 }
 
 static gboolean
-chat_composing_stop_timeout_cb (EmpathyChat *chat)
+chat_reset_size_request (gpointer widget)
 {
-       EmpathyChatPriv *priv;
-
-       priv = GET_PRIV (chat);
-
-       priv->composing_stop_timeout_id = 0;
-       empathy_tp_chat_set_state (priv->tp_chat,
-                                  TP_CHANNEL_CHAT_STATE_PAUSED);
+       gtk_widget_set_size_request (widget, -1, -1);
 
        return FALSE;
 }
 
 static void
-chat_state_changed_cb (EmpathyTpChat             *tp_chat,
-                      EmpathyContact             *contact,
-                      TelepathyChannelChatState  state,
-                      EmpathyChat                *chat)
+chat_set_show_contacts (EmpathyChat *chat, gboolean show)
 {
-       EmpathyChatPriv *priv;
-       GList          *l;
-       gboolean        was_composing;
-
-       priv = GET_PRIV (chat);
+       EmpathyChatPriv *priv = GET_PRIV (chat);
 
-       if (empathy_contact_is_user (contact)) {
-               /* We don't care about our own chat state */
+       if (!priv->scrolled_window_contacts) {
                return;
        }
 
-       was_composing = (priv->compositors != NULL);
+       if (show) {
+               EmpathyContactListStore *store;
+               gint                     min_width;
 
-       /* Find the contact in the list. After that l is the list elem or NULL */
-       for (l = priv->compositors; l; l = l->next) {
-               if (empathy_contact_equal (contact, l->data)) {
-                       break;
-               }
-       }
+               /* We are adding the contact list to the chat, we don't want the
+                * chat view to become too small. If the chat view is already
+                * smaller than 250 make sure that size won't change. If the
+                * chat view is bigger the contact list will take some space on
+                * it but we make sure the chat view don't become smaller than
+                * 250. Relax the size request once the resize is done */
+               min_width = MIN (priv->vbox_left->allocation.width, 250);
+               gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
+               g_idle_add (chat_reset_size_request, priv->vbox_left);
 
-       switch (state) {
-       case TP_CHANNEL_CHAT_STATE_GONE:
-       case TP_CHANNEL_CHAT_STATE_INACTIVE:
-       case TP_CHANNEL_CHAT_STATE_ACTIVE:
-               /* Contact is not composing */
-               if (l) {
-                       priv->compositors = g_list_remove_link (priv->compositors, l);
-                       g_object_unref (l->data);
-                       g_list_free1 (l);
+               if (priv->contacts_width > 0) {
+                       gtk_paned_set_position (GTK_PANED (priv->hpaned),
+                                               priv->contacts_width);
                }
-               break;
-       case TP_CHANNEL_CHAT_STATE_PAUSED:
-       case TP_CHANNEL_CHAT_STATE_COMPOSING:
-               /* Contact is composing */
-               if (!l) {
-                       priv->compositors = g_list_prepend (priv->compositors,
-                                                           g_object_ref (contact));
+
+               store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
+               priv->contact_list_view = GTK_WIDGET (empathy_contact_list_view_new (store,
+                       EMPATHY_CONTACT_LIST_FEATURE_NONE,
+                       EMPATHY_CONTACT_FEATURE_CHAT |
+                       EMPATHY_CONTACT_FEATURE_CALL |
+                       EMPATHY_CONTACT_FEATURE_LOG |
+                       EMPATHY_CONTACT_FEATURE_INFO));
+               gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
+                                  priv->contact_list_view);
+               gtk_widget_show (priv->contact_list_view);
+               gtk_widget_show (priv->scrolled_window_contacts);
+               g_object_unref (store);
+       } else {
+               priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
+               gtk_widget_hide (priv->scrolled_window_contacts);
+               if (priv->contact_list_view) {
+                       gtk_widget_destroy (priv->contact_list_view);
+                       priv->contact_list_view = NULL;
                }
-               break;
-       default:
-               g_assert_not_reached ();
        }
+}
+
+static void
+chat_remote_contact_changed_cb (EmpathyChat *chat)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
 
-       empathy_debug (DEBUG_DOMAIN, "Was composing: %s now composing: %s",
-                     was_composing ? "yes" : "no",
-                     priv->compositors ? "yes" : "no");
+       if (priv->remote_contact) {
+               g_object_unref (priv->remote_contact);
+               priv->remote_contact = NULL;
+       }
 
-       if ((was_composing && !priv->compositors) ||
-           (!was_composing && priv->compositors)) {
-               /* Composing state changed */
-               g_signal_emit (chat, signals[COMPOSING], 0,
-                              priv->compositors != NULL);
+       priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
+       if (priv->remote_contact) {
+               g_object_ref (priv->remote_contact);
+               priv->handle_type = TP_HANDLE_TYPE_CONTACT;
+               g_free (priv->id);
+               priv->id = g_strdup (empathy_contact_get_id (priv->remote_contact));
        }
+       else if (priv->tp_chat) {
+               TpChannel *channel;
+
+               channel = empathy_tp_chat_get_channel (priv->tp_chat);
+               g_object_get (channel, "handle-type", &priv->handle_type, NULL);
+               g_free (priv->id);
+               priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
+       }
+
+       chat_set_show_contacts (chat, priv->remote_contact == NULL);
+
+       g_object_notify (G_OBJECT (chat), "remote-contact");
+       g_object_notify (G_OBJECT (chat), "id");
 }
 
 static void
-chat_add_logs (EmpathyChat *chat)
+chat_destroy_cb (EmpathyTpChat *tp_chat,
+                EmpathyChat   *chat)
 {
        EmpathyChatPriv *priv;
-       GList          *messages, *l;
-       guint           num_messages;
-       guint           i;
 
        priv = GET_PRIV (chat);
 
-       /* Turn off scrolling temporarily */
-       empathy_chat_view_scroll (chat->view, FALSE);
+       if (!priv->tp_chat) {
+               return;
+       }
 
-       /* Add messages from last conversation */
-       messages = empathy_log_manager_get_last_messages (priv->log_manager,
-                                                         chat->account,
-                                                         empathy_chat_get_id (chat),
-                                                         empathy_chat_is_group_chat (chat));
-       num_messages  = g_list_length (messages);
+       chat_composing_remove_timeout (chat);
+       g_object_unref (priv->tp_chat);
+       priv->tp_chat = NULL;
+       g_object_notify (G_OBJECT (chat), "tp-chat");
 
-       for (l = messages, i = 0; l; l = l->next, i++) {
-               EmpathyMessage *message;
+       empathy_chat_view_append_event (chat->view, _("Disconnected"));
+       gtk_widget_set_sensitive (chat->input_text_view, FALSE);
+       chat_set_show_contacts (chat, FALSE);
+}
 
-               message = l->data;
+static void
+show_pending_messages (EmpathyChat *chat) {
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       const GList *messages, *l;
 
-               /* Only add 10 last messages */
-               if (num_messages - i > 10) {
-                       g_object_unref (message);
-                       continue;
-               }
+       if (chat->view == NULL || priv->tp_chat == NULL)
+               return;
 
-               priv->last_log_timestamp = empathy_message_get_timestamp (message);
-               empathy_chat_view_append_message (chat->view, message);
+       messages = empathy_tp_chat_get_pending_messages (priv->tp_chat);
 
-               g_object_unref (message);
+       for (l = messages; l != NULL ; l = g_list_next (l)) {
+               EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
+               chat_message_received (chat, message);
        }
-       g_list_free (messages);
+       empathy_tp_chat_acknowledge_messages (priv->tp_chat, messages);
+}
 
-       /* Turn back on scrolling */
-       empathy_chat_view_scroll (chat->view, TRUE);
+static void
+chat_create_ui (EmpathyChat *chat)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       GtkBuilder      *gui;
+       GList           *list = NULL; 
+       gchar           *filename;
+       GtkTextBuffer   *buffer;
 
-       /* Scroll to the most recent messages, we reference the chat
-        * for the duration of the scroll func.
-        */
-       priv->scroll_idle_id = g_idle_add ((GSourceFunc) chat_scroll_down_idle_func, 
-                                          g_object_ref (chat));
+       filename = empathy_file_lookup ("empathy-chat.ui",
+                                       "libempathy-gtk");
+       gui = empathy_builder_get_file (filename,
+                                       "chat_widget", &priv->widget,
+                                       "hpaned", &priv->hpaned,
+                                       "vbox_left", &priv->vbox_left,
+                                       "scrolled_window_chat", &priv->scrolled_window_chat,
+                                       "scrolled_window_input", &priv->scrolled_window_input,
+                                       "hbox_topic", &priv->hbox_topic,
+                                       "label_topic", &priv->label_topic,
+                                       "scrolled_window_contacts", &priv->scrolled_window_contacts,
+                                       NULL);
+       g_free (filename);
+
+       /* Add message view. */
+       chat->view = empathy_theme_manager_create_view (empathy_theme_manager_get ());
+       g_signal_connect (chat->view, "focus_in_event",
+                         G_CALLBACK (chat_text_view_focus_in_event_cb),
+                         chat);
+       gtk_container_add (GTK_CONTAINER (priv->scrolled_window_chat),
+                          GTK_WIDGET (chat->view));
+       gtk_widget_show (GTK_WIDGET (chat->view));
+
+       /* Add input GtkTextView */
+       chat->input_text_view = g_object_new (GTK_TYPE_TEXT_VIEW,
+                                             "pixels-above-lines", 2,
+                                             "pixels-below-lines", 2,
+                                             "pixels-inside-wrap", 1,
+                                             "right-margin", 2,
+                                             "left-margin", 2,
+                                             "wrap-mode", GTK_WRAP_WORD_CHAR,
+                                             NULL);
+       g_signal_connect (chat->input_text_view, "key-press-event",
+                         G_CALLBACK (chat_input_key_press_event_cb),
+                         chat);
+       g_signal_connect (chat->input_text_view, "size-request",
+                         G_CALLBACK (chat_input_size_request_cb),
+                         chat);
+       g_signal_connect (chat->input_text_view, "realize",
+                         G_CALLBACK (chat_input_realize_cb),
+                         chat);
+       g_signal_connect (chat->input_text_view, "populate-popup",
+                         G_CALLBACK (chat_input_populate_popup_cb),
+                         chat);
+       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
+       g_signal_connect (buffer, "changed",
+                         G_CALLBACK (chat_input_text_buffer_changed_cb),
+                         chat);
+       gtk_text_buffer_create_tag (buffer, "misspelled",
+                                   "underline", PANGO_UNDERLINE_ERROR,
+                                   NULL);
+       gtk_container_add (GTK_CONTAINER (priv->scrolled_window_input),
+                          chat->input_text_view);
+       gtk_widget_show (chat->input_text_view);
+
+       /* Create contact list */
+       chat_set_show_contacts (chat, priv->remote_contact == NULL);
+
+       /* Initialy hide the topic, will be shown if not empty */
+       gtk_widget_hide (priv->hbox_topic);
+
+       /* Set widget focus order */
+       list = g_list_append (NULL, priv->scrolled_window_input);
+       gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
+       g_list_free (list);
+
+       list = g_list_append (NULL, priv->vbox_left);
+       list = g_list_append (list, priv->scrolled_window_contacts);
+       gtk_container_set_focus_chain (GTK_CONTAINER (priv->hpaned), list);
+       g_list_free (list);
+
+       list = g_list_append (NULL, priv->hpaned);
+       list = g_list_append (list, priv->hbox_topic);
+       gtk_container_set_focus_chain (GTK_CONTAINER (priv->widget), list);
+       g_list_free (list);
+
+       /* Add the main widget in the chat widget */
+       gtk_container_add (GTK_CONTAINER (chat), priv->widget);
+       g_object_unref (gui);
 }
 
-/* Scroll down after the back-log has been received. */
-static gboolean
-chat_scroll_down_idle_func (EmpathyChat *chat)
+static void
+chat_size_request (GtkWidget      *widget,
+                  GtkRequisition *requisition)
 {
-       EmpathyChatPriv *priv;
+  GtkBin *bin = GTK_BIN (widget);
 
-       priv = GET_PRIV (chat);
+  requisition->width = GTK_CONTAINER (widget)->border_width * 2;
+  requisition->height = GTK_CONTAINER (widget)->border_width * 2;
 
-       empathy_chat_scroll_down (chat);
-       g_object_unref (chat);
+  if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+    {
+      GtkRequisition child_requisition;
+      
+      gtk_widget_size_request (bin->child, &child_requisition);
 
-       priv->scroll_idle_id = 0;
+      requisition->width += child_requisition.width;
+      requisition->height += child_requisition.height;
+    }
+}
 
-       return FALSE;
+static void
+chat_size_allocate (GtkWidget     *widget,
+                   GtkAllocation *allocation)
+{
+  GtkBin *bin = GTK_BIN (widget);
+  GtkAllocation child_allocation;
+  
+  widget->allocation = *allocation;
+
+  if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+    {
+      child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
+      child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width;
+      child_allocation.width = MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0);
+      child_allocation.height = MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0);
+
+      gtk_widget_size_allocate (bin->child, &child_allocation);
+    }
 }
 
-gboolean
-empathy_chat_get_is_command (const gchar *str)
+static void
+chat_finalize (GObject *object)
 {
-       g_return_val_if_fail (str != NULL, FALSE);
+       EmpathyChat     *chat;
+       EmpathyChatPriv *priv;
 
-       if (str[0] != '/') {
-               return FALSE;
-       }
+       chat = EMPATHY_CHAT (object);
+       priv = GET_PRIV (chat);
 
-       if (g_str_has_prefix (str, "/me")) {
-               return TRUE;
-       }
-       else if (g_str_has_prefix (str, "/nick")) {
-               return TRUE;
-       }
-       else if (g_str_has_prefix (str, "/topic")) {
-               return TRUE;
-       }
+       DEBUG ("Finalized: %p", object);
 
-       return FALSE;
-}
+       g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
+       g_slist_free (priv->sent_messages);
 
-void
-empathy_chat_correct_word (EmpathyChat  *chat,
-                         GtkTextIter  start,
-                         GtkTextIter  end,
-                         const gchar *new_word)
-{
-       GtkTextBuffer *buffer;
+       g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
+       g_list_free (priv->compositors);
 
-       g_return_if_fail (chat != NULL);
-       g_return_if_fail (new_word != NULL);
+       chat_composing_remove_timeout (chat);
 
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
+       g_signal_handlers_disconnect_by_func (priv->account_manager,
+                                             chat_new_connection_cb, object);
 
-       gtk_text_buffer_delete (buffer, &start, &end);
-       gtk_text_buffer_insert (buffer, &start,
-                               new_word,
-                               -1);
-}
+       g_object_unref (priv->account_manager);
+       g_object_unref (priv->log_manager);
 
-const gchar *
-empathy_chat_get_name (EmpathyChat *chat)
-{
-       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+       if (priv->tp_chat) {
+               g_signal_handlers_disconnect_by_func (priv->tp_chat,
+                       chat_destroy_cb, chat);
+               g_signal_handlers_disconnect_by_func (priv->tp_chat,
+                       chat_message_received_cb, chat);
+               g_signal_handlers_disconnect_by_func (priv->tp_chat,
+                       chat_send_error_cb, chat);
+               g_signal_handlers_disconnect_by_func (priv->tp_chat,
+                       chat_state_changed_cb, chat);
+               g_signal_handlers_disconnect_by_func (priv->tp_chat,
+                       chat_property_changed_cb, chat);
+               g_signal_handlers_disconnect_by_func (priv->tp_chat,
+                       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);
+               g_object_unref (priv->tp_chat);
+       }
+       if (priv->account) {
+               g_object_unref (priv->account);
+       }
+       if (priv->remote_contact) {
+               g_object_unref (priv->remote_contact);
+       }
 
-       if (EMPATHY_CHAT_GET_CLASS (chat)->get_name) {
-               return EMPATHY_CHAT_GET_CLASS (chat)->get_name (chat);
+       if (priv->block_events_timeout_id) {
+               g_source_remove (priv->block_events_timeout_id);
        }
 
-       return NULL;
+       g_free (priv->id);
+       g_free (priv->name);
+       g_free (priv->subject);
+       g_completion_free (priv->completion);
+
+       G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
 }
 
-gchar *
-empathy_chat_get_tooltip (EmpathyChat *chat)
+static void
+chat_constructed (GObject *object)
 {
-       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
-
-       if (EMPATHY_CHAT_GET_CLASS (chat)->get_tooltip) {
-               return EMPATHY_CHAT_GET_CLASS (chat)->get_tooltip (chat);
-       }
+       EmpathyChat *chat = EMPATHY_CHAT (object);
 
-       return NULL;
+       chat_create_ui (chat);
+       chat_add_logs (chat);
+       show_pending_messages (chat);
 }
 
-const gchar *
-empathy_chat_get_status_icon_name (EmpathyChat *chat)
+static void
+empathy_chat_class_init (EmpathyChatClass *klass)
 {
-       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
-
-       if (EMPATHY_CHAT_GET_CLASS (chat)->get_status_icon_name) {
-               return EMPATHY_CHAT_GET_CLASS (chat)->get_status_icon_name (chat);
-       }
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+       GObjectClass   *object_class = G_OBJECT_CLASS (klass);
 
-       return NULL;
-}
+       object_class->finalize = chat_finalize;
+       object_class->get_property = chat_get_property;
+       object_class->set_property = chat_set_property;
+       object_class->constructed = chat_constructed;
+
+       widget_class->size_request = chat_size_request;
+       widget_class->size_allocate = chat_size_allocate;
+
+       g_object_class_install_property (object_class,
+                                        PROP_TP_CHAT,
+                                        g_param_spec_object ("tp-chat",
+                                                             "Empathy tp chat",
+                                                             "The tp chat object",
+                                                             EMPATHY_TYPE_TP_CHAT,
+                                                             G_PARAM_CONSTRUCT |
+                                                             G_PARAM_READWRITE));
+       g_object_class_install_property (object_class,
+                                        PROP_ACCOUNT,
+                                        g_param_spec_object ("account",
+                                                             "Account of the chat",
+                                                             "The account of the chat",
+                                                             MC_TYPE_ACCOUNT,
+                                                             G_PARAM_READABLE));
+       g_object_class_install_property (object_class,
+                                        PROP_ID,
+                                        g_param_spec_string ("id",
+                                                             "Chat's id",
+                                                             "The id of the chat",
+                                                             NULL,
+                                                             G_PARAM_READABLE));
+       g_object_class_install_property (object_class,
+                                        PROP_NAME,
+                                        g_param_spec_string ("name",
+                                                             "Chat's name",
+                                                             "The name of the chat",
+                                                             NULL,
+                                                             G_PARAM_READABLE));
+       g_object_class_install_property (object_class,
+                                        PROP_SUBJECT,
+                                        g_param_spec_string ("subject",
+                                                             "Chat's subject",
+                                                             "The subject or topic of the chat",
+                                                             NULL,
+                                                             G_PARAM_READABLE));
+       g_object_class_install_property (object_class,
+                                        PROP_REMOTE_CONTACT,
+                                        g_param_spec_object ("remote-contact",
+                                                             "The remote contact",
+                                                             "The remote contact is any",
+                                                             EMPATHY_TYPE_CONTACT,
+                                                             G_PARAM_READABLE));
 
-GtkWidget *
-empathy_chat_get_widget (EmpathyChat *chat)
-{
-       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+       signals[COMPOSING] =
+               g_signal_new ("composing",
+                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_SIGNAL_RUN_LAST,
+                             0,
+                             NULL, NULL,
+                             g_cclosure_marshal_VOID__BOOLEAN,
+                             G_TYPE_NONE,
+                             1, G_TYPE_BOOLEAN);
 
-       if (EMPATHY_CHAT_GET_CLASS (chat)->get_widget) {
-               return EMPATHY_CHAT_GET_CLASS (chat)->get_widget (chat);
-       }
+       signals[NEW_MESSAGE] =
+               g_signal_new ("new-message",
+                             G_OBJECT_CLASS_TYPE (object_class),
+                             G_SIGNAL_RUN_LAST,
+                             0,
+                             NULL, NULL,
+                             g_cclosure_marshal_VOID__OBJECT,
+                             G_TYPE_NONE,
+                             1, EMPATHY_TYPE_MESSAGE);
 
-       return NULL;
+       g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
 }
 
-gboolean
-empathy_chat_is_group_chat (EmpathyChat *chat)
+static gboolean
+chat_block_events_timeout_cb (gpointer data)
 {
-       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
+       EmpathyChatPriv *priv = GET_PRIV (data);
 
-       if (EMPATHY_CHAT_GET_CLASS (chat)->is_group_chat) {
-               return EMPATHY_CHAT_GET_CLASS (chat)->is_group_chat (chat);
-       }
+       priv->block_events_timeout_id = 0;
 
        return FALSE;
 }
 
-gboolean 
-empathy_chat_is_connected (EmpathyChat *chat)
+static void
+empathy_chat_init (EmpathyChat *chat)
 {
-       EmpathyChatPriv *priv;
+       EmpathyChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
+               EMPATHY_TYPE_CHAT, EmpathyChatPriv);
 
-       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
+       chat->priv = priv;
+       priv->log_manager = empathy_log_manager_dup_singleton ();
+       priv->contacts_width = -1;
+       priv->sent_messages = NULL;
+       priv->sent_messages_index = -1;
+       priv->account_manager = empathy_account_manager_dup_singleton ();
 
-       priv = GET_PRIV (chat);
+       g_signal_connect (priv->account_manager,
+                         "new-connection",
+                         G_CALLBACK (chat_new_connection_cb),
+                         chat);
 
-       return (priv->tp_chat != NULL);
+       /* Block events for some time to avoid having "has come online" or
+        * "joined" messages. */
+       priv->block_events_timeout_id =
+               g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
+
+       /* Add nick name completion */
+       priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_name);
+       g_completion_set_compare (priv->completion, chat_contacts_completion_func);
 }
 
-void
-empathy_chat_save_geometry (EmpathyChat *chat,
-                          gint        x,
-                          gint        y,
-                          gint        w,
-                          gint        h)
+EmpathyChat *
+empathy_chat_new (EmpathyTpChat *tp_chat)
 {
-       empathy_geometry_save (empathy_chat_get_id (chat), x, y, w, h);
+       return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
 }
 
-void
-empathy_chat_load_geometry (EmpathyChat *chat,
-                          gint       *x,
-                          gint       *y,
-                          gint       *w,
-                          gint       *h)
+EmpathyTpChat *
+empathy_chat_get_tp_chat (EmpathyChat *chat)
 {
-       empathy_geometry_load (empathy_chat_get_id (chat), x, y, w, h);
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
+       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+
+       return priv->tp_chat;
 }
 
 void
 empathy_chat_set_tp_chat (EmpathyChat   *chat,
                          EmpathyTpChat *tp_chat)
 {
-       EmpathyChatPriv *priv;
-       GList           *messages, *l;
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       TpConnection    *connection;
 
        g_return_if_fail (EMPATHY_IS_CHAT (chat));
        g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
+       g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
 
-       priv = GET_PRIV (chat);
-
-       if (tp_chat == priv->tp_chat) {
+       if (priv->tp_chat) {
                return;
        }
 
-       if (priv->tp_chat) {
-               g_signal_handlers_disconnect_by_func (priv->tp_chat,
-                                                     chat_message_received_cb,
-                                                     chat);
-               g_signal_handlers_disconnect_by_func (priv->tp_chat,
-                                                     chat_send_error_cb,
-                                                     chat);
-               g_signal_handlers_disconnect_by_func (priv->tp_chat,
-                                                     chat_destroy_cb,
-                                                     chat);
-               g_object_unref (priv->tp_chat);
+       if (priv->account) {
+               g_object_unref (priv->account);
        }
 
-       g_free (priv->id);
        priv->tp_chat = g_object_ref (tp_chat);
-       priv->id = g_strdup (empathy_tp_chat_get_id (tp_chat));
-
-       if (priv->first_tp_chat) {
-               chat_add_logs (chat);
-               priv->first_tp_chat = FALSE;
-       }
+       connection = empathy_tp_chat_get_connection (priv->tp_chat);
+       priv->account = empathy_account_manager_get_account (priv->account_manager,
+                                                            connection);
+       g_object_ref (priv->account);
 
+       g_signal_connect (tp_chat, "destroy",
+                         G_CALLBACK (chat_destroy_cb),
+                         chat);
        g_signal_connect (tp_chat, "message-received",
                          G_CALLBACK (chat_message_received_cb),
                          chat);
@@ -1379,67 +1653,124 @@ empathy_chat_set_tp_chat (EmpathyChat   *chat,
        g_signal_connect (tp_chat, "chat-state-changed",
                          G_CALLBACK (chat_state_changed_cb),
                          chat);
-       g_signal_connect (tp_chat, "destroy",
-                         G_CALLBACK (chat_destroy_cb),
+       g_signal_connect (tp_chat, "property-changed",
+                         G_CALLBACK (chat_property_changed_cb),
                          chat);
+       g_signal_connect (tp_chat, "members-changed",
+                         G_CALLBACK (chat_members_changed_cb),
+                         chat);
+       g_signal_connect_swapped (tp_chat, "notify::remote-contact",
+                                 G_CALLBACK (chat_remote_contact_changed_cb),
+                                 chat);
 
-       /* Get pending messages */
-       empathy_tp_chat_set_acknowledge (tp_chat, TRUE);
-       messages = empathy_tp_chat_get_pendings (tp_chat);
-       for (l = messages; l; l = l->next) {
-               chat_message_received_cb (tp_chat, l->data, chat);
-               g_object_unref (l->data);
-       }
-       g_list_free (messages);
+       chat_remote_contact_changed_cb (chat);
 
-       if (!priv->sensitive) {
+       if (chat->input_text_view) {
                gtk_widget_set_sensitive (chat->input_text_view, TRUE);
-               empathy_chat_view_append_event (chat->view, _("Connected"));
-               priv->sensitive = TRUE;
+               if (priv->block_events_timeout_id == 0) {
+                       empathy_chat_view_append_event (chat->view, _("Connected"));
+               }
        }
 
-       if (EMPATHY_CHAT_GET_CLASS (chat)->set_tp_chat) {
-               EMPATHY_CHAT_GET_CLASS (chat)->set_tp_chat (chat, tp_chat);
-       }
+       g_object_notify (G_OBJECT (chat), "tp-chat");
+       g_object_notify (G_OBJECT (chat), "id");
+       g_object_notify (G_OBJECT (chat), "account");
+
+       /* This is a noop when tp-chat is set at object construction time and causes
+        * the pending messages to be show when it's set on the object after it has
+        * been created */
+       show_pending_messages (chat);
+}
+
+McAccount *
+empathy_chat_get_account (EmpathyChat *chat)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+
+       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
 
+       return priv->account;
 }
 
 const gchar *
 empathy_chat_get_id (EmpathyChat *chat)
 {
-       EmpathyChatPriv *priv;
+       EmpathyChatPriv *priv = GET_PRIV (chat);
 
-       priv = GET_PRIV (chat);
+       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
 
        return priv->id;
 }
 
-void
-empathy_chat_clear (EmpathyChat *chat)
+const gchar *
+empathy_chat_get_name (EmpathyChat *chat)
 {
-       g_return_if_fail (EMPATHY_IS_CHAT (chat));
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       const gchar *ret;
 
-       empathy_chat_view_clear (chat->view);
+       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+
+       ret = priv->name;
+       if (!ret && priv->remote_contact) {
+               ret = empathy_contact_get_name (priv->remote_contact);
+       }
+
+       if (!ret)
+               ret = priv->id;
+
+       return ret ? ret : _("Conversation");
 }
 
-void
-empathy_chat_set_window (EmpathyChat       *chat,
-                       EmpathyChatWindow *window)
+const gchar *
+empathy_chat_get_subject (EmpathyChat *chat)
 {
-       EmpathyChatPriv *priv;
+       EmpathyChatPriv *priv = GET_PRIV (chat);
 
-       priv = GET_PRIV (chat);
-       priv->window = window;
+       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+
+       return priv->subject;
 }
 
-EmpathyChatWindow *
-empathy_chat_get_window (EmpathyChat *chat)
+EmpathyContact *
+empathy_chat_get_remote_contact (EmpathyChat *chat)
 {
-       EmpathyChatPriv *priv;
+       EmpathyChatPriv *priv = GET_PRIV (chat);
 
-       priv = GET_PRIV (chat);
+       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+
+       return priv->remote_contact;
+}
+
+GtkWidget *
+empathy_chat_get_contact_menu (EmpathyChat *chat)
+{
+       EmpathyChatPriv *priv = GET_PRIV (chat);
+       GtkWidget       *menu = NULL;
+
+       g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+
+       if (priv->remote_contact) {
+               menu = empathy_contact_menu_new (priv->remote_contact,
+                                                EMPATHY_CONTACT_FEATURE_CALL |
+                                                EMPATHY_CONTACT_FEATURE_LOG |
+                                                EMPATHY_CONTACT_FEATURE_INFO);
+       }
+       else if (priv->contact_list_view) {
+               EmpathyContactListView *view;
+
+               view = EMPATHY_CONTACT_LIST_VIEW (priv->contact_list_view);
+               menu = empathy_contact_list_view_get_contact_menu (view);
+       }
+
+       return menu;
+}
+
+void
+empathy_chat_clear (EmpathyChat *chat)
+{
+       g_return_if_fail (EMPATHY_IS_CHAT (chat));
 
-       return priv->window;
+       empathy_chat_view_clear (chat->view);
 }
 
 void
@@ -1458,7 +1789,7 @@ empathy_chat_cut (EmpathyChat *chat)
        g_return_if_fail (EMPATHY_IS_CHAT (chat));
 
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
-       if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
+       if (gtk_text_buffer_get_has_selection (buffer)) {
                GtkClipboard *clipboard;
 
                clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
@@ -1474,13 +1805,13 @@ empathy_chat_copy (EmpathyChat *chat)
 
        g_return_if_fail (EMPATHY_IS_CHAT (chat));
 
-       if (empathy_chat_view_get_selection_bounds (chat->view, NULL, NULL)) {
+       if (empathy_chat_view_get_has_selection (chat->view)) {
                empathy_chat_view_copy_clipboard (chat->view);
                return;
        }
 
        buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
-       if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
+       if (gtk_text_buffer_get_has_selection (buffer)) {
                GtkClipboard *clipboard;
 
                clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
@@ -1504,116 +1835,31 @@ empathy_chat_paste (EmpathyChat *chat)
 }
 
 void
-empathy_chat_present (EmpathyChat *chat)
+empathy_chat_correct_word (EmpathyChat  *chat,
+                         GtkTextIter *start,
+                         GtkTextIter *end,
+                         const gchar *new_word)
 {
-       EmpathyChatPriv *priv;
-
-       g_return_if_fail (EMPATHY_IS_CHAT (chat));
-
-       priv = GET_PRIV (chat);
-
-       if (priv->window == NULL) {
-               EmpathyChatWindow *window;
-
-               window = empathy_chat_window_get_default ();
-               if (!window) {
-                       window = empathy_chat_window_new ();
-               }
+       GtkTextBuffer *buffer;
 
-               empathy_chat_window_add_chat (window, chat);
-       }
+       g_return_if_fail (chat != NULL);
+       g_return_if_fail (new_word != NULL);
 
-       empathy_chat_window_switch_to_chat (priv->window, chat);
-       empathy_window_present (
-               GTK_WINDOW (empathy_chat_window_get_dialog (priv->window)),
-               TRUE);
+       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
 
-       gtk_widget_grab_focus (chat->input_text_view); 
+       gtk_text_buffer_delete (buffer, start, end);
+       gtk_text_buffer_insert (buffer, start,
+                               new_word,
+                               -1);
 }
 
 gboolean
-empathy_chat_should_play_sound (EmpathyChat *chat)
+empathy_chat_is_room (EmpathyChat *chat)
 {
-       EmpathyChatWindow *window;
-       gboolean          play = TRUE;
+       EmpathyChatPriv *priv = GET_PRIV (chat);
 
        g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
 
-       window = empathy_chat_get_window (chat);
-       if (!window) {
-               return TRUE;
-       }
-
-       play = !empathy_chat_window_has_focus (window);
-
-       return play;
-}
-
-gboolean
-empathy_chat_should_highlight_nick (EmpathyMessage *message)
-{
-       EmpathyContact *contact;
-       const gchar   *msg, *to;
-       gchar         *cf_msg, *cf_to;
-       gchar         *ch;
-       gboolean       ret_val;
-
-       g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE);
-
-       empathy_debug (DEBUG_DOMAIN, "Highlighting nickname");
-
-       ret_val = FALSE;
-
-       msg = empathy_message_get_body (message);
-       if (!msg) {
-               return FALSE;
-       }
-
-       contact = empathy_message_get_receiver (message);
-       if (!contact || !empathy_contact_is_user (contact)) {
-               return FALSE;
-       }
-
-       to = empathy_contact_get_name (contact);
-       if (!to) {
-               return FALSE;
-       }
-
-       cf_msg = g_utf8_casefold (msg, -1);
-       cf_to = g_utf8_casefold (to, -1);
-
-       ch = strstr (cf_msg, cf_to);
-       if (ch == NULL) {
-               goto finished;
-       }
-
-       if (ch != cf_msg) {
-               /* Not first in the message */
-               if ((*(ch - 1) != ' ') &&
-                   (*(ch - 1) != ',') &&
-                   (*(ch - 1) != '.')) {
-                       goto finished;
-               }
-       }
-
-       ch = ch + strlen (cf_to);
-       if (ch >= cf_msg + strlen (cf_msg)) {
-               ret_val = TRUE;
-               goto finished;
-       }
-
-       if ((*ch == ' ') ||
-           (*ch == ',') ||
-           (*ch == '.') ||
-           (*ch == ':')) {
-               ret_val = TRUE;
-               goto finished;
-       }
-
-finished:
-       g_free (cf_msg);
-       g_free (cf_to);
-
-       return ret_val;
+       return (priv->handle_type == TP_HANDLE_TYPE_ROOM);
 }