[empathy] Don't assume that all TpfPersonas contain valid TpContacts



commit d1d3a49fc919ed734b77a6e94afb2d49109182f2
Author: Travis Reitter <travis reitter collabora co uk>
Date:   Mon Jun 27 14:31:25 2011 -0700

    Don't assume that all TpfPersonas contain valid TpContacts
    
    Helps: bgo#653599 - Empathy shouldn't assume all TpfPersonas contain a
    valid TpContact
    
    Signed-off-by: Jonny Lamb <jonnylamb gnome org>

 libempathy-gtk/empathy-individual-dialogs.c |    3 +
 libempathy-gtk/empathy-individual-menu.c    |   34 ++++++---
 libempathy-gtk/empathy-individual-store.c   |   57 +++++++++------
 libempathy-gtk/empathy-individual-widget.c  |   46 ++++++++----
 libempathy-gtk/empathy-persona-store.c      |  106 ++++++++++++++++-----------
 libempathy-gtk/empathy-persona-view.c       |   11 ++-
 libempathy/empathy-contact.c                |    3 +
 libempathy/empathy-individual-manager.c     |   52 ++++++++-----
 libempathy/empathy-utils.c                  |    7 +-
 9 files changed, 203 insertions(+), 116 deletions(-)
---
diff --git a/libempathy-gtk/empathy-individual-dialogs.c b/libempathy-gtk/empathy-individual-dialogs.c
index a197876..e1bd6f1 100644
--- a/libempathy-gtk/empathy-individual-dialogs.c
+++ b/libempathy-gtk/empathy-individual-dialogs.c
@@ -222,6 +222,9 @@ empathy_block_individual_dialog_show (GtkWindow *parent,
           goto while_finish;
 
       contact = tpf_persona_get_contact (persona);
+      if (contact == NULL)
+        goto while_finish;
+
       flags = empathy_contact_manager_get_flags_for_connection (
           contact_manager, tp_contact_get_connection (contact));
 
diff --git a/libempathy-gtk/empathy-individual-menu.c b/libempathy-gtk/empathy-individual-menu.c
index 6131bfd..eab28ec 100644
--- a/libempathy-gtk/empathy-individual-menu.c
+++ b/libempathy-gtk/empathy-individual-menu.c
@@ -127,6 +127,9 @@ individual_menu_add_personas (GtkMenuShell *menu,
         goto while_finish;
 
       tp_contact = tpf_persona_get_contact (persona);
+      if (tp_contact == NULL)
+        goto while_finish;
+
       contact = empathy_contact_dup_from_tp_contact (tp_contact);
 
       store = folks_persona_get_store (FOLKS_PERSONA (persona));
@@ -1038,17 +1041,20 @@ room_sub_menu_activate_cb (GtkWidget *item,
           if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
             {
               tp_contact = tpf_persona_get_contact (persona);
-              contact = empathy_contact_dup_from_tp_contact (tp_contact);
+              if (tp_contact != NULL)
+                {
+                  contact = empathy_contact_dup_from_tp_contact (tp_contact);
 
-              rooms = empathy_chatroom_manager_get_chatrooms (mgr,
-                  empathy_contact_get_account (contact));
+                  rooms = empathy_chatroom_manager_get_chatrooms (mgr,
+                      empathy_contact_get_account (contact));
 
-              if (g_list_find (rooms, data->chatroom) == NULL)
-                g_clear_object (&contact);
+                  if (g_list_find (rooms, data->chatroom) == NULL)
+                    g_clear_object (&contact);
 
-              /* if contact != NULL here, we've found our match */
+                  /* if contact != NULL here, we've found our match */
 
-              g_list_free (rooms);
+                  g_list_free (rooms);
+                }
             }
           g_clear_object (&persona);
         }
@@ -1143,13 +1149,17 @@ empathy_individual_invite_menu_item_new (FolksIndividual *individual,
           if (empathy_folks_persona_is_interesting (FOLKS_PERSONA (persona)))
             {
               tp_contact = tpf_persona_get_contact (persona);
-              contact_cur = empathy_contact_dup_from_tp_contact (tp_contact);
+              if (tp_contact != NULL)
+                {
+                  contact_cur = empathy_contact_dup_from_tp_contact (
+                      tp_contact);
 
-              rooms_cur = empathy_chatroom_manager_get_chatrooms (mgr,
-                  empathy_contact_get_account (contact_cur));
-              rooms = g_list_concat (rooms, rooms_cur);
+                  rooms_cur = empathy_chatroom_manager_get_chatrooms (mgr,
+                      empathy_contact_get_account (contact_cur));
+                  rooms = g_list_concat (rooms, rooms_cur);
 
-              g_object_unref (contact_cur);
+                  g_object_unref (contact_cur);
+                }
             }
           g_clear_object (&persona);
         }
diff --git a/libempathy-gtk/empathy-individual-store.c b/libempathy-gtk/empathy-individual-store.c
index e4e6444..4bdded8 100644
--- a/libempathy-gtk/empathy-individual-store.c
+++ b/libempathy-gtk/empathy-individual-store.c
@@ -133,21 +133,25 @@ individual_can_audio_video_call (FolksIndividual *individual,
     {
       FolksPersona *persona = gee_iterator_get (iter);
       TpContact *tp_contact;
-      EmpathyContact *contact;
 
       if (!empathy_folks_persona_is_interesting (persona))
         goto while_finish;
 
       tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
-      contact = empathy_contact_dup_from_tp_contact (tp_contact);
-      empathy_contact_set_persona (contact, persona);
+      if (tp_contact != NULL)
+        {
+          EmpathyContact *contact;
+
+          contact = empathy_contact_dup_from_tp_contact (tp_contact);
+          empathy_contact_set_persona (contact, persona);
 
-      can_audio = can_audio || empathy_contact_get_capabilities (contact) &
-          EMPATHY_CAPABILITIES_AUDIO;
-      can_video = can_video || empathy_contact_get_capabilities (contact) &
-          EMPATHY_CAPABILITIES_VIDEO;
+          can_audio = can_audio || empathy_contact_get_capabilities (contact) &
+              EMPATHY_CAPABILITIES_AUDIO;
+          can_video = can_video || empathy_contact_get_capabilities (contact) &
+              EMPATHY_CAPABILITIES_VIDEO;
 
-      g_object_unref (contact);
+          g_object_unref (contact);
+        }
 while_finish:
       g_clear_object (&persona);
 
@@ -190,7 +194,8 @@ individual_get_client_types (FolksIndividual *individual)
           presence_type = folks_presence_details_get_presence_type (presence);
 
           tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
-          types = tp_contact_get_client_types (tp_contact);
+          if (tp_contact != NULL)
+            types = tp_contact_get_client_types (tp_contact);
         }
 
 while_finish:
@@ -900,14 +905,17 @@ individual_personas_changed_cb (FolksIndividual *individual,
       if (TPF_IS_PERSONA (persona))
         {
           tp_contact = tpf_persona_get_contact (persona);
-          contact = empathy_contact_dup_from_tp_contact (tp_contact);
-          empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
+          if (tp_contact != NULL)
+            {
+              contact = empathy_contact_dup_from_tp_contact (tp_contact);
+              empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
 
-          g_object_set_data (G_OBJECT (contact), "individual", NULL);
-          g_signal_handlers_disconnect_by_func (contact,
-              (GCallback) individual_store_contact_updated_cb, self);
+              g_object_set_data (G_OBJECT (contact), "individual", NULL);
+              g_signal_handlers_disconnect_by_func (contact,
+                  (GCallback) individual_store_contact_updated_cb, self);
 
-          g_object_unref (contact);
+              g_object_unref (contact);
+            }
         }
 
       g_clear_object (&persona);
@@ -924,16 +932,19 @@ individual_personas_changed_cb (FolksIndividual *individual,
       if (TPF_IS_PERSONA (persona))
         {
           tp_contact = tpf_persona_get_contact (persona);
-          contact = empathy_contact_dup_from_tp_contact (tp_contact);
-          empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
+          if (tp_contact != NULL)
+            {
+              contact = empathy_contact_dup_from_tp_contact (tp_contact);
+              empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
 
-          g_object_set_data (G_OBJECT (contact), "individual", individual);
-          g_signal_connect (contact, "notify::capabilities",
-              (GCallback) individual_store_contact_updated_cb, self);
-          g_signal_connect (contact, "notify::client-types",
-              (GCallback) individual_store_contact_updated_cb, self);
+              g_object_set_data (G_OBJECT (contact), "individual", individual);
+              g_signal_connect (contact, "notify::capabilities",
+                  (GCallback) individual_store_contact_updated_cb, self);
+              g_signal_connect (contact, "notify::client-types",
+                  (GCallback) individual_store_contact_updated_cb, self);
 
-          g_object_unref (contact);
+              g_object_unref (contact);
+            }
         }
 
       g_clear_object (&persona);
diff --git a/libempathy-gtk/empathy-individual-widget.c b/libempathy-gtk/empathy-individual-widget.c
index fcc076b..0a3844a 100644
--- a/libempathy-gtk/empathy-individual-widget.c
+++ b/libempathy-gtk/empathy-individual-widget.c
@@ -574,16 +574,20 @@ location_update (EmpathyIndividualWidget *self)
            * have to keep it alive for the duration of the function, since we're
            * accessing its private data. */
           tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
-          contact = empathy_contact_dup_from_tp_contact (tp_contact);
-          empathy_contact_set_persona (contact, persona);
-
-          /* Try and get a location */
-          location = empathy_contact_get_location (contact);
-          /* if location isn't fully valid, treat the contact as insufficient */
-          if (location != NULL && g_hash_table_size (location) <= 0)
+          if (tp_contact != NULL)
             {
-              location = NULL;
-              g_clear_object (&contact);
+              contact = empathy_contact_dup_from_tp_contact (tp_contact);
+              empathy_contact_set_persona (contact, persona);
+
+              /* Try and get a location */
+              location = empathy_contact_get_location (contact);
+              /* if location isn't fully valid, treat the contact as
+               * insufficient */
+              if (location != NULL && g_hash_table_size (location) <= 0)
+                {
+                  location = NULL;
+                  g_clear_object (&contact);
+                }
             }
         }
       g_clear_object (&persona);
@@ -747,6 +751,9 @@ location_update (EmpathyIndividualWidget *self)
 
               /* Get the contact */
               tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+              if (tp_contact == NULL)
+                goto while_finish;
+
               contact = empathy_contact_dup_from_tp_contact (tp_contact);
               empathy_contact_set_persona (contact, persona);
 
@@ -856,6 +863,9 @@ persona_dup_avatar (FolksPersona *persona)
     return NULL;
 
   tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+  if (tp_contact == NULL)
+    return NULL;
+
   contact = empathy_contact_dup_from_tp_contact (tp_contact);
   empathy_contact_set_persona (contact, persona);
 
@@ -1063,16 +1073,19 @@ individual_is_user (FolksIndividual *individual)
       if (TPF_IS_PERSONA (persona))
         {
           TpContact *tp_contact;
-          EmpathyContact *contact;
+          EmpathyContact *contact = NULL;
 
           /* Get the contact */
           tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
-          contact = empathy_contact_dup_from_tp_contact (tp_contact);
-          empathy_contact_set_persona (contact, persona);
+          if (tp_contact != NULL)
+            {
+              contact = empathy_contact_dup_from_tp_contact (tp_contact);
+              empathy_contact_set_persona (contact, persona);
 
-          /* Determine if the contact is the user */
-          if (empathy_contact_is_user (contact))
-            retval = g_object_ref (empathy_contact_get_account (contact));
+              /* Determine if the contact is the user */
+              if (empathy_contact_is_user (contact))
+                retval = g_object_ref (empathy_contact_get_account (contact));
+            }
 
           g_object_unref (contact);
         }
@@ -1409,6 +1422,9 @@ update_persona (EmpathyIndividualWidget *self, FolksPersona *persona)
   g_assert (table != NULL);
 
   tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+  if (tp_contact == NULL)
+    return;
+
   contact = empathy_contact_dup_from_tp_contact (tp_contact);
   empathy_contact_set_persona (contact, persona);
 
diff --git a/libempathy-gtk/empathy-persona-store.c b/libempathy-gtk/empathy-persona-store.c
index a387778..70d53b3 100644
--- a/libempathy-gtk/empathy-persona-store.c
+++ b/libempathy-gtk/empathy-persona-store.c
@@ -278,6 +278,7 @@ add_persona (EmpathyPersonaStore *self,
   GtkTreeIter iter;
   GtkTreePath *path;
   FolksPersonaStore *store;
+  TpContact *tp_contact;
   EmpathyContact *contact;
   const gchar *alias;
 
@@ -290,8 +291,11 @@ add_persona (EmpathyPersonaStore *self,
   if (EMP_STR_EMPTY (alias))
     return;
 
-  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
-      TPF_PERSONA (persona)));
+  tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+  if (tp_contact == NULL)
+    return;
+
+  contact = empathy_contact_dup_from_tp_contact (tp_contact);
   store = folks_persona_get_store (persona);
 
   gtk_list_store_insert_with_values (GTK_LIST_STORE (self), &iter, 0,
@@ -348,14 +352,18 @@ get_persona_status_icon (EmpathyPersonaStore *self,
     FolksPersona *persona)
 {
   EmpathyPersonaStorePriv *priv = GET_PRIV (self);
+  TpContact *tp_contact;
   EmpathyContact *contact;
   const gchar *protocol_name = NULL;
   gchar *icon_name = NULL;
   GdkPixbuf *pixbuf_status = NULL;
   const gchar *status_icon_name = NULL;
 
-  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
-      TPF_PERSONA (persona)));
+  tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+  if (tp_contact == NULL)
+    return NULL;
+
+  contact = empathy_contact_dup_from_tp_contact (tp_contact);
 
   status_icon_name = empathy_icon_name_for_contact (contact);
   if (status_icon_name == NULL)
@@ -422,9 +430,10 @@ update_persona (EmpathyPersonaStore *self,
   else
     {
       FolksPersonaStore *store;
+      TpContact *tp_contact;
       EmpathyContact *contact;
       GtkTreeIter iter;
-      GdkPixbuf *pixbuf_avatar;
+      GdkPixbuf *pixbuf_avatar = NULL;
       GdkPixbuf *pixbuf_status;
       gboolean now_online = FALSE;
       gboolean was_online = TRUE;
@@ -464,39 +473,43 @@ update_persona (EmpathyPersonaStore *self,
         }
 
       /* We still need to use EmpathyContact for the capabilities stuff */
-      contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
-          TPF_PERSONA (persona)));
-      store = folks_persona_get_store (persona);
-
-      pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
-          32, 32);
-      pixbuf_status = get_persona_status_icon (self, persona);
-
-      gtk_list_store_set (GTK_LIST_STORE (self), &iter,
-          EMPATHY_PERSONA_STORE_COL_ICON_STATUS, pixbuf_status,
-          EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
-          EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR_VISIBLE, priv->show_avatars,
-          EMPATHY_PERSONA_STORE_COL_NAME, alias,
-          EMPATHY_PERSONA_STORE_COL_ACCOUNT_NAME,
-              folks_persona_store_get_display_name (store),
-          EMPATHY_PERSONA_STORE_COL_DISPLAY_ID,
-              folks_persona_get_display_id (persona),
-          EMPATHY_PERSONA_STORE_COL_PRESENCE_TYPE,
-              folks_presence_details_get_presence_type (
-                  FOLKS_PRESENCE_DETAILS (persona)),
-          EMPATHY_PERSONA_STORE_COL_STATUS,
-              folks_presence_details_get_presence_message (
-                  FOLKS_PRESENCE_DETAILS (persona)),
-          EMPATHY_PERSONA_STORE_COL_IS_ONLINE, now_online,
-          EMPATHY_PERSONA_STORE_COL_CAN_AUDIO_CALL,
-              empathy_contact_get_capabilities (contact) &
-                EMPATHY_CAPABILITIES_AUDIO,
-          EMPATHY_PERSONA_STORE_COL_CAN_VIDEO_CALL,
-              empathy_contact_get_capabilities (contact) &
-                EMPATHY_CAPABILITIES_VIDEO,
-          -1);
-
-      g_object_unref (contact);
+      tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+      if (tp_contact != NULL)
+        {
+          contact = empathy_contact_dup_from_tp_contact (tp_contact);
+          store = folks_persona_get_store (persona);
+
+          pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
+              32, 32);
+          pixbuf_status = get_persona_status_icon (self, persona);
+
+          gtk_list_store_set (GTK_LIST_STORE (self), &iter,
+              EMPATHY_PERSONA_STORE_COL_ICON_STATUS, pixbuf_status,
+              EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR, pixbuf_avatar,
+              EMPATHY_PERSONA_STORE_COL_PIXBUF_AVATAR_VISIBLE,
+                  priv->show_avatars,
+              EMPATHY_PERSONA_STORE_COL_NAME, alias,
+              EMPATHY_PERSONA_STORE_COL_ACCOUNT_NAME,
+                  folks_persona_store_get_display_name (store),
+              EMPATHY_PERSONA_STORE_COL_DISPLAY_ID,
+                  folks_persona_get_display_id (persona),
+              EMPATHY_PERSONA_STORE_COL_PRESENCE_TYPE,
+                  folks_presence_details_get_presence_type (
+                      FOLKS_PRESENCE_DETAILS (persona)),
+              EMPATHY_PERSONA_STORE_COL_STATUS,
+                  folks_presence_details_get_presence_message (
+                      FOLKS_PRESENCE_DETAILS (persona)),
+              EMPATHY_PERSONA_STORE_COL_IS_ONLINE, now_online,
+              EMPATHY_PERSONA_STORE_COL_CAN_AUDIO_CALL,
+                  empathy_contact_get_capabilities (contact) &
+                    EMPATHY_CAPABILITIES_AUDIO,
+              EMPATHY_PERSONA_STORE_COL_CAN_VIDEO_CALL,
+                  empathy_contact_get_capabilities (contact) &
+                    EMPATHY_CAPABILITIES_VIDEO,
+              -1);
+
+          g_object_unref (contact);
+        }
 
       if (pixbuf_avatar)
         g_object_unref (pixbuf_avatar);
@@ -566,6 +579,7 @@ sort_personas (FolksPersona *persona_a,
 {
   EmpathyContact *contact;
   TpAccount *account_a, *account_b;
+  TpContact *tp_contact_a, *tp_contact_b;
   gint ret_val;
 
   g_return_val_if_fail (persona_a != NULL || persona_b != NULL, 0);
@@ -585,13 +599,21 @@ sort_personas (FolksPersona *persona_a,
   if (ret_val != 0)
     goto out;
 
-  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
-      TPF_PERSONA (persona_a)));
+  tp_contact_a = tpf_persona_get_contact (TPF_PERSONA (persona_a));
+  tp_contact_b = tpf_persona_get_contact (TPF_PERSONA (persona_b));
+
+  /* handle the case that one or more of these personas are from the cache */
+  if (tp_contact_a == NULL || tp_contact_b == NULL)
+    {
+      ret_val = (tp_contact_a != NULL ? 1 : -1);
+      goto out;
+    }
+
+  contact = empathy_contact_dup_from_tp_contact (tp_contact_a);
   account_a = empathy_contact_get_account (contact);
   g_object_unref (contact);
 
-  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
-      TPF_PERSONA (persona_b)));
+  contact = empathy_contact_dup_from_tp_contact (tp_contact_b);
   account_b = empathy_contact_get_account (contact);
   g_object_unref (contact);
 
diff --git a/libempathy-gtk/empathy-persona-view.c b/libempathy-gtk/empathy-persona-view.c
index 6d16296..5cb77c9 100644
--- a/libempathy-gtk/empathy-persona-view.c
+++ b/libempathy-gtk/empathy-persona-view.c
@@ -174,6 +174,7 @@ query_tooltip_cb (EmpathyPersonaView *self,
 {
   EmpathyPersonaViewPriv *priv = GET_PRIV (self);
   FolksPersona *persona;
+  TpContact *tp_contact;
   EmpathyContact *contact;
   GtkTreeModel *model;
   GtkTreeIter iter;
@@ -201,8 +202,14 @@ query_tooltip_cb (EmpathyPersonaView *self,
   if (persona == NULL)
     goto OUT;
 
-  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
-      TPF_PERSONA (persona)));
+  tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+  if (tp_contact == NULL)
+    {
+      g_clear_object (&persona);
+      goto OUT;
+    }
+
+  contact = empathy_contact_dup_from_tp_contact (tp_contact);
 
   if (priv->tooltip_widget == NULL)
     {
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index d576489..eac5a8b 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -2032,6 +2032,9 @@ empathy_contact_dup_best_for_action (FolksIndividual *individual,
         goto while_finish;
 
       tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+      if (tp_contact == NULL)
+        goto while_finish;
+
       contact = empathy_contact_dup_from_tp_contact (tp_contact);
       empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
 
diff --git a/libempathy/empathy-individual-manager.c b/libempathy/empathy-individual-manager.c
index f6aa491..47a01cb 100644
--- a/libempathy/empathy-individual-manager.c
+++ b/libempathy/empathy-individual-manager.c
@@ -531,14 +531,21 @@ empathy_individual_manager_supports_blocking (EmpathyIndividualManager *self,
 
       if (TPF_IS_PERSONA (persona))
         {
-          conn = tp_contact_get_connection (tpf_persona_get_contact (persona));
-          manager = empathy_contact_manager_dup_singleton ();
+          TpContact *tp_contact;
 
-          if (empathy_contact_manager_get_flags_for_connection (manager, conn) &
-              EMPATHY_CONTACT_LIST_CAN_BLOCK)
-            retval = TRUE;
+          tp_contact = tpf_persona_get_contact (persona);
+          if (tp_contact != NULL)
+            {
+              conn = tp_contact_get_connection (tp_contact);
+              manager = empathy_contact_manager_dup_singleton ();
 
-          g_object_unref (manager);
+              if (empathy_contact_manager_get_flags_for_connection (
+                    manager, conn) &
+                  EMPATHY_CONTACT_LIST_CAN_BLOCK)
+                retval = TRUE;
+
+              g_object_unref (manager);
+            }
         }
       g_clear_object (&persona);
     }
@@ -569,20 +576,25 @@ empathy_individual_manager_set_blocked (EmpathyIndividualManager *self,
 
       if (TPF_IS_PERSONA (persona))
         {
-          contact = empathy_contact_dup_from_tp_contact (
-              tpf_persona_get_contact (persona));
-          empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
-          manager = empathy_contact_manager_dup_singleton ();
-          flags = empathy_contact_manager_get_flags_for_connection (manager,
-              empathy_contact_get_connection (contact));
-
-          if (flags & EMPATHY_CONTACT_LIST_CAN_BLOCK)
-            empathy_contact_list_set_blocked (
-                EMPATHY_CONTACT_LIST (manager),
-                contact, blocked, abusive);
-
-          g_object_unref (manager);
-          g_object_unref (contact);
+          TpContact *tp_contact;
+
+          tp_contact = tpf_persona_get_contact (persona);
+          if (tp_contact != NULL)
+            {
+              contact = empathy_contact_dup_from_tp_contact (tp_contact);
+              empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
+              manager = empathy_contact_manager_dup_singleton ();
+              flags = empathy_contact_manager_get_flags_for_connection (manager,
+                  empathy_contact_get_connection (contact));
+
+              if (flags & EMPATHY_CONTACT_LIST_CAN_BLOCK)
+                empathy_contact_list_set_blocked (
+                    EMPATHY_CONTACT_LIST (manager),
+                    contact, blocked, abusive);
+
+              g_object_unref (manager);
+              g_object_unref (contact);
+            }
         }
       g_clear_object (&persona);
     }
diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c
index 04a6c78..9a0d167 100644
--- a/libempathy/empathy-utils.c
+++ b/libempathy/empathy-utils.c
@@ -715,8 +715,11 @@ empathy_contact_dup_from_folks_individual (FolksIndividual *individual)
           TpContact *tp_contact;
 
           tp_contact = tpf_persona_get_contact (persona);
-          contact = empathy_contact_dup_from_tp_contact (tp_contact);
-          empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
+          if (tp_contact != NULL)
+            {
+              contact = empathy_contact_dup_from_tp_contact (tp_contact);
+              empathy_contact_set_persona (contact, FOLKS_PERSONA (persona));
+            }
         }
       g_clear_object (&persona);
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]