*/
#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
-
-#include "empathy-message.h"
+#include "empathy-client-factory.h"
+#include "empathy-time.h"
#include "empathy-utils.h"
#include "empathy-enum-types.h"
gchar *supersedes;
gchar *body;
gint64 timestamp;
+ gint64 original_timestamp;
gboolean is_backlog;
guint id;
gboolean incoming;
PROP_SUPERSEDES,
PROP_BODY,
PROP_TIMESTAMP,
+ PROP_ORIGINAL_TIMESTAMP,
PROP_IS_BACKLOG,
PROP_INCOMING,
PROP_FLAGS,
G_MININT64, G_MAXINT64, 0,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class,
+ PROP_ORIGINAL_TIMESTAMP,
+ g_param_spec_int64 ("original-timestamp",
+ "Original Timestamp",
+ "Timestamp of the original message",
+ G_MININT64, G_MAXINT64, 0,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_IS_BACKLOG,
g_param_spec_boolean ("is-backlog",
case PROP_TIMESTAMP:
g_value_set_int64 (value, priv->timestamp);
break;
+ case PROP_ORIGINAL_TIMESTAMP:
+ g_value_set_int64 (value, priv->original_timestamp);
+ break;
case PROP_IS_BACKLOG:
g_value_set_boolean (value, priv->is_backlog);
break;
if (priv->timestamp <= 0)
priv->timestamp = empathy_time_get_current ();
break;
+ case PROP_ORIGINAL_TIMESTAMP:
+ priv->original_timestamp = g_value_get_int64 (value);
+ break;
case PROP_IS_BACKLOG:
priv->is_backlog = g_value_get_boolean (value);
break;
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;
const gchar *token = NULL, *supersedes = NULL;
EmpathyContact *contact;
TpChannelTextMessageType type = TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL;
+ gint64 timestamp, original_timestamp = 0;
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 ()
* 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);
+ supersedes = tpl_text_event_get_supersedes_token (textevent);
+
+ /* tp-logger is kind of messy in that instead of having
+ * timestamp and original-timestamp like Telepathy it has
+ * timestamp (which is the original) and edited-timestamp,
+ * (which is when the message was edited) */
+ if (tp_str_empty (supersedes)) {
+ /* not an edited message */
+ timestamp = tpl_event_get_timestamp (logevent);
+ } else {
+ /* this is an edited event */
+ original_timestamp = tpl_event_get_timestamp (logevent);
+ timestamp = tpl_text_event_get_edit_timestamp (textevent);
+ }
+
body = g_strdup (tpl_text_event_get_message (textevent));
type = tpl_text_event_get_message_type (TPL_TEXT_EVENT (logevent));
token = tpl_text_event_get_message_token (textevent);
- supersedes = tpl_text_event_get_supersedes_token (textevent);
}
-#ifdef HAVE_CALL_LOGS
else if (TPL_IS_CALL_EVENT (logevent)) {
TplCallEvent *call = TPL_CALL_EVENT (logevent);
- if (tpl_call_event_get_end_reason (call) == TPL_CALL_END_REASON_NO_ANSWER)
+ timestamp = tpl_event_get_timestamp (logevent);
+
+ 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)
+ /* 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
body = g_strdup_printf (_("Call from %s"),
tpl_entity_get_alias (tpl_event_get_sender (logevent)));
}
-#endif
else {
/* Unknown event type */
return NULL;
"supersedes", supersedes,
"body", body,
"is-backlog", TRUE,
- "timestamp", tpl_event_get_timestamp (logevent),
+ "timestamp", timestamp,
+ "original-timestamp", original_timestamp,
NULL);
if (receiver != NULL) {
return priv->timestamp;
}
-gboolean
-empathy_message_is_backlog (EmpathyMessage *message)
+gint64
+empathy_message_get_original_timestamp (EmpathyMessage *message)
{
EmpathyMessagePriv *priv;
- g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE);
+ g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), -1);
priv = GET_PRIV (message);
- return priv->is_backlog;
+ return priv->original_timestamp;
}
-#define IS_SEPARATOR(ch) (ch == ' ' || ch == ',' || ch == '.' || ch == ':')
gboolean
-empathy_message_should_highlight (EmpathyMessage *message)
+empathy_message_is_backlog (EmpathyMessage *message)
{
- EmpathyContact *contact;
- const gchar *msg, *to;
- gchar *cf_msg, *cf_to;
- gchar *ch;
- gboolean ret_val;
- TpChannelTextMessageFlags flags;
+ EmpathyMessagePriv *priv;
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);
+ priv = GET_PRIV (message);
- return ret_val;
+ return priv->is_backlog;
}
TpChannelTextMessageType
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);