aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanielle Madeley <danielle.madeley@collabora.co.uk>2011-04-21 10:52:39 +0800
committerDanielle Madeley <danielle.madeley@collabora.co.uk>2011-04-21 10:52:39 +0800
commit462c1b74848498594239e818270efbcc0cac5170 (patch)
tree06c4eb10110794905d012c82754412996501984e
parentfd96433c558ca24e8db7397b69cbd600caa6b793 (diff)
parenteaaf3c72dcb03ad0be08f53e7b621cdc279cf21e (diff)
downloadgsoc2013-empathy-462c1b74848498594239e818270efbcc0cac5170.tar
gsoc2013-empathy-462c1b74848498594239e818270efbcc0cac5170.tar.gz
gsoc2013-empathy-462c1b74848498594239e818270efbcc0cac5170.tar.bz2
gsoc2013-empathy-462c1b74848498594239e818270efbcc0cac5170.tar.lz
gsoc2013-empathy-462c1b74848498594239e818270efbcc0cac5170.tar.xz
gsoc2013-empathy-462c1b74848498594239e818270efbcc0cac5170.tar.zst
gsoc2013-empathy-462c1b74848498594239e818270efbcc0cac5170.zip
Merge branch 'timestamp-rebase' into empathy-skype
-rw-r--r--libempathy-gtk/empathy-chat-text-view.c41
-rw-r--r--libempathy-gtk/empathy-chat-text-view.h2
-rw-r--r--libempathy-gtk/empathy-chat.c52
-rw-r--r--libempathy-gtk/empathy-contact-widget.c6
-rw-r--r--libempathy-gtk/empathy-individual-widget.c6
-rw-r--r--libempathy-gtk/empathy-location-manager.c12
-rw-r--r--libempathy-gtk/empathy-theme-adium.c6
-rw-r--r--libempathy-gtk/empathy-theme-boxes.c2
-rw-r--r--libempathy/empathy-ft-handler.c4
-rw-r--r--libempathy/empathy-message.c207
-rw-r--r--libempathy/empathy-message.h21
-rw-r--r--libempathy/empathy-time.c122
-rw-r--r--libempathy/empathy-time.h10
-rw-r--r--libempathy/empathy-tp-chat.c365
-rw-r--r--libempathy/empathy-tp-chat.h3
-rw-r--r--libempathy/empathy-tp-file.c2
-rw-r--r--src/empathy-chat-manager.c10
-rw-r--r--src/empathy-event-manager.c2
-rw-r--r--src/empathy-map-view.c16
19 files changed, 400 insertions, 489 deletions
diff --git a/libempathy-gtk/empathy-chat-text-view.c b/libempathy-gtk/empathy-chat-text-view.c
index c05b92fb9..977530971 100644
--- a/libempathy-gtk/empathy-chat-text-view.c
+++ b/libempathy-gtk/empathy-chat-text-view.c
@@ -49,7 +49,7 @@
#include <libempathy/empathy-debug.h>
/* Number of seconds between timestamps when using normal mode, 5 minutes. */
-#define TIMESTAMP_INTERVAL 300
+#define TIMESTAMP_INTERVAL (5 * G_TIME_SPAN_MINUTE)
#define MAX_LINES 800
#define MAX_SCROLL_TIME 0.4 /* seconds */
@@ -66,7 +66,7 @@ typedef struct {
gboolean find_wrapped;
gboolean find_last_direction;
EmpathyContact *last_contact;
- time_t last_timestamp;
+ gint64 last_timestamp;
gboolean allow_scrolling;
guint notify_system_fonts_id;
GConfClient *gconf_client;
@@ -402,7 +402,7 @@ chat_text_view_maybe_trim_buffer (EmpathyChatTextView *view)
static void
chat_text_view_append_timestamp (EmpathyChatTextView *view,
- time_t timestamp,
+ gint64 timestamp,
gboolean show_date)
{
EmpathyChatTextViewPriv *priv = GET_PRIV (view);
@@ -414,17 +414,12 @@ chat_text_view_append_timestamp (EmpathyChatTextView *view,
/* Append date if needed */
if (show_date) {
- GDate *date;
- gchar buf[256];
-
- date = g_date_new ();
- g_date_set_time_t (date, timestamp);
/* Translators: timestamp displayed between conversations in
* chat windows (strftime format string) */
- g_date_strftime (buf, 256, _("%A %B %d %Y"), date);
- g_string_append (str, buf);
+ tmp = empathy_time_to_string_utc (timestamp, _("%A %B %d %Y"));
+ g_string_append (str, tmp);
g_string_append (str, ", ");
- g_date_free (date);
+ g_free (tmp);
}
/* Append time */
@@ -448,32 +443,32 @@ chat_text_view_append_timestamp (EmpathyChatTextView *view,
static void
chat_text_maybe_append_date_and_time (EmpathyChatTextView *view,
- time_t timestamp)
+ gint64 timestamp)
{
EmpathyChatTextViewPriv *priv = GET_PRIV (view);
- GDate *date, *last_date;
+ GDateTime *date, *last_date;
gboolean append_date = FALSE;
gboolean append_time = FALSE;
+ GTimeSpan delta;
/* Get the date from last message */
- last_date = g_date_new ();
- g_date_set_time_t (last_date, priv->last_timestamp);
+ last_date = g_date_time_new_from_unix_utc (priv->last_timestamp);
/* Get the date of the message we are appending */
- date = g_date_new ();
- g_date_set_time_t (date, timestamp);
+ date = g_date_time_new_from_unix_utc (timestamp);
+ delta = g_date_time_difference (last_date, date);
/* If last message was from another day we append date and time */
- if (g_date_compare (date, last_date) > 0) {
+ if (delta >= G_TIME_SPAN_DAY) {
append_date = TRUE;
append_time = TRUE;
}
- g_date_free (last_date);
- g_date_free (date);
+ g_date_time_unref (last_date);
+ g_date_time_unref (date);
/* If last message is 'old' append the time */
- if (timestamp - priv->last_timestamp >= TIMESTAMP_INTERVAL) {
+ if (delta >= TIMESTAMP_INTERVAL) {
append_time = TRUE;
}
@@ -732,7 +727,7 @@ chat_text_view_append_message (EmpathyChatView *view,
EmpathyChatTextView *text_view = EMPATHY_CHAT_TEXT_VIEW (view);
EmpathyChatTextViewPriv *priv = GET_PRIV (text_view);
gboolean bottom;
- time_t timestamp;
+ gint64 timestamp;
g_return_if_fail (EMPATHY_IS_CHAT_TEXT_VIEW (view));
g_return_if_fail (EMPATHY_IS_MESSAGE (msg));
@@ -1327,7 +1322,7 @@ empathy_chat_text_view_get_last_contact (EmpathyChatTextView *view)
return priv->last_contact;
}
-time_t
+gint64
empathy_chat_text_view_get_last_timestamp (EmpathyChatTextView *view)
{
EmpathyChatTextViewPriv *priv = GET_PRIV (view);
diff --git a/libempathy-gtk/empathy-chat-text-view.h b/libempathy-gtk/empathy-chat-text-view.h
index 7ee7ba8a2..12edbcc64 100644
--- a/libempathy-gtk/empathy-chat-text-view.h
+++ b/libempathy-gtk/empathy-chat-text-view.h
@@ -70,7 +70,7 @@ struct _EmpathyChatTextViewClass {
GType empathy_chat_text_view_get_type (void) G_GNUC_CONST;
EmpathyContact * empathy_chat_text_view_get_last_contact (EmpathyChatTextView *view);
-time_t empathy_chat_text_view_get_last_timestamp (EmpathyChatTextView *view);
+gint64 empathy_chat_text_view_get_last_timestamp (EmpathyChatTextView *view);
void empathy_chat_text_view_set_only_if_date (EmpathyChatTextView *view,
gboolean only_if_date);
void empathy_chat_text_view_append_body (EmpathyChatTextView *view,
diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c
index e25c8ff6f..ee18be657 100644
--- a/libempathy-gtk/empathy-chat.c
+++ b/libempathy-gtk/empathy-chat.c
@@ -815,10 +815,35 @@ chat_command_me (EmpathyChat *chat,
GStrv strv)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- EmpathyMessage *message;
+ TpMessage *message;
+ TpChannel *channel;
+
+ channel = empathy_tp_chat_get_channel (priv->tp_chat);
+
+ /* Strictly speaking we don't depend yet on Messages so best to check that
+ * the channel is actually a TpTextChannel before casting it. */
+ if (TP_IS_TEXT_CHANNEL (channel) &&
+ !tp_text_channel_supports_message_type (TP_TEXT_CHANNEL (channel),
+ TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION)) {
+ /* Action message are not supported, 'simulate' the action */
+ EmpathyContact *self_contact;
+ gchar *tmp;
+
+ self_contact = empathy_tp_chat_get_self_contact (priv->tp_chat);
+ /* The TpChat can't be ready if it doesn't have the self contact */
+ g_assert (self_contact != NULL);
+
+ tmp = g_strdup_printf ("%s %s", empathy_contact_get_alias (self_contact),
+ strv[1]);
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ tmp);
+ g_free (tmp);
+ }
+ else {
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION,
+ strv[1]);
+ }
- message = empathy_message_new (strv[1]);
- empathy_message_set_tptype (message, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION);
empathy_tp_chat_send (priv->tp_chat, message);
g_object_unref (message);
}
@@ -828,9 +853,10 @@ chat_command_say (EmpathyChat *chat,
GStrv strv)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- EmpathyMessage *message;
+ TpMessage *message;
- message = empathy_message_new (strv[1]);
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ strv[1]);
empathy_tp_chat_send (priv->tp_chat, message);
g_object_unref (message);
}
@@ -979,7 +1005,7 @@ chat_send (EmpathyChat *chat,
const gchar *msg)
{
EmpathyChatPriv *priv;
- EmpathyMessage *message;
+ TpMessage *message;
guint i;
if (EMP_STR_EMPTY (msg)) {
@@ -1044,7 +1070,8 @@ chat_send (EmpathyChat *chat,
}
}
- message = empathy_message_new (msg);
+ message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
+ msg);
empathy_tp_chat_send (priv->tp_chat, message);
g_object_unref (message);
}
@@ -1198,9 +1225,14 @@ chat_send_error_cb (EmpathyTpChat *tp_chat,
break;
}
- str = g_strdup_printf (_("Error sending message '%s': %s"),
- message_body,
- error);
+ if (message_body != NULL) {
+ str = g_strdup_printf (_("Error sending message '%s': %s"),
+ message_body, error);
+ }
+ else {
+ str = g_strdup_printf (_("Error sending message: %s"), error);
+ }
+
empathy_chat_view_append_event (chat->view, str);
g_free (str);
}
diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c
index 61e04560e..93ab9d510 100644
--- a/libempathy-gtk/empathy-contact-widget.c
+++ b/libempathy-gtk/empathy-contact-widget.c
@@ -724,13 +724,11 @@ contact_widget_location_update (EmpathyContactWidget *information)
gchar *user_date;
gchar *text;
gint64 stamp;
- time_t time_;
gchar *tmp;
stamp = g_value_get_int64 (value);
- time_ = stamp;
- user_date = empathy_time_to_string_relative (time_);
+ user_date = empathy_time_to_string_relative (stamp);
tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
/* translators: format is "Location, $date" */
@@ -783,7 +781,7 @@ contact_widget_location_update (EmpathyContactWidget *information)
}
else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
{
- time_t time_;
+ gint64 time_;
time_ = g_value_get_int64 (value);
svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
diff --git a/libempathy-gtk/empathy-individual-widget.c b/libempathy-gtk/empathy-individual-widget.c
index ed5e3be6f..b2020fc6c 100644
--- a/libempathy-gtk/empathy-individual-widget.c
+++ b/libempathy-gtk/empathy-individual-widget.c
@@ -588,13 +588,11 @@ location_update (EmpathyIndividualWidget *self)
gchar *user_date;
gchar *text;
gint64 stamp;
- time_t time_;
gchar *tmp;
stamp = g_value_get_int64 (value);
- time_ = stamp;
- user_date = empathy_time_to_string_relative (time_);
+ user_date = empathy_time_to_string_relative (stamp);
tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
/* translators: format is "Location, $date" */
@@ -644,7 +642,7 @@ location_update (EmpathyIndividualWidget *self)
}
else if (G_VALUE_TYPE (gvalue) == G_TYPE_INT64)
{
- time_t time_;
+ gint64 time_;
time_ = g_value_get_int64 (value);
svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
diff --git a/libempathy-gtk/empathy-location-manager.c b/libempathy-gtk/empathy-location-manager.c
index 1c09c358c..8f64e325f 100644
--- a/libempathy-gtk/empathy-location-manager.c
+++ b/libempathy-gtk/empathy-location-manager.c
@@ -39,6 +39,7 @@
#include "libempathy/empathy-gsettings.h"
#include "libempathy/empathy-location.h"
#include "libempathy/empathy-utils.h"
+#include "libempathy/empathy-time.h"
#define DEBUG_FLAG EMPATHY_DEBUG_LOCATION
#include "libempathy/empathy-debug.h"
@@ -322,16 +323,15 @@ static void
update_timestamp (EmpathyLocationManager *self)
{
EmpathyLocationManagerPriv *priv= GET_PRIV (self);
+ gint64 timestamp;
GValue *new_value;
- gint64 stamp64;
- time_t timestamp;
- timestamp = time (NULL);
- stamp64 = (gint64) timestamp;
- new_value = tp_g_value_slice_new_int64 (stamp64);
+ timestamp = empathy_time_get_current ();
+ new_value = tp_g_value_slice_new_int64 (timestamp);
g_hash_table_insert (priv->location, g_strdup (EMPATHY_LOCATION_TIMESTAMP),
new_value);
- DEBUG ("\t - Timestamp: %" G_GINT64_FORMAT, stamp64);
+
+ DEBUG ("\t - Timestamp: %" G_GINT64_FORMAT, timestamp);
}
static void
diff --git a/libempathy-gtk/empathy-theme-adium.c b/libempathy-gtk/empathy-theme-adium.c
index b2f759e30..2569e7faf 100644
--- a/libempathy-gtk/empathy-theme-adium.c
+++ b/libempathy-gtk/empathy-theme-adium.c
@@ -59,7 +59,7 @@ typedef struct {
EmpathyAdiumData *data;
EmpathySmileyManager *smiley_manager;
EmpathyContact *last_contact;
- time_t last_timestamp;
+ gint64 last_timestamp;
gboolean last_is_backlog;
guint pages_loading;
GList *message_queue;
@@ -324,7 +324,7 @@ theme_adium_append_html (EmpathyThemeAdium *theme,
const gchar *contact_id,
const gchar *service_name,
const gchar *message_classes,
- time_t timestamp,
+ gint64 timestamp,
gboolean is_backlog)
{
GString *string;
@@ -442,7 +442,7 @@ theme_adium_append_message (EmpathyChatView *view,
const gchar *contact_id;
EmpathyAvatar *avatar;
const gchar *avatar_filename = NULL;
- time_t timestamp;
+ gint64 timestamp;
gchar *html = NULL;
gsize len = 0;
const gchar *func;
diff --git a/libempathy-gtk/empathy-theme-boxes.c b/libempathy-gtk/empathy-theme-boxes.c
index bf97f3f97..c0377b6ae 100644
--- a/libempathy-gtk/empathy-theme-boxes.c
+++ b/libempathy-gtk/empathy-theme-boxes.c
@@ -196,7 +196,7 @@ theme_boxes_maybe_append_header (EmpathyThemeBoxes *theme,
GtkTextChildAnchor *anchor;
GtkWidget *box;
gchar *str;
- time_t time_;
+ gint64 time_;
gchar *tmp;
GtkTextIter start;
gboolean color_set;
diff --git a/libempathy/empathy-ft-handler.c b/libempathy/empathy-ft-handler.c
index 94b9cf3d4..26db91b07 100644
--- a/libempathy/empathy-ft-handler.c
+++ b/libempathy/empathy-ft-handler.c
@@ -144,7 +144,7 @@ typedef struct {
/* time and speed */
gdouble speed;
guint remaining_time;
- time_t last_update_time;
+ gint64 last_update_time;
gboolean is_completed;
} EmpathyFTHandlerPriv;
@@ -662,7 +662,7 @@ update_remaining_time_and_speed (EmpathyFTHandler *handler,
guint64 transferred_bytes)
{
EmpathyFTHandlerPriv *priv = GET_PRIV (handler);
- time_t elapsed_time, current_time;
+ gint64 elapsed_time, current_time;
guint64 transferred, last_transferred_bytes;
gdouble speed;
gint remaining_time;
diff --git a/libempathy/empathy-message.c b/libempathy/empathy-message.c
index 65ea2ae40..076a10053 100644
--- a/libempathy/empathy-message.c
+++ b/libempathy/empathy-message.c
@@ -44,7 +44,7 @@ typedef struct {
EmpathyContact *sender;
EmpathyContact *receiver;
gchar *body;
- time_t timestamp;
+ gint64 timestamp;
gboolean is_backlog;
guint id;
gboolean incoming;
@@ -93,44 +93,46 @@ empathy_message_class_init (EmpathyMessageClass *class)
TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
TP_CHANNEL_TEXT_MESSAGE_TYPE_AUTO_REPLY,
TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
- G_PARAM_READWRITE));
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+ G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_SENDER,
g_param_spec_object ("sender",
"Message Sender",
"The sender of the message",
EMPATHY_TYPE_CONTACT,
- G_PARAM_READWRITE));
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class,
PROP_RECEIVER,
g_param_spec_object ("receiver",
"Message Receiver",
"The receiver of the message",
EMPATHY_TYPE_CONTACT,
- G_PARAM_READWRITE));
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class,
PROP_BODY,
g_param_spec_string ("body",
"Message Body",
"The content of the message",
NULL,
- G_PARAM_READWRITE));
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+ G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_TIMESTAMP,
- g_param_spec_long ("timestamp",
+ g_param_spec_int64 ("timestamp",
"timestamp",
"timestamp",
- -1,
- G_MAXLONG,
- -1,
- G_PARAM_READWRITE));
+ 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",
"History message",
"If the message belongs to history",
FALSE,
- G_PARAM_READWRITE));
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+ G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
@@ -139,7 +141,8 @@ empathy_message_class_init (EmpathyMessageClass *class)
"Incoming",
"If this is an incoming (as opposed to sent) message",
FALSE,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+ G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_FLAGS,
@@ -147,7 +150,8 @@ empathy_message_class_init (EmpathyMessageClass *class)
"Flags",
"The TpChannelTextMessageFlags of this message",
0, G_MAXUINT, 0,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
+ G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (object_class, sizeof (EmpathyMessagePriv));
@@ -205,9 +209,18 @@ message_get_property (GObject *object,
case PROP_BODY:
g_value_set_string (value, priv->body);
break;
+ case PROP_TIMESTAMP:
+ g_value_set_int64 (value, priv->timestamp);
+ break;
+ case PROP_IS_BACKLOG:
+ g_value_set_boolean (value, priv->is_backlog);
+ break;
case PROP_INCOMING:
g_value_set_boolean (value, priv->incoming);
break;
+ case PROP_FLAGS:
+ g_value_set_uint (value, priv->flags);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -226,8 +239,7 @@ message_set_property (GObject *object,
switch (param_id) {
case PROP_TYPE:
- empathy_message_set_tptype (EMPATHY_MESSAGE (object),
- g_value_get_uint (value));
+ priv->type = g_value_get_uint (value);
break;
case PROP_SENDER:
empathy_message_set_sender (EMPATHY_MESSAGE (object),
@@ -238,12 +250,23 @@ message_set_property (GObject *object,
EMPATHY_CONTACT (g_value_get_object (value)));
break;
case PROP_BODY:
- empathy_message_set_body (EMPATHY_MESSAGE (object),
- g_value_get_string (value));
+ g_assert (priv->body == NULL); /* construct only */
+ priv->body = g_value_dup_string (value);
+ break;
+ case PROP_TIMESTAMP:
+ priv->timestamp = g_value_get_int64 (value);
+ if (priv->timestamp <= 0)
+ priv->timestamp = empathy_time_get_current ();
+ break;
+ case PROP_IS_BACKLOG:
+ priv->is_backlog = g_value_get_boolean (value);
break;
case PROP_INCOMING:
priv->incoming = g_value_get_boolean (value);
break;
+ case PROP_FLAGS:
+ priv->flags = g_value_get_uint (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -251,14 +274,6 @@ message_set_property (GObject *object,
}
EmpathyMessage *
-empathy_message_new (const gchar *body)
-{
- return g_object_new (EMPATHY_TYPE_MESSAGE,
- "body", body,
- NULL);
-}
-
-EmpathyMessage *
empathy_message_from_tpl_log_event (TplEvent *logevent)
{
EmpathyMessage *retval = NULL;
@@ -303,7 +318,13 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
receiver = tpl_event_get_receiver (logevent);
sender = tpl_event_get_sender (logevent);
- retval = empathy_message_new (body);
+ retval = g_object_new (EMPATHY_TYPE_MESSAGE,
+ "type", tpl_text_event_get_message_type (TPL_TEXT_EVENT (logevent)),
+ "body", body,
+ "is-backlog", TRUE,
+ "timestamp", tpl_event_get_timestamp (logevent),
+ NULL);
+
if (receiver != NULL) {
contact = empathy_contact_from_tpl_contact (account, receiver);
empathy_message_set_receiver (retval, contact);
@@ -316,12 +337,6 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
g_object_unref (contact);
}
- empathy_message_set_timestamp (retval,
- tpl_event_get_timestamp (logevent));
- empathy_message_set_tptype (retval,
- tpl_text_event_get_message_type (TPL_TEXT_EVENT (logevent)));
- empathy_message_set_is_backlog (retval, TRUE);
-
g_free (body);
return retval;
@@ -340,21 +355,6 @@ empathy_message_get_tptype (EmpathyMessage *message)
return priv->type;
}
-void
-empathy_message_set_tptype (EmpathyMessage *message,
- TpChannelTextMessageType type)
-{
- EmpathyMessagePriv *priv;
-
- g_return_if_fail (EMPATHY_IS_MESSAGE (message));
-
- priv = GET_PRIV (message);
-
- priv->type = type;
-
- g_object_notify (G_OBJECT (message), "type");
-}
-
EmpathyContact *
empathy_message_get_sender (EmpathyMessage *message)
{
@@ -433,26 +433,7 @@ empathy_message_get_body (EmpathyMessage *message)
return priv->body;
}
-void
-empathy_message_set_body (EmpathyMessage *message,
- const gchar *body)
-{
- EmpathyMessagePriv *priv = GET_PRIV (message);
-
- g_return_if_fail (EMPATHY_IS_MESSAGE (message));
-
- g_free (priv->body);
-
- if (body) {
- priv->body = g_strdup (body);
- } else {
- priv->body = NULL;
- }
-
- g_object_notify (G_OBJECT (message), "body");
-}
-
-time_t
+gint64
empathy_message_get_timestamp (EmpathyMessage *message)
{
EmpathyMessagePriv *priv;
@@ -464,26 +445,6 @@ empathy_message_get_timestamp (EmpathyMessage *message)
return priv->timestamp;
}
-void
-empathy_message_set_timestamp (EmpathyMessage *message,
- time_t timestamp)
-{
- EmpathyMessagePriv *priv;
-
- g_return_if_fail (EMPATHY_IS_MESSAGE (message));
- g_return_if_fail (timestamp >= -1);
-
- priv = GET_PRIV (message);
-
- if (timestamp <= 0) {
- priv->timestamp = empathy_time_get_current ();
- } else {
- priv->timestamp = timestamp;
- }
-
- g_object_notify (G_OBJECT (message), "timestamp");
-}
-
gboolean
empathy_message_is_backlog (EmpathyMessage *message)
{
@@ -496,21 +457,6 @@ empathy_message_is_backlog (EmpathyMessage *message)
return priv->is_backlog;
}
-void
-empathy_message_set_is_backlog (EmpathyMessage *message,
- gboolean is_backlog)
-{
- EmpathyMessagePriv *priv;
-
- g_return_if_fail (EMPATHY_IS_MESSAGE (message));
-
- priv = GET_PRIV (message);
-
- priv->is_backlog = is_backlog;
-
- g_object_notify (G_OBJECT (message), "is-backlog");
-}
-
#define IS_SEPARATOR(ch) (ch == ' ' || ch == ',' || ch == '.' || ch == ':')
gboolean
empathy_message_should_highlight (EmpathyMessage *message)
@@ -627,28 +573,6 @@ empathy_message_get_id (EmpathyMessage *message)
return priv->id;
}
-void
-empathy_message_set_id (EmpathyMessage *message, guint id)
-{
- EmpathyMessagePriv *priv = GET_PRIV (message);
-
- priv->id = id;
-}
-
-void
-empathy_message_set_incoming (EmpathyMessage *message, gboolean incoming)
-{
- EmpathyMessagePriv *priv;
-
- g_return_if_fail (EMPATHY_IS_MESSAGE (message));
-
- priv = GET_PRIV (message);
-
- priv->incoming = incoming;
-
- g_object_notify (G_OBJECT (message), "incoming");
-}
-
gboolean
empathy_message_is_incoming (EmpathyMessage *message)
{
@@ -689,17 +613,38 @@ empathy_message_get_flags (EmpathyMessage *self)
return priv->flags;
}
-void
-empathy_message_set_flags (EmpathyMessage *self,
- TpChannelTextMessageFlags flags)
+EmpathyMessage *
+empathy_message_new_from_tp_message (TpMessage *tp_msg,
+ gboolean incoming)
{
+ EmpathyMessage *message;
EmpathyMessagePriv *priv;
+ gchar *body;
+ TpChannelTextMessageFlags flags;
+ guint id;
+
+ g_return_val_if_fail (TP_IS_MESSAGE (tp_msg), NULL);
- g_return_if_fail (EMPATHY_IS_MESSAGE (self));
+ body = tp_message_to_text (tp_msg, &flags);
- priv = GET_PRIV (self);
+ message = g_object_new (EMPATHY_TYPE_MESSAGE,
+ "body", body,
+ "type", tp_message_get_message_type (tp_msg),
+ "timestamp", tp_message_get_received_timestamp (tp_msg),
+ "flags", flags,
+ "is-backlog", flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK,
+ "incoming", incoming,
+ NULL);
- priv->flags = flags;
+ priv = GET_PRIV (message);
+
+ /* FIXME: this is pretty low level, ideally we shouldn't have to use the
+ * ID directly but we don't use TpTextChannel's ack API everywhere yet. */
+ id = tp_asv_get_uint32 (tp_message_peek (tp_msg, 0),
+ "pending-message-id", NULL);
- g_object_notify (G_OBJECT (self), "flags");
+ priv->id = id;
+
+ g_free (body);
+ return message;
}
diff --git a/libempathy/empathy-message.h b/libempathy/empathy-message.h
index 1db0eff60..7508cb08e 100644
--- a/libempathy/empathy-message.h
+++ b/libempathy/empathy-message.h
@@ -26,6 +26,7 @@
#define __EMPATHY_MESSAGE_H__
#include <glib-object.h>
+#include <telepathy-glib/message.h>
#include <telepathy-logger/event.h>
#include "empathy-contact.h"
@@ -53,11 +54,12 @@ struct _EmpathyMessageClass {
};
GType empathy_message_get_type (void) G_GNUC_CONST;
-EmpathyMessage * empathy_message_new (const gchar *body);
+
EmpathyMessage * empathy_message_from_tpl_log_event (TplEvent *logevent);
+EmpathyMessage * empathy_message_new_from_tp_message (TpMessage *tp_msg,
+ gboolean incoming);
+
TpChannelTextMessageType empathy_message_get_tptype (EmpathyMessage *message);
-void empathy_message_set_tptype (EmpathyMessage *message,
- TpChannelTextMessageType type);
EmpathyContact * empathy_message_get_sender (EmpathyMessage *message);
void empathy_message_set_sender (EmpathyMessage *message,
EmpathyContact *contact);
@@ -65,30 +67,19 @@ EmpathyContact * empathy_message_get_receiver (EmpathyMessage
void empathy_message_set_receiver (EmpathyMessage *message,
EmpathyContact *contact);
const gchar * empathy_message_get_body (EmpathyMessage *message);
-void empathy_message_set_body (EmpathyMessage *message,
- const gchar *body);
-time_t empathy_message_get_timestamp (EmpathyMessage *message);
-void empathy_message_set_timestamp (EmpathyMessage *message,
- time_t timestamp);
+gint64 empathy_message_get_timestamp (EmpathyMessage *message);
gboolean empathy_message_is_backlog (EmpathyMessage *message);
-void empathy_message_set_is_backlog (EmpathyMessage *message,
- gboolean is_backlog);
gboolean empathy_message_is_incoming (EmpathyMessage *message);
-void empathy_message_set_incoming (EmpathyMessage *message,
- gboolean incoming);
gboolean empathy_message_should_highlight (EmpathyMessage *message);
TpChannelTextMessageType empathy_message_type_from_str (const gchar *type_str);
const gchar * empathy_message_type_to_str (TpChannelTextMessageType type);
guint empathy_message_get_id (EmpathyMessage *message);
-void empathy_message_set_id (EmpathyMessage *message, guint id);
gboolean empathy_message_equal (EmpathyMessage *message1, EmpathyMessage *message2);
TpChannelTextMessageFlags empathy_message_get_flags (EmpathyMessage *message);
-void empathy_message_set_flags (EmpathyMessage *message,
- TpChannelTextMessageFlags flags);
G_END_DECLS
diff --git a/libempathy/empathy-time.c b/libempathy/empathy-time.c
index 13e17d152..f33152d97 100644
--- a/libempathy/empathy-time.c
+++ b/libempathy/empathy-time.c
@@ -31,139 +31,107 @@
/* Note: EmpathyTime is always in UTC. */
-time_t
+gint64
empathy_time_get_current (void)
{
- return time (NULL);
-}
-
-time_t
-empathy_time_get_local_time (struct tm *tm)
-{
- const gchar *tz;
- time_t t;
-
- tz = g_getenv ("TZ");
- g_setenv ("TZ", "", TRUE);
-
- tzset ();
-
- t = mktime (tm);
+ GDateTime *now;
+ gint64 result;
- if (tz) {
- g_setenv ("TZ", tz, TRUE);
- } else {
- g_unsetenv ("TZ");
- }
-
- tzset ();
+ now = g_date_time_new_now_utc ();
+ result = g_date_time_to_unix (now);
+ g_date_time_unref (now);
- return t;
-}
-
-/* The format is: "20021209T23:51:30" and is in UTC. 0 is returned on
- * failure. The alternative format "20021209" is also accepted.
- */
-time_t
-empathy_time_parse (const gchar *str)
-{
- struct tm tm;
- gint year, month;
- gint n_parsed;
-
- memset (&tm, 0, sizeof (struct tm));
-
- n_parsed = sscanf (str, "%4d%2d%2dT%2d:%2d:%2d",
- &year, &month, &tm.tm_mday, &tm.tm_hour,
- &tm.tm_min, &tm.tm_sec);
- if (n_parsed != 3 && n_parsed != 6) {
- return 0;
- }
-
- tm.tm_year = year - 1900;
- tm.tm_mon = month - 1;
- tm.tm_isdst = -1;
-
- return empathy_time_get_local_time (&tm);
+ return result;
}
/* Converts the UTC timestamp to a string, also in UTC. Returns NULL on failure. */
gchar *
-empathy_time_to_string_utc (time_t t,
+empathy_time_to_string_utc (gint64 t,
const gchar *format)
{
- gchar stamp[128];
- struct tm *tm;
+ GDateTime *d;
+ char *result;
g_return_val_if_fail (format != NULL, NULL);
- tm = gmtime (&t);
- if (strftime (stamp, sizeof (stamp), format, tm) == 0) {
- return NULL;
- }
+ d = g_date_time_new_from_unix_utc (t);
+ result = g_date_time_format (d, format);
+ g_date_time_unref (d);
- return g_strdup (stamp);
+ return result;
}
/* Converts the UTC timestamp to a string, in local time. Returns NULL on failure. */
gchar *
-empathy_time_to_string_local (time_t t,
+empathy_time_to_string_local (gint64 t,
const gchar *format)
{
- gchar stamp[128];
- struct tm *tm;
+ GDateTime *d, *local;
+ gchar *result;
g_return_val_if_fail (format != NULL, NULL);
- tm = localtime (&t);
- if (strftime (stamp, sizeof (stamp), format, tm) == 0) {
- return NULL;
- }
+ d = g_date_time_new_from_unix_utc (t);
+ local = g_date_time_to_local (d);
+ g_date_time_unref (d);
+
+ result = g_date_time_format (local, format);
+ g_date_time_unref (local);
- return g_strdup (stamp);
+ return result;
}
gchar *
-empathy_time_to_string_relative (time_t then)
+empathy_time_to_string_relative (gint64 t)
{
- time_t now;
+ GDateTime *now, *then;
gint seconds;
+ GTimeSpan delta;
+ gchar *result;
+
+ now = g_date_time_new_now_utc ();
+ then = g_date_time_new_from_unix_utc (t);
- now = time (NULL);
- seconds = now - then;
+ delta = g_date_time_difference (now, then);
+ seconds = delta / G_TIME_SPAN_SECOND;
if (seconds > 0) {
if (seconds < 60) {
- return g_strdup_printf (ngettext ("%d second ago",
+ result = g_strdup_printf (ngettext ("%d second ago",
"%d seconds ago", seconds), seconds);
}
else if (seconds < (60 * 60)) {
seconds /= 60;
- return g_strdup_printf (ngettext ("%d minute ago",
+ result = g_strdup_printf (ngettext ("%d minute ago",
"%d minutes ago", seconds), seconds);
}
else if (seconds < (60 * 60 * 24)) {
seconds /= 60 * 60;
- return g_strdup_printf (ngettext ("%d hour ago",
+ result = g_strdup_printf (ngettext ("%d hour ago",
"%d hours ago", seconds), seconds);
}
else if (seconds < (60 * 60 * 24 * 7)) {
seconds /= 60 * 60 * 24;
- return g_strdup_printf (ngettext ("%d day ago",
+ result = g_strdup_printf (ngettext ("%d day ago",
"%d days ago", seconds), seconds);
}
else if (seconds < (60 * 60 * 24 * 30)) {
seconds /= 60 * 60 * 24 * 7;
- return g_strdup_printf (ngettext ("%d week ago",
+ result = g_strdup_printf (ngettext ("%d week ago",
"%d weeks ago", seconds), seconds);
}
else {
seconds /= 60 * 60 * 24 * 30;
- return g_strdup_printf (ngettext ("%d month ago",
+ result = g_strdup_printf (ngettext ("%d month ago",
"%d months ago", seconds), seconds);
}
}
else {
- return g_strdup (_("in the future"));
+ result = g_strdup (_("in the future"));
}
+
+ g_date_time_unref (now);
+ g_date_time_unref (then);
+
+ return result;
}
diff --git a/libempathy/empathy-time.h b/libempathy/empathy-time.h
index 65e0127c7..7fac48221 100644
--- a/libempathy/empathy-time.h
+++ b/libempathy/empathy-time.h
@@ -39,14 +39,12 @@ G_BEGIN_DECLS
#define EMPATHY_DATE_FORMAT_DISPLAY_SHORT _("%a %d %b %Y")
#define EMPATHY_TIME_DATE_FORMAT_DISPLAY_SHORT _("%a %d %b %Y, %H:%M")
-time_t empathy_time_get_current (void);
-time_t empathy_time_get_local_time (struct tm *tm);
-time_t empathy_time_parse (const gchar *str);
-gchar *empathy_time_to_string_utc (time_t t,
+gint64 empathy_time_get_current (void);
+gchar *empathy_time_to_string_utc (gint64 t,
const gchar *format);
-gchar *empathy_time_to_string_local (time_t t,
+gchar *empathy_time_to_string_local (gint64 t,
const gchar *format);
-gchar *empathy_time_to_string_relative (time_t t);
+gchar *empathy_time_to_string_relative (gint64 t);
G_END_DECLS
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index da3ac663a..e829d6e6b 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -47,7 +47,6 @@ typedef struct {
EmpathyContact *remote_contact;
GList *members;
TpChannel *channel;
- gboolean listing_pending_messages;
/* Queue of messages not signalled yet */
GQueue *messages_queue;
/* Queue of messages signalled but not acked yet */
@@ -283,149 +282,176 @@ tp_chat_got_sender_cb (TpConnection *connection,
static void
tp_chat_build_message (EmpathyTpChat *chat,
- gboolean incoming,
- guint id,
- guint type,
- guint timestamp,
- guint from_handle,
- const gchar *message_body,
- TpChannelTextMessageFlags flags)
+ TpMessage *msg,
+ gboolean incoming)
{
EmpathyTpChatPriv *priv;
EmpathyMessage *message;
+ TpContact *sender;
priv = GET_PRIV (chat);
- message = empathy_message_new (message_body);
- empathy_message_set_tptype (message, type);
+ message = empathy_message_new_from_tp_message (msg, incoming);
+ /* FIXME: this is actually a lie for incoming messages. */
empathy_message_set_receiver (message, priv->user);
- empathy_message_set_timestamp (message, timestamp);
- empathy_message_set_id (message, id);
- empathy_message_set_incoming (message, incoming);
- empathy_message_set_flags (message, flags);
-
- if (flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK)
- empathy_message_set_is_backlog (message, TRUE);
g_queue_push_tail (priv->messages_queue, message);
- if (from_handle == 0) {
+ sender = tp_signalled_message_get_sender (msg);
+ g_assert (sender != NULL);
+
+ if (tp_contact_get_handle (sender) == 0) {
empathy_message_set_sender (message, priv->user);
tp_chat_emit_queued_messages (chat);
} else {
empathy_tp_contact_factory_get_from_handle (priv->connection,
- from_handle,
+ tp_contact_get_handle (sender),
tp_chat_got_sender_cb,
message, NULL, G_OBJECT (chat));
}
}
static void
-tp_chat_received_cb (TpChannel *channel,
- guint message_id,
- guint timestamp,
- guint from_handle,
- guint message_type,
- guint message_flags,
- const gchar *message_body,
- gpointer user_data,
- GObject *chat_)
-{
- EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
- EmpathyTpChatPriv *priv = GET_PRIV (chat);
+handle_delivery_report (EmpathyTpChat *self,
+ TpMessage *message)
+{
+ EmpathyTpChatPriv *priv = GET_PRIV (self);
+ TpDeliveryStatus delivery_status;
+ const GHashTable *header;
+ TpChannelTextSendError delivery_error;
+ gboolean valid;
+ GPtrArray *echo;
+ const gchar *message_body = NULL;
+
+ header = tp_message_peek (message, 0);
+ if (header == NULL)
+ goto out;
- if (priv->channel == NULL)
- return;
+ delivery_status = tp_asv_get_uint32 (header, "delivery-status", &valid);
+ if (!valid || delivery_status != TP_DELIVERY_STATUS_PERMANENTLY_FAILED)
+ goto out;
+
+ delivery_error = tp_asv_get_uint32 (header, "delivery-error", &valid);
+ if (!valid)
+ delivery_error = TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN;
+
+ /* TODO: ideally we should use tp-glib API giving us the echoed message as a
+ * TpMessage. (fdo #35884) */
+ echo = tp_asv_get_boxed (header, "delivery-echo",
+ TP_ARRAY_TYPE_MESSAGE_PART_LIST);
+ if (echo != NULL && echo->len >= 1) {
+ const GHashTable *echo_body;
+
+ echo_body = g_ptr_array_index (echo, 1);
+ if (echo_body != NULL)
+ message_body = tp_asv_get_string (echo_body, "content");
+ }
+
+ g_signal_emit (self, signals[SEND_ERROR], 0, message_body, delivery_error);
+
+out:
+ tp_text_channel_ack_message_async (TP_TEXT_CHANNEL (priv->channel),
+ message, NULL, NULL);
+}
+
+static void
+handle_incoming_message (EmpathyTpChat *self,
+ TpMessage *message,
+ gboolean pending)
+{
+ EmpathyTpChatPriv *priv = GET_PRIV (self);
+ gchar *message_body;
- if (priv->listing_pending_messages) {
+ if (tp_message_is_delivery_report (message)) {
+ handle_delivery_report (self, message);
return;
}
- DEBUG ("Message received from channel %s: %s",
- tp_proxy_get_object_path (channel), message_body);
+ message_body = tp_message_to_text (message, NULL);
- if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
- !tp_strdiff (message_body, "")) {
- GArray *ids;
+ DEBUG ("Message %s (channel %s): %s",
+ pending ? "pending" : "received",
+ tp_proxy_get_object_path (priv->channel), message_body);
+ if (message_body == NULL) {
DEBUG ("Empty message with NonTextContent, ignoring and acking.");
- ids = g_array_sized_new (FALSE, FALSE, sizeof (guint), 1);
- g_array_append_val (ids, message_id);
- acknowledge_messages (chat, ids);
- g_array_free (ids, TRUE);
-
+ tp_text_channel_ack_message_async (TP_TEXT_CHANNEL (priv->channel),
+ message, NULL, NULL);
return;
}
- tp_chat_build_message (chat,
- TRUE,
- message_id,
- message_type,
- timestamp,
- from_handle,
- message_body,
- message_flags);
+ tp_chat_build_message (self, message, TRUE);
+
+ g_free (message_body);
}
static void
-tp_chat_sent_cb (TpChannel *channel,
- guint timestamp,
- guint message_type,
- const gchar *message_body,
- gpointer user_data,
- GObject *chat_)
-{
- EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
- EmpathyTpChatPriv *priv = GET_PRIV (chat);
+message_received_cb (TpTextChannel *channel,
+ TpMessage *message,
+ EmpathyTpChat *chat)
+{
+ handle_incoming_message (chat, message, FALSE);
+}
- if (priv->channel == NULL)
- return;
+static void
+message_sent_cb (TpTextChannel *channel,
+ TpMessage *message,
+ TpMessageSendingFlags flags,
+ gchar *token,
+ EmpathyTpChat *chat)
+{
+ gchar *message_body;
+
+ message_body = tp_message_to_text (message, NULL);
DEBUG ("Message sent: %s", message_body);
- tp_chat_build_message (chat,
- FALSE,
- 0,
- message_type,
- timestamp,
- 0,
- message_body,
- 0);
+ tp_chat_build_message (chat, message, FALSE);
+
+ g_free (message_body);
}
-static void
-tp_chat_send_error_cb (TpChannel *channel,
- guint error_code,
- guint timestamp,
- guint message_type,
- const gchar *message_body,
- gpointer user_data,
- GObject *chat)
+static TpChannelTextSendError
+error_to_text_send_error (GError *error)
{
- EmpathyTpChatPriv *priv = GET_PRIV (chat);
-
- if (priv->channel == NULL)
- return;
+ if (error->domain != TP_ERRORS)
+ return TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN;
- DEBUG ("Error sending '%s' (%d)", message_body, error_code);
+ switch (error->code) {
+ case TP_ERROR_OFFLINE:
+ return TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE;
+ case TP_ERROR_INVALID_HANDLE:
+ return TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT;
+ case TP_ERROR_PERMISSION_DENIED:
+ return TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED;
+ case TP_ERROR_NOT_IMPLEMENTED:
+ return TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED;
+ }
- g_signal_emit (chat, signals[SEND_ERROR], 0, message_body, error_code);
+ return TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN;
}
static void
-tp_chat_send_cb (TpChannel *proxy,
- const GError *error,
- gpointer user_data,
- GObject *chat)
+message_send_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- EmpathyMessage *message = EMPATHY_MESSAGE (user_data);
+ EmpathyTpChat *chat = user_data;
+ TpTextChannel *channel = (TpTextChannel *) source;
+ GError *error = NULL;
- if (error) {
+ if (!tp_text_channel_send_message_finish (channel, result, NULL, &error)) {
DEBUG ("Error: %s", error->message);
+
+ /* FIXME: we should use the body of the message as first argument of the
+ * signal but can't easily get it as we just get a user_data pointer. Once
+ * we'll have rebased EmpathyTpChat on top of TpTextChannel we'll be able
+ * to use the user_data pointer to pass the message and fix this. */
g_signal_emit (chat, signals[SEND_ERROR], 0,
- empathy_message_get_body (message),
- TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN);
+ NULL, error_to_text_send_error (error));
+
+ g_error_free (error);
}
}
@@ -460,86 +486,33 @@ static void
tp_chat_state_changed_cb (TpChannel *channel,
TpHandle handle,
TpChannelChatState state,
- gpointer user_data,
- GObject *chat)
+ EmpathyTpChat *chat)
{
EmpathyTpChatPriv *priv = GET_PRIV (chat);
empathy_tp_contact_factory_get_from_handle (priv->connection, handle,
tp_chat_state_changed_got_contact_cb, GUINT_TO_POINTER (state),
- NULL, chat);
+ NULL, G_OBJECT (chat));
}
static void
-tp_chat_list_pending_messages_cb (TpChannel *channel,
- const GPtrArray *messages_list,
- const GError *error,
- gpointer user_data,
- GObject *chat_)
+list_pending_messages (EmpathyTpChat *self)
{
- EmpathyTpChat *chat = EMPATHY_TP_CHAT (chat_);
- EmpathyTpChatPriv *priv = GET_PRIV (chat);
- guint i;
- GArray *empty_non_text_content_ids = NULL;
-
- priv->listing_pending_messages = FALSE;
-
- if (priv->channel == NULL)
- return;
-
- if (error) {
- DEBUG ("Error listing pending messages: %s", error->message);
- return;
- }
-
- for (i = 0; i < messages_list->len; i++) {
- GValueArray *message_struct;
- const gchar *message_body;
- guint message_id;
- guint timestamp;
- guint from_handle;
- guint message_type;
- guint message_flags;
-
- message_struct = g_ptr_array_index (messages_list, i);
-
- message_id = g_value_get_uint (g_value_array_get_nth (message_struct, 0));
- timestamp = g_value_get_uint (g_value_array_get_nth (message_struct, 1));
- from_handle = g_value_get_uint (g_value_array_get_nth (message_struct, 2));
- message_type = g_value_get_uint (g_value_array_get_nth (message_struct, 3));
- message_flags = g_value_get_uint (g_value_array_get_nth (message_struct, 4));
- message_body = g_value_get_string (g_value_array_get_nth (message_struct, 5));
-
- DEBUG ("Message pending: %s", message_body);
+ EmpathyTpChatPriv *priv = GET_PRIV (self);
+ GList *messages, *l;
- if (message_flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT &&
- !tp_strdiff (message_body, "")) {
- DEBUG ("Empty message with NonTextContent, ignoring and acking.");
+ g_assert (priv->channel != NULL);
- if (empty_non_text_content_ids == NULL) {
- empty_non_text_content_ids = g_array_new (FALSE, FALSE, sizeof (guint));
- }
+ messages = tp_text_channel_get_pending_messages (
+ TP_TEXT_CHANNEL (priv->channel));
- g_array_append_val (empty_non_text_content_ids, message_id);
- continue;
- }
+ for (l = messages; l != NULL; l = g_list_next (l)) {
+ TpMessage *message = l->data;
- tp_chat_build_message (chat,
- TRUE,
- message_id,
- message_type,
- timestamp,
- from_handle,
- message_body,
- message_flags);
+ handle_incoming_message (self, message, FALSE);
}
- if (empty_non_text_content_ids != NULL) {
- acknowledge_messages (chat, empty_non_text_content_ids);
- g_array_free (empty_non_text_content_ids, TRUE);
- }
-
- check_ready (chat);
+ g_list_free (messages);
}
static void
@@ -867,32 +840,22 @@ check_almost_ready (EmpathyTpChat *chat)
priv->remote_contact == NULL)
return;
- tp_cli_channel_type_text_connect_to_received (priv->channel,
- tp_chat_received_cb,
- NULL, NULL,
- G_OBJECT (chat), NULL);
- priv->listing_pending_messages = TRUE;
-
- /* TpChat will be ready once ListPendingMessages returned and all the messages
- * have been added to the pending messages queue. */
- tp_cli_channel_type_text_call_list_pending_messages (priv->channel, -1,
- FALSE,
- tp_chat_list_pending_messages_cb,
- NULL, NULL,
- G_OBJECT (chat));
-
- tp_cli_channel_type_text_connect_to_sent (priv->channel,
- tp_chat_sent_cb,
- NULL, NULL,
- G_OBJECT (chat), NULL);
- tp_cli_channel_type_text_connect_to_send_error (priv->channel,
- tp_chat_send_error_cb,
- NULL, NULL,
- G_OBJECT (chat), NULL);
- tp_cli_channel_interface_chat_state_connect_to_chat_state_changed (priv->channel,
- tp_chat_state_changed_cb,
- NULL, NULL,
- G_OBJECT (chat), NULL);
+ /* We use the default factory so this feature should have been prepared */
+ g_assert (tp_proxy_is_prepared (priv->channel,
+ TP_TEXT_CHANNEL_FEATURE_INCOMING_MESSAGES));
+
+ tp_g_signal_connect_object (priv->channel, "message-received",
+ G_CALLBACK (message_received_cb), chat, 0);
+
+ list_pending_messages (chat);
+
+ tp_g_signal_connect_object (priv->channel, "message-sent",
+ G_CALLBACK (message_sent_cb), chat, 0);
+
+ tp_g_signal_connect_object (priv->channel, "chat-state-changed",
+ G_CALLBACK (tp_chat_state_changed_cb), chat, 0);
+
+ check_ready (chat);
}
static void
@@ -1618,7 +1581,7 @@ empathy_tp_chat_new (TpAccount *account,
TpChannel *channel)
{
g_return_val_if_fail (TP_IS_ACCOUNT (account), NULL);
- g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL);
+ g_return_val_if_fail (TP_IS_TEXT_CHANNEL (channel), NULL);
return g_object_new (EMPATHY_TYPE_TP_CHAT,
"account", account,
@@ -1707,27 +1670,23 @@ empathy_tp_chat_is_ready (EmpathyTpChat *chat)
void
empathy_tp_chat_send (EmpathyTpChat *chat,
- EmpathyMessage *message)
+ TpMessage *message)
{
EmpathyTpChatPriv *priv = GET_PRIV (chat);
- const gchar *message_body;
- TpChannelTextMessageType message_type;
+ gchar *message_body;
g_return_if_fail (EMPATHY_IS_TP_CHAT (chat));
- g_return_if_fail (EMPATHY_IS_MESSAGE (message));
+ g_return_if_fail (TP_IS_CLIENT_MESSAGE (message));
g_return_if_fail (priv->ready);
- message_body = empathy_message_get_body (message);
- message_type = empathy_message_get_tptype (message);
+ message_body = tp_message_to_text (message, NULL);
DEBUG ("Sending message: %s", message_body);
- tp_cli_channel_type_text_call_send (priv->channel, -1,
- message_type,
- message_body,
- tp_chat_send_cb,
- g_object_ref (message),
- (GDestroyNotify) g_object_unref,
- G_OBJECT (chat));
+
+ tp_text_channel_send_message_async (TP_TEXT_CHANNEL (priv->channel),
+ message, 0, message_send_cb, chat);
+
+ g_free (message_body);
}
void
@@ -2052,3 +2011,13 @@ empathy_tp_chat_is_sms_channel (EmpathyTpChat *self)
return priv->sms_channel;
}
+
+EmpathyContact *
+empathy_tp_chat_get_self_contact (EmpathyTpChat *self)
+{
+ EmpathyTpChatPriv *priv = GET_PRIV (self);
+
+ g_return_val_if_fail (EMPATHY_IS_TP_CHAT (self), NULL);
+
+ return priv->user;
+}
diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h
index a71c81c7e..d72c30e06 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -64,12 +64,13 @@ EmpathyTpChat *empathy_tp_chat_new (TpAccount *account,
TpChannel *channel);
const gchar * empathy_tp_chat_get_id (EmpathyTpChat *chat);
EmpathyContact *empathy_tp_chat_get_remote_contact (EmpathyTpChat *chat);
+EmpathyContact *empathy_tp_chat_get_self_contact (EmpathyTpChat *chat);
TpChannel * empathy_tp_chat_get_channel (EmpathyTpChat *chat);
TpAccount * empathy_tp_chat_get_account (EmpathyTpChat *chat);
TpConnection * empathy_tp_chat_get_connection (EmpathyTpChat *chat);
gboolean empathy_tp_chat_is_ready (EmpathyTpChat *chat);
void empathy_tp_chat_send (EmpathyTpChat *chat,
- EmpathyMessage *message);
+ TpMessage *message);
void empathy_tp_chat_set_state (EmpathyTpChat *chat,
TpChannelChatState state);
void empathy_tp_chat_set_property (EmpathyTpChat *chat,
diff --git a/libempathy/empathy-tp-file.c b/libempathy/empathy-tp-file.c
index d69b2153a..3bb2dd49c 100644
--- a/libempathy/empathy-tp-file.c
+++ b/libempathy/empathy-tp-file.c
@@ -79,7 +79,7 @@ struct _EmpathyTpFilePrivate {
/* transfer properties */
gboolean incoming;
- time_t start_time;
+ gint64 start_time;
GArray *socket_address;
guint port;
guint64 offset;
diff --git a/src/empathy-chat-manager.c b/src/empathy-chat-manager.c
index 4ff6b7d30..8455001f5 100644
--- a/src/empathy-chat-manager.c
+++ b/src/empathy-chat-manager.c
@@ -216,6 +216,16 @@ handle_channels (TpSimpleHandler *handler,
TpChannel *channel = l->data;
EmpathyTpChat *tp_chat;
+ if (tp_proxy_get_invalidated (channel) != NULL)
+ continue;
+
+ if (!TP_IS_TEXT_CHANNEL (channel))
+ {
+ DEBUG ("Channel %s doesn't implement Messages; can't handle it",
+ tp_proxy_get_object_path (channel));
+ continue;
+ }
+
tp_chat = empathy_tp_chat_new (account, channel);
if (empathy_tp_chat_is_ready (tp_chat))
diff --git a/src/empathy-event-manager.c b/src/empathy-event-manager.c
index 041d22a18..e2ce0725f 100644
--- a/src/empathy-event-manager.c
+++ b/src/empathy-event-manager.c
@@ -1037,7 +1037,7 @@ approve_channels (TpSimpleApprover *approver,
channel_type = tp_channel_get_channel_type_id (channel);
- if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_TEXT)
+ if (TP_IS_TEXT_CHANNEL (channel))
{
EmpathyTpChat *tp_chat;
diff --git a/src/empathy-map-view.c b/src/empathy-map-view.c
index 31fa997c2..321fbce53 100644
--- a/src/empathy-map-view.c
+++ b/src/empathy-map-view.c
@@ -231,7 +231,7 @@ map_view_contacts_update_label (ChamplainMarker *marker)
gchar *date;
gchar *label;
GValue *gtime;
- time_t loctime;
+ gint64 loctime;
GHashTable *location;
EmpathyContact *contact;
@@ -242,18 +242,24 @@ map_view_contacts_update_label (ChamplainMarker *marker)
if (gtime != NULL)
{
- time_t now;
+ GDateTime *now, *d;
+ GTimeSpan delta;
loctime = g_value_get_int64 (gtime);
date = empathy_time_to_string_relative (loctime);
label = g_strconcat ("<b>", name, "</b>\n<small>", date, "</small>", NULL);
g_free (date);
- now = time (NULL);
+ now = g_date_time_new_now_utc ();
+ d = g_date_time_new_from_unix_utc (loctime);
+ delta = g_date_time_difference (now, d);
/* if location is older than a week */
- if (now - loctime > (60 * 60 * 24 * 7))
- clutter_actor_set_opacity (CLUTTER_ACTOR (marker), 0.75 * 255);
+ if (delta > G_TIME_SPAN_DAY * 7)
+ clutter_actor_set_opacity (marker, 0.75 * 255);
+
+ g_date_time_unref (now);
+ g_date_time_unref (d);
}
else
{