[next] telepathy-glib: TpChannel: move target-contact and initiator-contact as part of CORE

Xavier Claessens xclaesse at kemper.freedesktop.org
Thu May 3 12:11:33 PDT 2012


Module: telepathy-glib
Branch: next
Commit: ca7a1577264b1545414f596b427a1c1ffa19a45f
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=ca7a1577264b1545414f596b427a1c1ffa19a45f

Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date:   Thu May  3 14:21:32 2012 +0200

TpChannel: move target-contact and initiator-contact as part of CORE

---

 next-NEWS                         |    3 +
 telepathy-glib/channel-contacts.c |   34 ------------
 telepathy-glib/channel-internal.h |    1 -
 telepathy-glib/channel.c          |  105 +++++++++++++++++++++++++++++++++++--
 telepathy-glib/channel.h          |    8 ++--
 5 files changed, 107 insertions(+), 44 deletions(-)

diff --git a/next-NEWS b/next-NEWS
index 5b03cae..95917ef 100644
--- a/next-NEWS
+++ b/next-NEWS
@@ -31,3 +31,6 @@ API/Behaviour changes
  - TpAutomaticClientFactory now only has CORE features by default, other
    features must be added explicitly by the user using
    tp_client_factory_add_*_features().
+
+ - TpChannel:target-contact and TpChannel:initiator-contact are now prepared
+   as part of TP_CHANNEL_FEATURE_CORE instead of TP_CHANNEL_FEATURE_CONTACTS.
diff --git a/telepathy-glib/channel-contacts.c b/telepathy-glib/channel-contacts.c
index b882e91..178a222 100644
--- a/telepathy-glib/channel-contacts.c
+++ b/telepathy-glib/channel-contacts.c
@@ -155,34 +155,6 @@ dup_owners_table (TpChannel *self,
 }
 
 void
-_tp_channel_contacts_init (TpChannel *self)
-{
-  /* Create TpContact objects if we have them for free */
-
-  g_assert (self->priv->target_contact == NULL);
-  g_assert (self->priv->initiator_contact == NULL);
-
-  if (self->priv->handle != 0 && self->priv->identifier != NULL &&
-      self->priv->handle_type == TP_HANDLE_TYPE_CONTACT)
-    {
-      self->priv->target_contact = tp_client_factory_ensure_contact (
-          tp_proxy_get_factory (self->priv->connection), self->priv->connection,
-          self->priv->handle, self->priv->identifier);
-    }
-
-  G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-  if (tp_channel_get_initiator_handle (self) != 0 &&
-      !tp_str_empty (tp_channel_get_initiator_identifier (self)))
-    {
-      self->priv->initiator_contact = tp_client_factory_ensure_contact (
-          tp_proxy_get_factory (self->priv->connection), self->priv->connection,
-          tp_channel_get_initiator_handle (self),
-          tp_channel_get_initiator_identifier (self));
-    }
-  G_GNUC_END_IGNORE_DEPRECATIONS
-}
-
-void
 _tp_channel_contacts_group_init (TpChannel *self,
     GHashTable *identifiers)
 {
@@ -1101,12 +1073,6 @@ _tp_channel_contacts_prepare_async (TpProxy *proxy,
   contacts = g_ptr_array_new ();
 
   /* Collect all the TpContacts we have for this channel */
-  if (self->priv->target_contact != NULL)
-    g_ptr_array_add (contacts, self->priv->target_contact);
-
-  if (self->priv->initiator_contact != NULL)
-    g_ptr_array_add (contacts, self->priv->initiator_contact);
-
   if (self->priv->group_self_contact != NULL)
     g_ptr_array_add (contacts, self->priv->group_self_contact);
 
diff --git a/telepathy-glib/channel-internal.h b/telepathy-glib/channel-internal.h
index e64467d..8ede51e 100644
--- a/telepathy-glib/channel-internal.h
+++ b/telepathy-glib/channel-internal.h
@@ -111,7 +111,6 @@ void _tp_channel_get_group_properties (TpChannel *self);
 
 /* channel-contacts.c internals */
 
-void _tp_channel_contacts_init (TpChannel *self);
 void _tp_channel_contacts_group_init (TpChannel *self, GHashTable *identifiers);
 void _tp_channel_contacts_members_changed (TpChannel *self,
     const GArray *added, const GArray *removed, const GArray *local_pending,
diff --git a/telepathy-glib/channel.c b/telepathy-glib/channel.c
index 4b86322..17eb947 100644
--- a/telepathy-glib/channel.c
+++ b/telepathy-glib/channel.c
@@ -880,13 +880,102 @@ _tp_channel_prepare_connection (TpChannel *self)
 }
 
 static void
-_tp_channel_create_contacts (TpChannel *self)
+upgrade_contacts_cb (TpConnection *connection,
+    guint n_contacts,
+    TpContact * const *contacts,
+    const GError *error,
+    gpointer user_data,
+    GObject *weak_object)
 {
-  _tp_channel_contacts_init (self);
+  TpChannel *self = (TpChannel *) weak_object;
+
+  if (error != NULL)
+    {
+      _tp_channel_abort_introspection (self, "Upgrading contacts failed",
+          error);
+      return;
+    }
+
   _tp_channel_continue_introspection (self);
 }
 
 static void
+_tp_channel_create_contacts (TpChannel *self)
+{
+  GPtrArray *contacts;
+  TpHandle initiator_handle;
+  const gchar *initiator_id;
+
+  g_assert (self->priv->target_contact == NULL);
+  g_assert (self->priv->initiator_contact == NULL);
+
+  contacts = g_ptr_array_new ();
+
+  /* Create target contact */
+  if (self->priv->handle_type == TP_HANDLE_TYPE_CONTACT)
+    {
+      if (self->priv->handle == 0 || self->priv->identifier == NULL)
+        {
+          GError e = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
+              "Channel with HandleType CONTACT must have a valid handle "
+              "and identifier" };
+          _tp_channel_abort_introspection (self, e.message, &e);
+          return;
+        }
+
+      self->priv->target_contact = tp_client_factory_ensure_contact (
+          tp_proxy_get_factory (self->priv->connection), self->priv->connection,
+          self->priv->handle, self->priv->identifier);
+      g_ptr_array_add (contacts, self->priv->target_contact);
+    }
+
+  /* Create initiator contact */
+  initiator_handle = tp_asv_get_uint32 (self->priv->channel_properties,
+      TP_PROP_CHANNEL_INITIATOR_HANDLE, NULL);
+  initiator_id = tp_asv_get_string (self->priv->channel_properties,
+      TP_PROP_CHANNEL_INITIATOR_ID);
+
+  if (initiator_handle != 0 && !tp_str_empty (initiator_id))
+    {
+      self->priv->initiator_contact = tp_client_factory_ensure_contact (
+          tp_proxy_get_factory (self->priv->connection), self->priv->connection,
+          initiator_handle, initiator_id);
+      g_ptr_array_add (contacts, self->priv->initiator_contact);
+    }
+  else if ((initiator_handle == 0) != (tp_str_empty (initiator_id)))
+    {
+      GError e = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
+          "Channel must have both initiator handle and identifier, "
+          "or none of them" };
+      _tp_channel_abort_introspection (self, e.message, &e);
+      return;
+    }
+
+  /* Prepare initiator and target contacts */
+  if (contacts->len > 0)
+    {
+      GArray *features;
+
+      features = tp_client_factory_dup_contact_features (
+          tp_proxy_get_factory (self->priv->connection),
+          self->priv->connection);
+
+      tp_connection_upgrade_contacts (self->priv->connection,
+          contacts->len, (TpContact **) contacts->pdata,
+          (GQuark *) features->data,
+          upgrade_contacts_cb, NULL, NULL, (GObject *) self);
+
+      g_array_unref (features);
+    }
+  else
+    {
+      _tp_channel_continue_introspection (self);
+    }
+
+  g_ptr_array_unref (contacts);
+}
+
+static void
 tp_channel_closed_cb (TpChannel *self,
                       gpointer user_data,
                       GObject *weak_object)
@@ -1312,7 +1401,7 @@ tp_channel_class_init (TpChannelClass *klass)
    * %TRUE if this channel was created in response to a local request, such
    * as a call to tp_account_channel_request_create_channel_async(). %FALSE
    * if this channel was initiated by a remote contact
-   * (the #TpChannel:initiator-handle), or if it appeared as a side-effect
+   * (the #TpChannel:initiator-contact), or if it appeared as a side-effect
    * of some other action.
    *
    * For instance, this is %FALSE on incoming calls and file transfers,
@@ -1482,9 +1571,12 @@ tp_channel_class_init (TpChannelClass *klass)
    * other channels without a single remote contact, %NULL.
    *
    * This is not guaranteed to be set until tp_proxy_prepare_async() has
-   * finished preparing %TP_CHANNEL_FEATURE_CONTACTS; until then, it may be
+   * finished preparing %TP_CHANNEL_FEATURE_CORE; until then, it may be
    * %NULL.
    *
+   * The #TpContact object is guaranteed to have all of the features previously
+   * passed to tp_client_factory_add_contact_features() prepared.
+   *
    * Since: 0.15.6
    */
   param_spec = g_param_spec_object ("target-contact", "Target Contact",
@@ -1512,9 +1604,12 @@ tp_channel_class_init (TpChannelClass *klass)
    * side-effect of connecting to the server), this property may be %NULL.
    *
    * This is not guaranteed to be set until tp_proxy_prepare_async() has
-   * finished preparing %TP_CHANNEL_FEATURE_CONTACTS; until then, it may be
+   * finished preparing %TP_CHANNEL_FEATURE_CORE; until then, it may be
    * %NULL.
    *
+   * The #TpContact object is guaranteed to have all of the features previously
+   * passed to tp_client_factory_add_contact_features() prepared.
+   *
    * Since: 0.15.6
    */
   param_spec = g_param_spec_object ("initiator-contact", "Initiator Contact",
diff --git a/telepathy-glib/channel.h b/telepathy-glib/channel.h
index 4121544..5bc8768 100644
--- a/telepathy-glib/channel.h
+++ b/telepathy-glib/channel.h
@@ -134,6 +134,10 @@ TpHandle tp_channel_get_initiator_handle (TpChannel *self);
 _TP_DEPRECATED_IN_0_20_FOR (tp_channel_get_initiator_contact)
 const gchar * tp_channel_get_initiator_identifier (TpChannel *self);
 #endif
+_TP_AVAILABLE_IN_0_16
+TpContact *tp_channel_get_target_contact (TpChannel *self);
+_TP_AVAILABLE_IN_0_16
+TpContact *tp_channel_get_initiator_contact (TpChannel *self);
 
 #define TP_CHANNEL_FEATURE_GROUP \
   tp_channel_get_feature_quark_group ()
@@ -180,10 +184,6 @@ _TP_AVAILABLE_IN_0_16
 GQuark tp_channel_get_feature_quark_contacts (void) G_GNUC_CONST;
 
 _TP_AVAILABLE_IN_0_16
-TpContact *tp_channel_get_target_contact (TpChannel *self);
-_TP_AVAILABLE_IN_0_16
-TpContact *tp_channel_get_initiator_contact (TpChannel *self);
-_TP_AVAILABLE_IN_0_16
 TpContact *tp_channel_group_get_self_contact (TpChannel *self);
 _TP_AVAILABLE_IN_0_16
 GPtrArray *tp_channel_group_dup_members_contacts (TpChannel *self);



More information about the telepathy-commits mailing list