summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2011-04-06 10:22:20 +0100
committerJonny Lamb <jonny.lamb@collabora.co.uk>2011-04-06 10:36:34 +0100
commitb2304457ef55403509d7c4df85d968dc12410be1 (patch)
tree3a7ad2f67545379f0fd7af0c2bf8e918b1c672a8
parent9d4802deb229e4a104c5dabea9fb1575c4cdd106 (diff)
contact-factory: weak unref an existing LL contact if we're replacing it
Also, stop making more dups of JIDs than necessary, again. Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--wocky/wocky-contact-factory.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/wocky/wocky-contact-factory.c b/wocky/wocky-contact-factory.c
index f8ba362..fcf75d3 100644
--- a/wocky/wocky-contact-factory.c
+++ b/wocky/wocky-contact-factory.c
@@ -447,17 +447,24 @@ wocky_contact_factory_add_ll_contact (WockyContactFactory *self,
WockyLLContact *contact)
{
WockyContactFactoryPrivate *priv = self->priv;
+ gchar *jid = wocky_contact_dup_jid (WOCKY_CONTACT (contact));
+ WockyLLContact *old_contact = g_hash_table_lookup (priv->ll_contacts, jid);
- if (g_hash_table_lookup (priv->ll_contacts,
- wocky_contact_dup_jid (WOCKY_CONTACT (contact)))
- == contact)
- return;
+ if (old_contact == contact)
+ {
+ g_free (jid);
+ return;
+ }
+
+ if (old_contact != NULL)
+ {
+ g_object_weak_unref (G_OBJECT (old_contact), contact_disposed_cb,
+ priv->ll_contacts);
+ }
g_object_weak_ref (G_OBJECT (contact), contact_disposed_cb,
priv->ll_contacts);
- g_hash_table_insert (priv->ll_contacts,
- wocky_contact_dup_jid (WOCKY_CONTACT (contact)),
- contact);
+ g_hash_table_insert (priv->ll_contacts, jid, contact);
g_signal_emit (self, signals[LL_CONTACT_ADDED], 0, contact);
}