]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/gossip-chat.c
sv.po: Updated Swedish translation
[empathy.git] / libempathy-gtk / gossip-chat.c
index 5492edfbf82ad1d2a05ba0b66a4dfbaebb7009c5..1ad76b7f5fc6b8b2a360953280a78cf2978ceb58 100644 (file)
@@ -33,7 +33,6 @@
 #include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
-#include <glade/glade.h>
 
 #include <libempathy/empathy-contact-manager.h>
 #include <libempathy/empathy-log-manager.h>
@@ -47,7 +46,7 @@
 #include "gossip-geometry.h"
 #include "gossip-preferences.h"
 #include "gossip-spell.h"
-//#include "gossip-spell-dialog.h"
+#include "gossip-spell-dialog.h"
 #include "gossip-ui-utils.h"
 
 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_CHAT, GossipChatPriv))
@@ -77,6 +76,7 @@ struct _GossipChatPriv {
        GList                 *compositors;
        guint                  scroll_idle_id;
        gboolean               first_tp_chat;
+       GossipTime             time_joined;
        /* Used to automatically shrink a window that has temporarily
         * grown due to long input. 
         */
@@ -340,9 +340,8 @@ static void
 chat_send (GossipChat  *chat,
           const gchar *msg)
 {
-       GossipChatPriv    *priv;
-       GossipMessage     *message;
-       GossipContact     *own_contact;
+       GossipChatPriv *priv;
+       GossipMessage  *message;
 
        priv = GET_PRIV (chat);
 
@@ -360,9 +359,7 @@ chat_send (GossipChat  *chat,
        /* FIXME: add here something to let group/privrate chat handle
         *        some special messages */
 
-       own_contact = empathy_contact_manager_get_user (priv->manager, chat->account);
        message = gossip_message_new (msg);
-       gossip_message_set_sender (message, own_contact);
 
        empathy_tp_chat_send (priv->tp_chat, message);
 
@@ -401,6 +398,7 @@ chat_message_received_cb (EmpathyTpChat *tp_chat,
 {
        GossipChatPriv *priv;
        GossipContact  *sender;
+       GossipTime      timestamp;
 
        priv = GET_PRIV (chat);
 
@@ -408,9 +406,14 @@ chat_message_received_cb (EmpathyTpChat *tp_chat,
        gossip_debug (DEBUG_DOMAIN, "Appending message ('%s')",
                      gossip_contact_get_name (sender));
 
-       empathy_log_manager_add_message (priv->log_manager,
-                                        gossip_chat_get_id (chat),
-                                        message);
+       /* Log the message only if it's not backlog */
+       timestamp = gossip_message_get_timestamp (message);
+       if (timestamp >= priv->time_joined) {
+               empathy_log_manager_add_message (priv->log_manager,
+                                                gossip_chat_get_id (chat),
+                                                gossip_chat_is_group_chat (chat),
+                                                message);
+       }
 
        gossip_chat_view_append_message (chat->view, message);
 
@@ -930,10 +933,10 @@ static void
 chat_text_check_word_spelling_cb (GtkMenuItem     *menuitem,
                                  GossipChatSpell *chat_spell)
 {
-/*FIXME:       gossip_spell_dialog_show (chat_spell->chat,
+       gossip_spell_dialog_show (chat_spell->chat,
                                  chat_spell->start,
                                  chat_spell->end,
-                                 chat_spell->word);*/
+                                 chat_spell->word);
 }
 
 static GossipChatSpell *
@@ -1029,14 +1032,12 @@ chat_state_changed_cb (EmpathyTpChat             *tp_chat,
                       GossipChat                *chat)
 {
        GossipChatPriv *priv;
-       GossipContact  *own_contact;
        GList          *l;
        gboolean        was_composing;
 
        priv = GET_PRIV (chat);
 
-       own_contact = gossip_contact_get_user (contact);
-       if (gossip_contact_equal (own_contact, contact)) {
+       if (gossip_contact_is_user (contact)) {
                /* We don't care about our own chat state */
                return;
        }
@@ -1081,7 +1082,7 @@ chat_state_changed_cb (EmpathyTpChat             *tp_chat,
            (!was_composing && priv->compositors)) {
                /* Composing state changed */
                g_signal_emit (chat, signals[COMPOSING], 0,
-                              (gboolean) priv->compositors);
+                              priv->compositors != NULL);
        }
 }
 
@@ -1095,13 +1096,19 @@ chat_add_logs (GossipChat *chat)
 
        priv = GET_PRIV (chat);
 
+       /* Do not display backlog for chatrooms */
+       if (gossip_chat_is_group_chat (chat)) {
+               return;
+       }
+
        /* Turn off scrolling temporarily */
        gossip_chat_view_scroll (chat->view, FALSE);
 
        /* Add messages from last conversation */
        messages = empathy_log_manager_get_last_messages (priv->log_manager,
                                                          chat->account,
-                                                         gossip_chat_get_id (chat));
+                                                         gossip_chat_get_id (chat),
+                                                         gossip_chat_is_group_chat (chat));
        num_messages  = g_list_length (messages);
 
        for (l = messages, i = 0; l; l = l->next, i++) {
@@ -1308,6 +1315,7 @@ gossip_chat_set_tp_chat (GossipChat    *chat,
        g_free (priv->id);
        priv->tp_chat = g_object_ref (tp_chat);
        priv->id = g_strdup (empathy_tp_chat_get_id (tp_chat));
+       priv->time_joined = gossip_time_get_current ();
 
        if (priv->first_tp_chat) {
                chat_add_logs (chat);
@@ -1486,7 +1494,7 @@ gossip_chat_should_play_sound (GossipChat *chat)
 gboolean
 gossip_chat_should_highlight_nick (GossipMessage *message)
 {
-       GossipContact *my_contact;
+       GossipContact *contact;
        const gchar   *msg, *to;
        gchar         *cf_msg, *cf_to;
        gchar         *ch;
@@ -1503,8 +1511,12 @@ gossip_chat_should_highlight_nick (GossipMessage *message)
                return FALSE;
        }
 
-       my_contact = gossip_contact_get_user (gossip_message_get_sender (message));
-       to = gossip_contact_get_name (my_contact);
+       contact = gossip_message_get_receiver (message);
+       if (!contact || !gossip_contact_is_user (contact)) {
+               return FALSE;
+       }
+
+       to = gossip_contact_get_name (contact);
        if (!to) {
                return FALSE;
        }