]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-message.c
Updated Swedish translation
[empathy.git] / libempathy / empathy-message.c
index 9841cbb618f24e3e7246be3eddf7d101aca0895c..ab683c717e2c753c70cb86f4e62e834f44369357 100644 (file)
  */
 
 #include "config.h"
-
-#include <string.h>
+#include "empathy-message.h"
 
 #include <glib/gi18n-lib.h>
-
-#include <telepathy-glib/util.h>
-#include <telepathy-glib/account.h>
-#include <telepathy-glib/account-manager.h>
-
-#include <telepathy-logger/entity.h>
-#include <telepathy-logger/event.h>
-#include <telepathy-logger/text-event.h>
-#ifdef HAVE_CALL_LOGS
-# include <telepathy-logger/call-event.h>
-#endif
-
-#define DEBUG_FLAG EMPATHY_DEBUG_CHAT
-#include "empathy-debug.h"
+#include <tp-account-widgets/tpaw-time.h>
 
 #include "empathy-client-factory.h"
-#include "empathy-message.h"
 #include "empathy-utils.h"
 #include "empathy-enum-types.h"
 
@@ -61,7 +46,6 @@ typedef struct {
        gboolean                  is_backlog;
        guint                     id;
        gboolean                  incoming;
-       TpChannelTextMessageFlags flags;
 } EmpathyMessagePriv;
 
 static void empathy_message_finalize   (GObject            *object);
@@ -88,7 +72,6 @@ enum {
        PROP_ORIGINAL_TIMESTAMP,
        PROP_IS_BACKLOG,
        PROP_INCOMING,
-       PROP_FLAGS,
        PROP_TP_MESSAGE,
 };
 
@@ -182,15 +165,6 @@ empathy_message_class_init (EmpathyMessageClass *class)
                                                               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
                                                               G_PARAM_CONSTRUCT_ONLY));
 
-       g_object_class_install_property (object_class,
-                                        PROP_FLAGS,
-                                        g_param_spec_uint ("flags",
-                                                              "Flags",
-                                                              "The TpChannelTextMessageFlags of this message",
-                                                              0, G_MAXUINT, 0,
-                                                              G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
-                                                              G_PARAM_CONSTRUCT_ONLY));
-
        g_object_class_install_property (object_class,
                                         PROP_TP_MESSAGE,
                                         g_param_spec_object ("tp-message",
@@ -211,7 +185,7 @@ empathy_message_init (EmpathyMessage *message)
                EMPATHY_TYPE_MESSAGE, EmpathyMessagePriv);
 
        message->priv = priv;
-       priv->timestamp = empathy_time_get_current ();
+       priv->timestamp = tpaw_time_get_current ();
 }
 
 static void
@@ -280,9 +254,6 @@ message_get_property (GObject    *object,
        case PROP_INCOMING:
                g_value_set_boolean (value, priv->incoming);
                break;
-       case PROP_FLAGS:
-               g_value_set_uint (value, priv->flags);
-               break;
        case PROP_TP_MESSAGE:
                g_value_set_object (value, priv->tp_message);
                break;
@@ -329,7 +300,7 @@ message_set_property (GObject      *object,
        case PROP_TIMESTAMP:
                priv->timestamp = g_value_get_int64 (value);
                if (priv->timestamp <= 0)
-                       priv->timestamp = empathy_time_get_current ();
+                       priv->timestamp = tpaw_time_get_current ();
                break;
        case PROP_ORIGINAL_TIMESTAMP:
                priv->original_timestamp = g_value_get_int64 (value);
@@ -340,9 +311,6 @@ message_set_property (GObject      *object,
        case PROP_INCOMING:
                priv->incoming = g_value_get_boolean (value);
                break;
-       case PROP_FLAGS:
-               priv->flags = g_value_get_uint (value);
-               break;
        case PROP_TP_MESSAGE:
                priv->tp_message = g_value_dup_object (value);
                break;
@@ -408,13 +376,12 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
                type = tpl_text_event_get_message_type (TPL_TEXT_EVENT (logevent));
                token = tpl_text_event_get_message_token (textevent);
        }
-#ifdef HAVE_CALL_LOGS
        else if (TPL_IS_CALL_EVENT (logevent)) {
                TplCallEvent *call = TPL_CALL_EVENT (logevent);
 
                timestamp = tpl_event_get_timestamp (logevent);
 
-               if (tpl_call_event_get_end_reason (call) == TPL_CALL_END_REASON_NO_ANSWER)
+               if (tpl_call_event_get_end_reason (call) == TP_CALL_STATE_CHANGE_REASON_NO_ANSWER)
                        body = g_strdup_printf (_("Missed call from %s"),
                                tpl_entity_get_alias (tpl_event_get_sender (logevent)));
                else if (tpl_entity_get_entity_type (tpl_event_get_sender (logevent)) == TPL_ENTITY_SELF)
@@ -425,7 +392,6 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
                        body = g_strdup_printf (_("Call from %s"),
                                tpl_entity_get_alias (tpl_event_get_sender (logevent)));
        }
-#endif
        else {
                /* Unknown event type */
                return NULL;
@@ -636,73 +602,6 @@ empathy_message_is_backlog (EmpathyMessage *message)
        return priv->is_backlog;
 }
 
-static GRegex *
-get_highlight_regex_for (const gchar *name)
-{
-       GRegex *regex;
-       gchar *name_esc, *pattern;
-       GError *error = NULL;
-
-       name_esc = g_regex_escape_string (name, -1);
-       pattern = g_strdup_printf ("\\b%s\\b", name_esc);
-       regex = g_regex_new (pattern, G_REGEX_CASELESS | G_REGEX_OPTIMIZE, 0,
-               &error);
-
-       if (regex == NULL) {
-               DEBUG ("couldn't compile regex /%s/: %s", pattern,
-                       error->message);
-
-               g_error_free (error);
-       }
-
-       g_free (pattern);
-       g_free (name_esc);
-
-       return regex;
-}
-
-gboolean
-empathy_message_should_highlight (EmpathyMessage *message)
-{
-       EmpathyContact *contact;
-       const gchar   *msg, *to;
-       gboolean       ret_val = FALSE;
-       TpChannelTextMessageFlags flags;
-       GRegex *regex;
-
-       g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), 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_alias (contact);
-       if (!to) {
-               return FALSE;
-       }
-
-       flags = empathy_message_get_flags (message);
-       if (flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK) {
-               /* FIXME: Ideally we shouldn't highlight scrollback messages only if they
-                * have already been received by the user before (and so are in the logs) */
-               return FALSE;
-       }
-
-       regex = get_highlight_regex_for (to);
-       if (regex != NULL) {
-               ret_val = g_regex_match (regex, msg, 0, NULL);
-               g_regex_unref (regex);
-       }
-
-       return ret_val;
-}
-
 TpChannelTextMessageType
 empathy_message_type_from_str (const gchar *type_str)
 {
@@ -770,31 +669,19 @@ empathy_message_equal (EmpathyMessage *message1, EmpathyMessage *message2)
        return FALSE;
 }
 
-TpChannelTextMessageFlags
-empathy_message_get_flags (EmpathyMessage *self)
-{
-       EmpathyMessagePriv *priv = GET_PRIV (self);
-
-       g_return_val_if_fail (EMPATHY_IS_MESSAGE (self), 0);
-
-       return priv->flags;
-}
-
 EmpathyMessage *
 empathy_message_new_from_tp_message (TpMessage *tp_msg,
                                     gboolean incoming)
 {
        EmpathyMessage *message;
        gchar *body;
-       TpChannelTextMessageFlags flags;
        gint64 timestamp;
        gint64 original_timestamp;
        const GHashTable *part = tp_message_peek (tp_msg, 0);
-       gboolean is_backlog;
 
        g_return_val_if_fail (TP_IS_MESSAGE (tp_msg), NULL);
 
-       body = tp_message_to_text (tp_msg, &flags);
+       body = tp_message_to_text (tp_msg, NULL);
 
        timestamp = tp_message_get_sent_timestamp (tp_msg);
        if (timestamp == 0)
@@ -803,9 +690,6 @@ empathy_message_new_from_tp_message (TpMessage *tp_msg,
        original_timestamp = tp_asv_get_int64 (part,
                "original-message-received", NULL);
 
-       is_backlog = (flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK) ==
-               TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK;
-
        message = g_object_new (EMPATHY_TYPE_MESSAGE,
                "body", body,
                "token", tp_message_get_token (tp_msg),
@@ -813,8 +697,7 @@ empathy_message_new_from_tp_message (TpMessage *tp_msg,
                "type", tp_message_get_message_type (tp_msg),
                "timestamp", timestamp,
                "original-timestamp", original_timestamp,
-               "flags", flags,
-               "is-backlog", is_backlog,
+               "is-backlog", tp_message_is_scrollback (tp_msg),
                "incoming", incoming,
                "tp-message", tp_msg,
                NULL);