summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2010-01-28 15:32:47 +0000
committerCosimo Alfarano <cosimo.alfarano@collabora.co.uk>2010-01-28 15:32:47 +0000
commit38342ffb98648723a62cb884adca78700c0de6b7 (patch)
treebe08031806beb27a88e1f0d0b8db5dd61b90562b
parent1623ad20ceca5f0c89d9123bcceabe1e97ca5b0a (diff)
Better handling of remote TpContact when on 1-1
* split the received signal CB in order * fixed a but introduce during refactory, registering to the obsever connection paths instead of channel paths.
-rw-r--r--telepathy-logger/channel-text.c77
-rw-r--r--telepathy-logger/observer.c8
2 files changed, 55 insertions, 30 deletions
diff --git a/telepathy-logger/channel-text.c b/telepathy-logger/channel-text.c
index 5b445fe57..0afb70a82 100644
--- a/telepathy-logger/channel-text.c
+++ b/telepathy-logger/channel-text.c
@@ -79,6 +79,10 @@ static void pendingproc_get_chatroom_id (TplActionChain *ctx);
static void _tpl_channel_text_get_chatroom_cb (TpConnection *proxy,
const gchar **out_Identifiers, const GError *error, gpointer user_data,
GObject *weak_object);
+static void pendingproc_get_my_contact (TplActionChain *ctx);
+static void pendingproc_get_remote_contact (TplActionChain *ctx);
+static void pendingproc_get_remote_handle_type (TplActionChain *ctx);
+static void keepon (TplLogEntryText *log);
/* retrieve contacts (me and remote buddy/chatroom) and set TplChannelText
@@ -184,6 +188,7 @@ pendingproc_get_my_contact (TplActionChain *ctx)
features, _tpl_channel_text_get_contact_cb, ctx, NULL, NULL);
}
+
static void
pendingproc_get_remote_handle_type (TplActionChain *ctx)
{
@@ -703,30 +708,29 @@ _channel_on_sent_signal_cb (TpChannel *proxy,
static void
_channel_on_received_signal_with_contact_cb (TpConnection *connection,
- guint n_contacts,
- TpContact *const *contacts,
- guint n_failed,
- const TpHandle *failed,
- const GError *error,
- gpointer user_data,
- GObject *weak_object)
+ guint n_contacts,
+ TpContact *const *contacts,
+ guint n_failed,
+ const TpHandle *failed,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
{
TplLogEntryText *log = TPL_LOG_ENTRY_TEXT (user_data);
- TplChannelText *tpl_text = tpl_log_entry_text_get_tpl_channel_text (log);
- GError *e = NULL;
- TplLogManager *logmanager;
- TplContact *tpl_contact_sender;
+ TplChannelText *tpl_text;
TpContact *remote;
- gchar *chat_id;
g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (log));
+ tpl_text = tpl_log_entry_text_get_tpl_channel_text (log);
+
if (error != NULL)
{
g_error ("Unrecoverable error retrieving remote contact "
"information: %s", error->message);
g_error ("Not able to log the received message: %s",
tpl_log_entry_text_get_message (log));
+ g_object_unref (log);
return;
}
@@ -736,20 +740,39 @@ _channel_on_received_signal_with_contact_cb (TpConnection *connection,
"tp_connection_get_contacts_by_handle()", n_failed);
g_error ("Not able to log the received message: %s",
tpl_log_entry_text_get_message (log));
+ g_object_unref (log);
return;
}
remote = contacts[0];
tpl_channel_text_set_remote_contact (tpl_text, remote);
- tpl_contact_sender = tpl_contact_from_tp_contact (remote);
+ keepon (log);
+}
+
+static void
+keepon (TplLogEntryText *log)
+{
+ TplChannelText *tpl_text;
+ GError *e = NULL;
+ TplLogManager *logmanager;
+ TplContact *tpl_contact_sender;
+ TpContact *remote;
+ gchar *chat_id;
+
+ g_return_if_fail (TPL_IS_LOG_ENTRY_TEXT (log));
+
+ tpl_text = tpl_log_entry_text_get_tpl_channel_text (log);
+ remote = tpl_channel_text_get_remote_contact (tpl_text);
+
+ tpl_contact_sender = tpl_contact_from_tp_contact (remote);
tpl_contact_set_contact_type (tpl_contact_sender, TPL_CONTACT_USER);
tpl_log_entry_text_set_sender (log, tpl_contact_sender);
g_message ("recvd: %s (%s): %s",
- tpl_contact_get_identifier (tpl_contact_sender),
- tpl_contact_get_alias (tpl_contact_sender),
- tpl_log_entry_text_get_message (log));
+ tpl_contact_get_identifier (tpl_contact_sender),
+ tpl_contact_get_alias (tpl_contact_sender),
+ tpl_log_entry_text_get_message (log));
/* Initialise LogStore and store the message */
@@ -790,16 +813,17 @@ _channel_on_received_signal_cb (TpChannel *proxy,
TpHandle remote_handle = (TpHandle) arg_Sender;
TplChannelText *tpl_text = TPL_CHANNEL_TEXT (user_data);
TplChannel *tpl_chan = TPL_CHANNEL (tpl_text);
+ TpConnection *tp_conn;
TpContact *me;
TplContact *tpl_contact_receiver;
TplLogEntryText *log;
- // TODO use the Message iface to check the delivery
- // notification and handle it correctly
+ /* TODO use the Message iface to check the delivery
+ notification and handle it correctly */
if (arg_Flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT)
{
- g_debug ("Non text content flag set."
- "Probably a delivery notification for a sent message."
+ g_debug ("Non text content flag set. "
+ "Probably a delivery notification for a sent message. "
"Ignoring");
return;
}
@@ -820,10 +844,15 @@ _channel_on_received_signal_cb (TpChannel *proxy,
tpl_log_entry_text_set_timestamp (log, (time_t) arg_Timestamp);
- tp_connection_get_contacts_by_handle (tp_channel_borrow_connection (
- TP_CHANNEL (tpl_chan)), 1, &remote_handle, TP_CONTACT_FEATURES_LEN,
- features, _channel_on_received_signal_with_contact_cb, log,
- g_object_unref, NULL);
+ tp_conn = tp_channel_borrow_connection (TP_CHANNEL (tpl_chan));
+ /* it's a chatroom and no contact has been pre-cached */
+ if (tpl_channel_text_get_remote_contact (tpl_text) == NULL)
+ tp_connection_get_contacts_by_handle (tp_conn, 1, &remote_handle,
+ TP_CONTACT_FEATURES_LEN, features,
+ _channel_on_received_signal_with_contact_cb, log, g_object_unref,
+ NULL);
+ else
+ keepon (log);
g_object_unref (tpl_contact_receiver);
}
diff --git a/telepathy-logger/observer.c b/telepathy-logger/observer.c
index 23c8d56d3..4519ffc87 100644
--- a/telepathy-logger/observer.c
+++ b/telepathy-logger/observer.c
@@ -397,8 +397,7 @@ tpl_observer_register_channel (TplObserver *self,
g_return_val_if_fail (glob_map != NULL, FALSE);
/* 'key' will be freed by the hash table on key removal/destruction */
- g_object_get (G_OBJECT (tp_channel_borrow_connection (
- TP_CHANNEL (channel))), "object-path", &key, NULL);
+ g_object_get (G_OBJECT (channel), "object-path", &key, NULL);
if (g_hash_table_lookup (glob_map, key) != NULL)
{
@@ -406,9 +405,7 @@ tpl_observer_register_channel (TplObserver *self,
g_hash_table_remove (glob_map, key);
}
else
- {
g_debug ("Channel path not found, registering %s", key);
- }
g_hash_table_insert (glob_map, key, channel);
@@ -429,8 +426,7 @@ tpl_observer_unregister_channel (TplObserver *self,
g_return_val_if_fail (TPL_IS_CHANNEL (channel), FALSE);
g_return_val_if_fail (glob_map != NULL, FALSE);
- g_object_get (G_OBJECT (tp_channel_borrow_connection (
- TP_CHANNEL (channel))), "object-path", &key, NULL);
+ g_object_get (G_OBJECT (channel), "object-path", &key, NULL);
g_debug ("Unregistering channel path %s", key);