aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-04-15 21:17:07 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-04-18 19:09:49 +0800
commit2af2286eb763f631624db953679c1cba28ff91d7 (patch)
tree2a3f12afce8baf3a662e19f5612edc5de261ae06 /libempathy
parent05ab1873675c5e2a6a04c85ef976fb1067a0d743 (diff)
downloadgsoc2013-empathy-2af2286eb763f631624db953679c1cba28ff91d7.tar
gsoc2013-empathy-2af2286eb763f631624db953679c1cba28ff91d7.tar.gz
gsoc2013-empathy-2af2286eb763f631624db953679c1cba28ff91d7.tar.bz2
gsoc2013-empathy-2af2286eb763f631624db953679c1cba28ff91d7.tar.lz
gsoc2013-empathy-2af2286eb763f631624db953679c1cba28ff91d7.tar.xz
gsoc2013-empathy-2af2286eb763f631624db953679c1cba28ff91d7.tar.zst
gsoc2013-empathy-2af2286eb763f631624db953679c1cba28ff91d7.zip
factor out empathy_message_new_from_tp_message
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-message.c33
-rw-r--r--libempathy/empathy-message.h5
-rw-r--r--libempathy/empathy-tp-chat.c83
3 files changed, 53 insertions, 68 deletions
diff --git a/libempathy/empathy-message.c b/libempathy/empathy-message.c
index f98e955a0..520dbe650 100644
--- a/libempathy/empathy-message.c
+++ b/libempathy/empathy-message.c
@@ -721,3 +721,36 @@ empathy_message_set_flags (EmpathyMessage *self,
g_object_notify (G_OBJECT (self), "flags");
}
+
+EmpathyMessage *
+empathy_message_new_from_tp_message (TpMessage *tp_msg,
+ gboolean incoming)
+{
+ EmpathyMessage *message;
+ gchar *body;
+ TpChannelTextMessageFlags flags;
+ guint id;
+
+ g_return_val_if_fail (TP_IS_MESSAGE (tp_msg), NULL);
+
+ body = tp_message_to_text (tp_msg, &flags);
+
+ 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);
+
+ /* 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);
+
+ empathy_message_set_id (message, id);
+
+ g_free (body);
+ return message;
+}
diff --git a/libempathy/empathy-message.h b/libempathy/empathy-message.h
index 1db0eff60..cb57f0755 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,8 +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);
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index b21ebeb1c..eed87d90f 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -279,38 +279,30 @@ 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));
}
@@ -322,20 +314,9 @@ message_received_cb (TpTextChannel *channel,
EmpathyTpChat *chat)
{
EmpathyTpChatPriv *priv = GET_PRIV (chat);
- guint message_id;
gchar *message_body;
- TpContact *sender;
- TpHandle from_handle;
- TpChannelTextMessageFlags message_flags;
-
- message_id = tp_asv_get_uint32 (tp_message_peek (message, 0),
- "pending-message-id", NULL);
- sender = tp_signalled_message_get_sender (message);
- g_assert (sender != NULL);
- from_handle = tp_contact_get_handle (sender);
-
- message_body = tp_message_to_text (message, &message_flags);
+ message_body = tp_message_to_text (message, NULL);
DEBUG ("Message received from channel %s: %s",
tp_proxy_get_object_path (channel), message_body);
@@ -348,14 +329,7 @@ message_received_cb (TpTextChannel *channel,
return;
}
- tp_chat_build_message (chat,
- TRUE,
- message_id,
- tp_message_get_message_type (message),
- tp_message_get_received_timestamp (message),
- from_handle,
- message_body,
- message_flags);
+ tp_chat_build_message (chat, message, TRUE);
g_free (message_body);
}
@@ -373,14 +347,7 @@ message_sent_cb (TpTextChannel *channel,
DEBUG ("Message sent: %s", message_body);
- tp_chat_build_message (chat,
- FALSE,
- 0,
- tp_message_get_message_type (message),
- tp_message_get_received_timestamp (message),
- 0,
- message_body,
- 0);
+ tp_chat_build_message (chat, message, FALSE);
g_free (message_body);
}
@@ -475,21 +442,8 @@ list_pending_messages (EmpathyTpChat *self)
for (l = messages; l != NULL; l = g_list_next (l)) {
TpMessage *message = l->data;
gchar *message_body;
- guint message_id;
- guint from_handle;
- guint message_flags;
- TpContact *sender;
-
- /* 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. */
- message_id = tp_asv_get_uint32 (tp_message_peek (message, 0),
- "pending-message-id", NULL);
-
- sender = tp_signalled_message_get_sender (message);
- g_assert (sender != NULL);
- from_handle = tp_contact_get_handle (sender);
- message_body = tp_message_to_text (message, &message_flags);
+ message_body = tp_message_to_text (message, NULL);
DEBUG ("Message pending: %s", message_body);
@@ -501,14 +455,7 @@ list_pending_messages (EmpathyTpChat *self)
continue;
}
- tp_chat_build_message (self,
- TRUE,
- message_id,
- tp_message_get_message_type (message),
- tp_message_get_received_timestamp (message),
- from_handle,
- message_body,
- message_flags);
+ tp_chat_build_message (self, message, TRUE);
g_free (message_body);
}