aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy/empathy-contact.c
diff options
context:
space:
mode:
authorEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>2011-05-10 02:51:34 +0800
committerEmilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>2011-06-09 19:34:57 +0800
commit577effbd7b0a97ce168105feb184ad5671db2bb6 (patch)
treef4bad8ec1523a117c5934a9ccf961ab661a815cb /libempathy/empathy-contact.c
parent7e79c7c05aeee5497f31935ae79db1abee141875 (diff)
downloadgsoc2013-empathy-577effbd7b0a97ce168105feb184ad5671db2bb6.tar
gsoc2013-empathy-577effbd7b0a97ce168105feb184ad5671db2bb6.tar.gz
gsoc2013-empathy-577effbd7b0a97ce168105feb184ad5671db2bb6.tar.bz2
gsoc2013-empathy-577effbd7b0a97ce168105feb184ad5671db2bb6.tar.lz
gsoc2013-empathy-577effbd7b0a97ce168105feb184ad5671db2bb6.tar.xz
gsoc2013-empathy-577effbd7b0a97ce168105feb184ad5671db2bb6.tar.zst
gsoc2013-empathy-577effbd7b0a97ce168105feb184ad5671db2bb6.zip
empathy_contact_from_tpl_contact: set the TpContact
If available, so we get extra info like capabilities. Based on a patch from Nicolas Dufresne. Conflicts: libempathy/empathy-contact.c
Diffstat (limited to 'libempathy/empathy-contact.c')
-rw-r--r--libempathy/empathy-contact.c65
1 files changed, 50 insertions, 15 deletions
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index 55bc40bdd..8150e9e67 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -72,6 +72,8 @@ typedef struct {
GHashTable *location;
GeeHashSet *groups;
gchar **client_types;
+
+ gboolean keep_tpcontact;
} EmpathyContactPriv;
static void contact_finalize (GObject *object);
@@ -190,14 +192,15 @@ contact_dispose (GObject *object)
{
EmpathyContactPriv *priv = GET_PRIV (object);
- if (priv->tp_contact)
+ if (priv->tp_contact != NULL)
{
- g_hash_table_remove (contacts_table, priv->tp_contact);
+ if (!priv->keep_tpcontact)
+ g_hash_table_remove (contacts_table, priv->tp_contact);
+
g_signal_handlers_disconnect_by_func (priv->tp_contact,
tp_contact_notify_cb, object);
- g_object_unref (priv->tp_contact);
}
- priv->tp_contact = NULL;
+ tp_clear_object (&priv->tp_contact);
if (priv->account)
g_object_unref (priv->account);
@@ -641,23 +644,55 @@ empathy_contact_new (TpContact *tp_contact)
NULL);
}
+static gboolean
+contact_is_tpl_entity (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ TpContact *contact = key;
+ TplEntity *entity = user_data;
+
+ return !tp_strdiff (tp_contact_get_identifier (contact),
+ tpl_entity_get_identifier (entity));
+}
+
EmpathyContact *
empathy_contact_from_tpl_contact (TpAccount *account,
TplEntity *tpl_entity)
{
EmpathyContact *retval;
gboolean is_user;
+ EmpathyContact *existing_contact = NULL;
g_return_val_if_fail (TPL_IS_ENTITY (tpl_entity), NULL);
- is_user = (TPL_ENTITY_SELF == tpl_entity_get_entity_type (tpl_entity));
+ if (contacts_table != NULL)
+ existing_contact = g_hash_table_find (contacts_table,
+ contact_is_tpl_entity, tpl_entity);
- retval = g_object_new (EMPATHY_TYPE_CONTACT,
- "id", tpl_entity_get_identifier (tpl_entity),
- "alias", tpl_entity_get_alias (tpl_entity),
- "account", account,
- "is-user", is_user,
- NULL);
+ if (existing_contact != NULL)
+ {
+ EmpathyContactPriv *priv;
+
+ retval = g_object_new (EMPATHY_TYPE_CONTACT,
+ "tp-contact", empathy_contact_get_tp_contact (existing_contact),
+ "alias", tpl_entity_get_alias (tpl_entity),
+ NULL);
+
+ priv = GET_PRIV (retval);
+ priv->keep_tpcontact = TRUE;
+ }
+ else
+ {
+ is_user = (TPL_ENTITY_SELF == tpl_entity_get_entity_type (tpl_entity));
+
+ retval = g_object_new (EMPATHY_TYPE_CONTACT,
+ "id", tpl_entity_get_identifier (tpl_entity),
+ "alias", tpl_entity_get_alias (tpl_entity),
+ "account", account,
+ "is-user", is_user,
+ NULL);
+ }
if (!EMP_STR_EMPTY (tpl_entity_get_avatar_token (tpl_entity)))
contact_load_avatar_cache (retval,
@@ -697,16 +732,16 @@ const gchar *
empathy_contact_get_alias (EmpathyContact *contact)
{
EmpathyContactPriv *priv;
- const gchar *alias;
+ const gchar *alias = NULL;
g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
priv = GET_PRIV (contact);
- if (priv->tp_contact != NULL)
- alias = tp_contact_get_alias (priv->tp_contact);
- else
+ if (!EMP_STR_EMPTY (priv->alias))
alias = priv->alias;
+ else if (priv->tp_contact != NULL)
+ alias = tp_contact_get_alias (priv->tp_contact);
if (!EMP_STR_EMPTY (alias))
return alias;