]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-message.c
Merge remote-tracking branch 'glassrose/add-All-service-selection-in-debug-window'
[empathy.git] / libempathy / empathy-message.c
index 7864ee2ba7c1d9e77df06ad092704f7f42af762d..6111bcd8c25ace3f783f840325353b111c62a964 100644 (file)
@@ -39,6 +39,7 @@
 # include <telepathy-logger/call-event.h>
 #endif
 
+#include "empathy-client-factory.h"
 #include "empathy-message.h"
 #include "empathy-utils.h"
 #include "empathy-enum-types.h"
@@ -352,7 +353,7 @@ EmpathyMessage *
 empathy_message_from_tpl_log_event (TplEvent *logevent)
 {
        EmpathyMessage *retval = NULL;
-       TpAccountManager *acc_man = NULL;
+       EmpathyClientFactory *factory;
        TpAccount *account = NULL;
        TplEntity *receiver = NULL;
        TplEntity *sender = NULL;
@@ -364,7 +365,7 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
 
        g_return_val_if_fail (TPL_IS_EVENT (logevent), NULL);
 
-       acc_man = tp_account_manager_dup ();
+       factory = empathy_client_factory_dup ();
        /* FIXME Currently Empathy shows in the log viewer only valid accounts, so it
         * won't be selected any non-existing (ie removed) account.
         * When #610455 will be fixed, calling tp_account_manager_ensure_account ()
@@ -376,9 +377,10 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
         * If the way EmpathyContact stores the avatar is changes, it might not be
         * needed anymore any TpAccount passing and the following call will be
         * useless */
-       account = tp_account_manager_ensure_account (acc_man,
-                       tpl_event_get_account_path (logevent));
-       g_object_unref (acc_man);
+       account = tp_simple_client_factory_ensure_account (
+                       TP_SIMPLE_CLIENT_FACTORY (factory),
+                       tpl_event_get_account_path (logevent), NULL, NULL);
+       g_object_unref (factory);
 
        if (TPL_IS_TEXT_EVENT (logevent)) {
                TplTextEvent *textevent = TPL_TEXT_EVENT (logevent);
@@ -413,6 +415,7 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
                        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)
+                       /* Translators: this is an outgoing call, e.g. 'Called Alice' */
                        body = g_strdup_printf (_("Called %s"),
                                tpl_entity_get_alias (tpl_event_get_receiver (logevent)));
                else
@@ -630,75 +633,6 @@ empathy_message_is_backlog (EmpathyMessage *message)
        return priv->is_backlog;
 }
 
-#define IS_SEPARATOR(ch) (ch == ' ' || ch == ',' || ch == '.' || ch == ':')
-gboolean
-empathy_message_should_highlight (EmpathyMessage *message)
-{
-       EmpathyContact *contact;
-       const gchar   *msg, *to;
-       gchar         *cf_msg, *cf_to;
-       gchar         *ch;
-       gboolean       ret_val;
-       TpChannelTextMessageFlags flags;
-
-       g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE);
-
-       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_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;
-       }
-
-       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 (!IS_SEPARATOR (*(ch - 1))) {
-                       goto finished;
-               }
-       }
-
-       ch = ch + strlen (cf_to);
-       if (ch >= cf_msg + strlen (cf_msg)) {
-               ret_val = TRUE;
-               goto finished;
-       }
-
-       if (IS_SEPARATOR (*ch)) {
-               ret_val = TRUE;
-               goto finished;
-       }
-
-finished:
-       g_free (cf_msg);
-       g_free (cf_to);
-
-       return ret_val;
-}
-
 TpChannelTextMessageType
 empathy_message_type_from_str (const gchar *type_str)
 {
@@ -783,25 +717,34 @@ empathy_message_new_from_tp_message (TpMessage *tp_msg,
        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);
 
+       timestamp = tp_message_get_sent_timestamp (tp_msg);
+       if (timestamp == 0)
+               timestamp = tp_message_get_received_timestamp (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),
                "supersedes", tp_message_get_supersedes (tp_msg),
                "type", tp_message_get_message_type (tp_msg),
-               "timestamp", tp_message_get_received_timestamp (tp_msg),
+               "timestamp", timestamp,
                "original-timestamp", original_timestamp,
                "flags", flags,
-               "is-backlog", flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK,
+               "is-backlog", is_backlog,
                "incoming", incoming,
                "tp-message", tp_msg,
                NULL);