From 719cce7f4528aecd4d31a7f5c5875324e7780e7b Mon Sep 17 00:00:00 2001 From: Travis Reitter Date: Thu, 14 Oct 2010 09:20:39 -0700 Subject: Make Individual implement IMable. --- NEWS | 1 + folks/individual.vala | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/NEWS b/NEWS index 171fbb2e..285f3807 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,7 @@ Major changes: * Add the PersonaStore:can-remove-personas property * Add the PersonaStore:can-alias-personas property * Add the PersonaStore:can-group-personas property +* Make Individual implement the IMable interface Bugs fixed: * Bug 630431 — notify::alias is never emitted diff --git a/folks/individual.vala b/folks/individual.vala index bd24ae4c..10062847 100644 --- a/folks/individual.vala +++ b/folks/individual.vala @@ -67,6 +67,7 @@ public class Folks.Individual : Object, Avatar, Favourite, Groupable, + IMable, Presence { private bool _is_favourite; @@ -87,6 +88,7 @@ public class Folks.Individual : Object, /* The number of Personas in this Individual which have * Persona.is_user == true. Iff this is > 0, Individual.is_user == true. */ private uint persona_user_count = 0; + private HashTable> _im_addresses; /** * The trust level of the Individual. @@ -261,6 +263,15 @@ public class Folks.Individual : Object, } } + /** + * {@inheritDoc} + */ + public HashTable> im_addresses + { + get { return this._im_addresses; } + private set {} + } + /** * The set of {@link Persona}s encapsulated by this Individual. * @@ -336,6 +347,11 @@ public class Folks.Individual : Object, this.update_presence (); } + private void notify_im_addresses_cb (Object obj, ParamSpec ps) + { + this.update_im_addresses (); + } + private void notify_is_favourite_cb (Object obj, ParamSpec ps) { this.update_is_favourite (); @@ -354,6 +370,8 @@ public class Folks.Individual : Object, */ public Individual (GLib.List? personas) { + this._im_addresses = + new HashTable> (str_hash, str_equal); this._persona_set = new HashSet (null, null); this.stores = new HashMap (null, null); this.personas = personas; @@ -426,6 +444,7 @@ public class Folks.Individual : Object, this.update_avatar (); this.update_alias (); this.update_trust_level (); + this.update_im_addresses (); } private void update_groups () @@ -662,6 +681,44 @@ public class Folks.Individual : Object, this.trust_level = trust_level; } + private void update_im_addresses () + { + /* populate the IM addresses as the union of our Personas' addresses */ + foreach (var persona in this.personas) + { + if (persona is IMable) + { + var imable = (IMable) persona; + imable.im_addresses.foreach ((k, v) => + { + var cur_protocol = (string) k; + var cur_addresses = (GenericArray) v; + var old_im_array = this._im_addresses.lookup (cur_protocol); + var im_array = new GenericArray (); + + /* use a set to eliminate duplicates */ + var address_set = new HashSet (str_hash, str_equal); + if (old_im_array != null) + { + old_im_array.foreach ((old_address) => + { + address_set.add ((string) old_address); + }); + } + cur_addresses.foreach ((cur_address) => + { + address_set.add ((string) cur_address); + }); + foreach (string addr in address_set) + im_array.add (addr); + + this._im_addresses.insert (cur_protocol, im_array); + }); + } + } + this.notify_property ("im-addresses"); + } + /* * GLib/C convenience functions (for built-in casting, etc.) */ @@ -747,6 +804,7 @@ public class Folks.Individual : Object, persona.notify["avatar"].connect (this.notify_avatar_cb); persona.notify["presence-message"].connect (this.notify_presence_cb); persona.notify["presence-type"].connect (this.notify_presence_cb); + persona.notify["im-addresses"].connect (this.notify_im_addresses_cb); persona.notify["is-favourite"].connect (this.notify_is_favourite_cb); if (persona is Groupable) @@ -763,6 +821,8 @@ public class Folks.Individual : Object, persona.notify["presence-message"].disconnect ( this.notify_presence_cb); persona.notify["presence-type"].disconnect (this.notify_presence_cb); + persona.notify["im-addresses"].disconnect ( + this.notify_im_addresses_cb); persona.notify["is-favourite"].disconnect ( this.notify_is_favourite_cb); -- cgit v1.2.3