From 41e57ce513df32f95f8919a236d54bef1b501311 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Thu, 26 Sep 2013 17:03:10 +0200 Subject: [PATCH 4/6] use account's normalized name instead of its account id It doesn't make sense to use the account opaque ID as 'self id'. Fix fdo#69814. --- telepathy-logger/log-store-xml.c | 42 ++++++++++++------------------------- tests/dbus/test-tpl-log-store-xml.c | 6 ++++-- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/telepathy-logger/log-store-xml.c b/telepathy-logger/log-store-xml.c index 0dd6795..b869cc4 100644 --- a/telepathy-logger/log-store-xml.c +++ b/telepathy-logger/log-store-xml.c @@ -1055,7 +1055,6 @@ parse_text_node (TplLogStoreXml *self, xmlNodePtr node, gboolean is_room, const gchar *target_id, - const gchar *self_id, TpAccount *account) { TplEvent *event; @@ -1109,8 +1108,8 @@ parse_text_node (TplLogStoreXml *self, else if (is_user) receiver = tpl_entity_new (target_id, TPL_ENTITY_CONTACT, NULL, NULL); else - receiver = tpl_entity_new (self_id, TPL_ENTITY_SELF, - tp_account_get_nickname (account), NULL); + receiver = tpl_entity_new (tp_account_get_normalized_name (account), + TPL_ENTITY_SELF, tp_account_get_nickname (account), NULL); sender = tpl_entity_new (sender_id, is_user ? TPL_ENTITY_SELF : TPL_ENTITY_CONTACT, @@ -1153,7 +1152,6 @@ parse_call_node (TplLogStoreXml *self, xmlNodePtr node, gboolean is_room, const gchar *target_id, - const gchar *self_id, TpAccount *account) { TplEvent *event; @@ -1205,8 +1203,8 @@ parse_call_node (TplLogStoreXml *self, else if (is_user) receiver = tpl_entity_new (target_id, TPL_ENTITY_CONTACT, NULL, NULL); else - receiver = tpl_entity_new (self_id, TPL_ENTITY_SELF, - tp_account_get_nickname (account), NULL); + receiver = tpl_entity_new (tp_account_get_normalized_name (account), + TPL_ENTITY_SELF, tp_account_get_nickname (account), NULL); sender = tpl_entity_new (sender_id, is_user ? TPL_ENTITY_SELF : TPL_ENTITY_CONTACT, @@ -1322,7 +1320,12 @@ event_queue_add_text_event (GQueue *events, } -/* returns a Glist of TplEvent instances */ +/* returns a Glist of TplEvent instances. + * + * @account needs to have TP_ACCOUNT_FEATURE_CORE prepared (we use + * tp_account_get_nickname() and tp_account_get_normalized_name() which rely + * on CORE being prepared). + * */ static void log_store_xml_get_events_for_file (TplLogStoreXml *self, TpAccount *account, @@ -1338,15 +1341,14 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self, gchar *dirname; gchar *tmp; gchar *target_id; - gchar *self_id; GHashTable *supersedes_links; - GError *error = NULL; guint num_events = 0; GList *index; g_return_if_fail (TPL_IS_LOG_STORE_XML (self)); g_return_if_fail (TP_IS_ACCOUNT (account)); g_return_if_fail (!TPL_STR_EMPTY (filename)); + g_return_if_fail (tp_proxy_is_prepared (account, TP_ACCOUNT_FEATURE_CORE)); DEBUG ("Attempting to parse filename:'%s'...", filename); @@ -1356,19 +1358,6 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self, return; } - /* FIXME: fdo#69814 ideally we shouldn't use the account_id as self_id */ - G_GNUC_BEGIN_IGNORE_DEPRECATIONS - if (!tp_account_parse_object_path ( - tp_proxy_get_object_path (TP_PROXY (account)), - NULL, NULL, &self_id, &error)) - { - DEBUG ("Cannot get self identifier from account: %s", - error->message); - g_error_free (error); - return; - } - G_GNUC_END_IGNORE_DEPRECATIONS - /* Create parser. */ ctxt = xmlNewParserCtxt (); @@ -1378,7 +1367,6 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self, { g_warning ("Failed to parse file:'%s'", filename); xmlFreeParserCtxt (ctxt); - g_free (self_id); return; } @@ -1388,7 +1376,6 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self, { xmlFreeDoc (doc); xmlFreeParserCtxt (ctxt); - g_free (self_id); return; } @@ -1419,8 +1406,7 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self, if (type == TPL_TYPE_TEXT_EVENT && strcmp ((const gchar *) node->name, "message") == 0) { - event = parse_text_node (self, node, is_room, target_id, self_id, - account); + event = parse_text_node (self, node, is_room, target_id, account); if (event == NULL) continue; @@ -1432,8 +1418,7 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self, else if (type == TPL_TYPE_CALL_EVENT && strcmp ((const char*) node->name, "call") == 0) { - event = parse_call_node (self, node, is_room, target_id, self_id, - account); + event = parse_call_node (self, node, is_room, target_id, account); if (event == NULL) continue; @@ -1446,7 +1431,6 @@ log_store_xml_get_events_for_file (TplLogStoreXml *self, DEBUG ("Parsed %u events", num_events); g_free (target_id); - g_free (self_id); xmlFreeDoc (doc); xmlFreeParserCtxt (ctxt); g_hash_table_unref (supersedes_links); diff --git a/tests/dbus/test-tpl-log-store-xml.c b/tests/dbus/test-tpl-log-store-xml.c index 6dd77d3..8de7bc9 100644 --- a/tests/dbus/test-tpl-log-store-xml.c +++ b/tests/dbus/test-tpl-log-store-xml.c @@ -320,7 +320,8 @@ test_add_text_event (XmlTestCaseFixture *fixture, fixture->main_loop, TP_ACCOUNT_OBJECT_PATH_BASE "idle/irc/me", &account, &account_service); - me = tpl_entity_new ("me", TPL_ENTITY_SELF, "my-alias", "my-avatar"); + me = tpl_entity_new ("bob.mcbadgers@example.com", TPL_ENTITY_SELF, + "my-alias", "my-avatar"); contact = tpl_entity_new ("contact", TPL_ENTITY_CONTACT, "contact-alias", "contact-token"); room = tpl_entity_new_from_room_id ("room"); @@ -744,7 +745,8 @@ test_add_call_event (XmlTestCaseFixture *fixture, fixture->main_loop, TP_ACCOUNT_OBJECT_PATH_BASE "gabble/jabber/me", &account, &account_service); - me = tpl_entity_new ("me", TPL_ENTITY_SELF, "my-alias", "my-avatar"); + me = tpl_entity_new ("bob.mcbadgers@example.com", TPL_ENTITY_SELF, + "my-alias", "my-avatar"); contact = tpl_entity_new ("contact", TPL_ENTITY_CONTACT, "contact-alias", "contact-token"); room = tpl_entity_new_from_room_id ("room"); -- 1.8.3.1