]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-contact.c
Remove tp-yell and use TpCallChannel
[empathy.git] / libempathy / empathy-contact.c
index f27de0414a284ebeceea4ec7da83093c1151e767..b8d2f3c401f12dbb2e4195ee1e6f3a19ca527712 100644 (file)
@@ -28,7 +28,6 @@
 #include <telepathy-glib/account-manager.h>
 #include <telepathy-glib/interfaces.h>
 #include <telepathy-glib/util.h>
-#include <telepathy-yell/telepathy-yell.h>
 
 #include <telepathy-logger/log-manager.h>
 
@@ -44,7 +43,6 @@
 #include "empathy-individual-manager.h"
 #include "empathy-utils.h"
 #include "empathy-enum-types.h"
-#include "empathy-marshal.h"
 #include "empathy-location.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
@@ -405,7 +403,7 @@ empathy_contact_class_init (EmpathyContactClass *class)
                   G_SIGNAL_RUN_LAST,
                   0,
                   NULL, NULL,
-                  _empathy_marshal_VOID__UINT_UINT,
+                  g_cclosure_marshal_generic,
                   G_TYPE_NONE,
                   2, G_TYPE_UINT,
                   G_TYPE_UINT);
@@ -695,6 +693,34 @@ contact_is_tpl_entity (gpointer key,
          !tp_strdiff (tp_proxy_get_object_path (data->account), path);
 }
 
+static void
+get_contacts_cb (TpConnection *connection,
+    guint n_contacts,
+    TpContact * const *contacts,
+    const gchar * const *requested_ids,
+    GHashTable *failed_id_errors,
+    const GError *error,
+    gpointer user_data,
+    GObject *weak_object)
+{
+  EmpathyContact *self = (EmpathyContact *) weak_object;
+  EmpathyContactPriv *priv = GET_PRIV (self);
+  TpContact *tp_contact;
+
+  if (n_contacts != 1)
+    return;
+
+  tp_contact = contacts[0];
+
+  g_return_if_fail (priv->tp_contact == NULL);
+  priv->tp_contact = g_object_ref (tp_contact);
+  g_object_notify (G_OBJECT (self), "tp-contact");
+
+  /* Update capabilities now that we have a TpContact */
+  set_capabilities_from_tp_caps (self,
+      tp_contact_get_capabilities (tp_contact));
+}
+
 EmpathyContact *
 empathy_contact_from_tpl_contact (TpAccount *account,
     TplEntity *tpl_entity)
@@ -725,14 +751,33 @@ empathy_contact_from_tpl_contact (TpAccount *account,
     }
   else
     {
+      TpConnection *conn;
+      const gchar *id;
+
       is_user = (TPL_ENTITY_SELF == tpl_entity_get_entity_type (tpl_entity));
 
+      id = tpl_entity_get_identifier (tpl_entity);
+
       retval = g_object_new (EMPATHY_TYPE_CONTACT,
-          "id", tpl_entity_get_identifier (tpl_entity),
+          "id", id,
           "alias", tpl_entity_get_alias (tpl_entity),
           "account", account,
           "is-user", is_user,
           NULL);
+
+      /* Try to get a TpContact associated to have at least contact
+       * capabilities if possible. This is useful for CM supporting calling
+       * offline contacts for example. */
+      conn = tp_account_get_connection (account);
+      if (conn != NULL)
+        {
+          TpContactFeature features[] = { TP_CONTACT_FEATURE_CAPABILITIES };
+          conn = tp_account_get_connection (account);
+
+          tp_connection_get_contacts_by_id (conn, 1, &id,
+              G_N_ELEMENTS (features), features, get_contacts_cb,
+              NULL, NULL, G_OBJECT (retval));
+        }
     }
 
   if (!EMP_STR_EMPTY (tpl_entity_get_avatar_token (tpl_entity)))
@@ -957,46 +1002,14 @@ empathy_contact_get_persona (EmpathyContact *contact)
 
   if (priv->persona == NULL && priv->tp_contact != NULL)
     {
-      /* FIXME: This is disgustingly slow */
-      /* Query for the persona */
-      EmpathyIndividualManager *manager;
-      GList *individuals, *l;
+      TpfPersona *persona;
 
-      manager = empathy_individual_manager_dup_singleton ();
-      individuals = empathy_individual_manager_get_members (manager);
-
-      for (l = individuals; l != NULL; l = l->next)
+      persona = tpf_persona_dup_for_contact (priv->tp_contact);
+      if (persona != NULL)
         {
-          FolksIndividual *individual = FOLKS_INDIVIDUAL (l->data);
-          GeeSet *personas;
-          GeeIterator *iter;
-          gboolean persona_found = FALSE;
-
-          personas = folks_individual_get_personas (individual);
-          iter = gee_iterable_iterator (GEE_ITERABLE (personas));
-          while (!persona_found && gee_iterator_next (iter))
-            {
-              TpfPersona *persona = gee_iterator_get (iter);
-
-              if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
-                {
-                  TpContact *tp_contact = tpf_persona_get_contact (persona);
-
-                  if (tp_contact == priv->tp_contact)
-                    {
-                      /* Found the right persona */
-                      empathy_contact_set_persona (contact,
-                          (FolksPersona *) persona);
-                      persona_found = TRUE;
-                    }
-                  g_clear_object (&persona);
-                }
-            }
-          g_clear_object (&iter);
+          empathy_contact_set_persona (contact, (FolksPersona *) persona);
+          g_object_unref (persona);
         }
-
-      g_list_free (individuals);
-      g_object_unref (manager);
     }
 
   return priv->persona;
@@ -1727,8 +1740,7 @@ tp_caps_to_capabilities (TpCapabilities *caps)
           if (!tp_strdiff (service, "rfb"))
             capabilities |= EMPATHY_CAPABILITIES_RFB_STREAM_TUBE;
         }
-      else if (!tp_strdiff (chan_type,
-        TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA))
+      else if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA))
         {
           guint j;
 
@@ -1755,26 +1767,25 @@ tp_caps_to_capabilities (TpCapabilities *caps)
                 TP_PROP_CHANNEL_INTERFACE_SMS_SMS_CHANNEL, NULL))
             capabilities |= EMPATHY_CAPABILITIES_SMS;
         }
-      else if (!tp_strdiff (chan_type,
-        TPY_IFACE_CHANNEL_TYPE_CALL))
+      else if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_CALL))
         {
           guint j;
 
           if (tp_asv_get_boolean (fixed_prop,
-              TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, NULL))
+              TP_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO, NULL))
             capabilities |= EMPATHY_CAPABILITIES_AUDIO;
 
           if (tp_asv_get_boolean (fixed_prop,
-              TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO, NULL))
+              TP_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO, NULL))
             capabilities |= EMPATHY_CAPABILITIES_VIDEO;
 
           for (j = 0; allowed_prop[j] != NULL; j++)
             {
               if (!tp_strdiff (allowed_prop[j],
-                    TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO))
+                    TP_PROP_CHANNEL_TYPE_CALL_INITIAL_AUDIO))
                 capabilities |= EMPATHY_CAPABILITIES_AUDIO;
               else if (!tp_strdiff (allowed_prop[j],
-                    TPY_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO))
+                    TP_PROP_CHANNEL_TYPE_CALL_INITIAL_VIDEO))
                 capabilities |= EMPATHY_CAPABILITIES_VIDEO;
             }
         }
@@ -2072,3 +2083,53 @@ while_finish:
 
   return best_contact;
 }
+
+#define declare_contact_cb(name) \
+static void \
+contact_##name##_cb (GObject *source, \
+    GAsyncResult *result, \
+    gpointer user_data) \
+{ \
+  TpContact *contact = (TpContact *) source; \
+  GError *error = NULL; \
+  \
+  if (!tp_contact_##name##_finish (contact, result, &error)) \
+    { \
+      DEBUG ("Failed to ##name## on %s\n", \
+          tp_contact_get_identifier (contact)); \
+      g_error_free (error); \
+    } \
+}
+
+declare_contact_cb (request_subscription)
+declare_contact_cb (authorize_publication)
+declare_contact_cb (unblock)
+
+void
+empathy_contact_add_to_contact_list (EmpathyContact *self,
+    const gchar *message)
+{
+  EmpathyContactPriv *priv = GET_PRIV (self);
+
+  g_return_if_fail (priv->tp_contact != NULL);
+
+  tp_contact_request_subscription_async (priv->tp_contact, message,
+      contact_request_subscription_cb, NULL);
+
+  tp_contact_authorize_publication_async (priv->tp_contact,
+      contact_authorize_publication_cb, NULL);
+
+  tp_contact_unblock_async (priv->tp_contact, contact_unblock_cb, NULL);
+}
+
+declare_contact_cb (remove)
+
+void
+empathy_contact_remove_from_contact_list (EmpathyContact *self)
+{
+  EmpathyContactPriv *priv = GET_PRIV (self);
+
+  g_return_if_fail (priv->tp_contact != NULL);
+
+  tp_contact_remove_async (priv->tp_contact, contact_remove_cb, NULL);
+}