[folks] Port PersonaStore.personas_changed to Set<Persona>
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Port PersonaStore.personas_changed to Set<Persona>
- Date: Sat, 23 Apr 2011 21:02:52 +0000 (UTC)
commit dd378b72c4bc63567b0ed74d4b319008fbb1c6be
Author: Philip Withnall <philip withnall collabora co uk>
Date: Thu Mar 24 16:07:55 2011 +0000
Port PersonaStore.personas_changed to Set<Persona>
Helps: bgo#640092
NEWS | 1 +
backends/key-file/kf-persona-store.vala | 24 +++++---
backends/libsocialweb/lib/swf-persona-store.vala | 29 ++++++---
backends/telepathy/lib/tpf-persona-store.vala | 72 ++++++++++++++--------
backends/tracker/lib/trf-persona-store.vala | 42 ++++++++-----
folks/individual-aggregator.vala | 23 +++----
folks/individual.vala | 10 +--
folks/persona-store.vala | 11 ++-
8 files changed, 126 insertions(+), 86 deletions(-)
---
diff --git a/NEWS b/NEWS
index f01be27..becba5a 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,7 @@ API changes:
returns an owned variable.
* Individual.personas now has type Set<Persona>
* Individual.personas_changed now uses Set<Persona>-typed parameters
+* PersonaStore.personas_changed now uses Set<Persona>-typed parameters
Overview of changes from libfolks 0.4.0 to libfolks 0.5.0
=========================================================
diff --git a/backends/key-file/kf-persona-store.vala b/backends/key-file/kf-persona-store.vala
index d1121c9..5ca588e 100644
--- a/backends/key-file/kf-persona-store.vala
+++ b/backends/key-file/kf-persona-store.vala
@@ -33,6 +33,7 @@ using Folks.Backends.Kf;
public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
{
private HashTable<string, Persona> _personas;
+ private HashSet<Persona> _persona_set;
private File _file;
private GLib.KeyFile _key_file;
private unowned Cancellable _save_key_file_cancellable = null;
@@ -127,6 +128,7 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
this.trust_level = PersonaStoreTrust.FULL;
this._file = key_file;
this._personas = new HashTable<string, Persona> (str_hash, str_equal);
+ this._persona_set = new HashSet<Persona> ();
}
/**
@@ -231,13 +233,15 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
Persona persona = new Kf.Persona (this._key_file, persona_id,
this);
this._personas.insert (persona.iid, persona);
+ this._persona_set.add (persona);
}
if (this._personas.size () > 0)
{
/* FIXME: GroupDetails.ChangeReason is not the right enum to
* use here */
- this.personas_changed (this._personas.get_values (), null,
+ this.personas_changed (this._persona_set,
+ new HashSet<Persona> (),
null, null, GroupDetails.ChangeReason.NONE);
}
@@ -276,9 +280,11 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
yield this.save_key_file ();
/* Signal the removal of the Persona */
- GLib.List<Folks.Persona> personas = new GLib.List<Folks.Persona> ();
- personas.prepend (persona);
- this.personas_changed (null, personas, null, null, 0);
+ var personas = new HashSet<Folks.Persona> ();
+ personas.add (persona);
+
+ this.personas_changed (new HashSet<Persona> (), personas,
+ null, null, 0);
}
catch (KeyFileError e)
{
@@ -343,16 +349,18 @@ public class Folks.Backends.Kf.PersonaStore : Folks.PersonaStore
* key file */
Persona persona = new Kf.Persona (this._key_file, persona_id, this);
this._personas.insert (persona.iid, persona);
+ this._persona_set.add (persona);
if (im_addresses_size > 0)
persona.im_addresses = im_addresses;
if (web_service_addresses_size > 0)
persona.web_service_addresses = web_service_addresses;
/* FIXME: GroupDetails.ChangeReason is not the right enum to use here */
- GLib.List<Persona> personas = new GLib.List<Persona> ();
- personas.prepend (persona);
- this.personas_changed (personas, null, null, null,
- GroupDetails.ChangeReason.NONE);
+ var personas = new HashSet<Persona> ();
+ personas.add (persona);
+
+ this.personas_changed (personas, new HashSet<Persona> (),
+ null, null, GroupDetails.ChangeReason.NONE);
return persona;
}
diff --git a/backends/libsocialweb/lib/swf-persona-store.vala b/backends/libsocialweb/lib/swf-persona-store.vala
index 0effd7a..8505ccd 100644
--- a/backends/libsocialweb/lib/swf-persona-store.vala
+++ b/backends/libsocialweb/lib/swf-persona-store.vala
@@ -21,6 +21,7 @@
*/
using GLib;
+using Gee;
using Folks;
using SocialWebClient;
@@ -211,21 +212,24 @@ public class Swf.PersonaStore : Folks.PersonaStore
}
}
- private void contacts_added_cb (List<unowned Contact> contacts)
+ private void contacts_added_cb (GLib.List<unowned Contact> contacts)
{
- var added_personas = new Queue<Persona> ();
+ var added_personas = new HashSet<Persona> ();
foreach (var contact in contacts)
{
var persona = new Persona(this, contact);
_personas.insert(persona.iid, persona);
- added_personas.push_tail(persona);
+ added_personas.add (persona);
}
- if (added_personas.length > 0)
- this.personas_changed (added_personas.head, null, null, null, 0);
+ if (added_personas.size > 0)
+ {
+ this.personas_changed (added_personas, new HashSet<Persona> (),
+ null, null, 0);
+ }
}
- private void contacts_changed_cb (List<unowned Contact> contacts)
+ private void contacts_changed_cb (GLib.List<unowned Contact> contacts)
{
foreach (var contact in contacts)
{
@@ -240,9 +244,9 @@ public class Swf.PersonaStore : Folks.PersonaStore
}
}
- private void contacts_removed_cb (List<unowned Contact> contacts)
+ private void contacts_removed_cb (GLib.List<unowned Contact> contacts)
{
- var removed_personas = new Queue<Persona> ();
+ var removed_personas = new HashSet<Persona> ();
foreach (var contact in contacts)
{
if (this._service.get_name () != contact.service)
@@ -253,12 +257,15 @@ public class Swf.PersonaStore : Folks.PersonaStore
var persona = _personas.lookup(iid);
if (persona != null)
{
- removed_personas.push_tail(persona);
+ removed_personas.add (persona);
_personas.remove(persona.iid);
}
}
- if (removed_personas.length > 0)
- this.personas_changed (null, removed_personas.head, null, null, 0);
+ if (removed_personas.size > 0)
+ {
+ this.personas_changed (new HashSet<Persona> (), removed_personas,
+ null, null, 0);
+ }
}
}
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index c174b44..9a4685e 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -61,6 +61,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
};
private HashTable<string, Persona> _personas;
+ private HashSet<Persona> _persona_set;
/* universal, contact owner handles (not channel-specific) */
private HashMap<uint, Persona> _handle_persona_map;
private HashMap<Channel, HashSet<Persona>> _channel_group_personas_map;
@@ -203,6 +204,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
this._personas = new HashTable<string, Persona> (str_hash,
str_equal);
+ this._persona_set = new HashSet<Persona> ();
this._conn = null;
this._handle_persona_map = new HashMap<uint, Persona> ();
this._channel_group_personas_map =
@@ -265,8 +267,8 @@ public class Tpf.PersonaStore : Folks.PersonaStore
{
if (this.account == a)
{
- this.personas_changed (null, this._personas.get_values (),
- null, null, 0);
+ this.personas_changed (new HashSet<Persona> (),
+ this._persona_set, null, null, 0);
this.removed ();
}
});
@@ -274,8 +276,8 @@ public class Tpf.PersonaStore : Folks.PersonaStore
{
if (this.account == a)
{
- this.personas_changed (null, this._personas.get_values (),
- null, null, 0);
+ this.personas_changed (new HashSet<Persona> (),
+ this._persona_set, null, null, 0);
this.removed ();
}
});
@@ -284,8 +286,8 @@ public class Tpf.PersonaStore : Folks.PersonaStore
{
if (!valid && this.account == a)
{
- this.personas_changed (null, this._personas.get_values
- (), null, null, 0);
+ this.personas_changed (new HashSet<Persona> (),
+ this._persona_set, null, null, 0);
this.removed ();
}
});
@@ -479,8 +481,8 @@ public class Tpf.PersonaStore : Folks.PersonaStore
/* When disconnecting, we want the PersonaStore to remain alive, but
* all its Personas to be removed. We do *not* want the PersonaStore
* to be destroyed, as that makes coming back online hard. */
- this.personas_changed (null, this._personas.get_values (), null, null,
- 0);
+ this.personas_changed (new HashSet<Persona> (),
+ this._persona_set, null, null, 0);
this._reset ();
return;
}
@@ -638,11 +640,12 @@ public class Tpf.PersonaStore : Folks.PersonaStore
Contact contact = contacts[0];
Persona persona = this._add_persona_from_contact (contact, false);
- GLib.List<Persona> personas = new GLib.List<Persona> ();
- personas.prepend (persona);
+ var personas = new HashSet<Persona> ();
+ personas.add (persona);
this._self_contact = contact;
- this.personas_changed (personas, null, null, null, 0);
+ this.personas_changed (personas, new HashSet<Persona> (),
+ null, null, 0);
},
this);
}
@@ -984,10 +987,13 @@ public class Tpf.PersonaStore : Folks.PersonaStore
members.remove (persona);
}
- var personas = new GLib.List<Persona> ();
- personas.append (persona);
- this.personas_changed (null, personas, message, actor, reason);
+ var personas = new HashSet<Persona> ();
+ personas.add (persona);
+
+ this.personas_changed (new HashSet<Persona> (), personas,
+ message, actor, reason);
this._personas.remove (persona.iid);
+ this._persona_set.remove (persona);
}
/**
@@ -1309,7 +1315,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
}
}
- private async GLib.List<Tpf.Persona>? _create_personas_from_contact_ids (
+ private async HashSet<Persona>? _create_personas_from_contact_ids (
string[] contact_ids) throws GLib.Error
{
if (contact_ids.length > 0)
@@ -1318,7 +1324,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
yield this._ll.connection_get_contacts_by_id_async (
this._conn, contact_ids, (uint[]) _contact_features);
- GLib.List<Persona> personas = new GLib.List<Persona> ();
+ var personas = new HashSet<Persona> ();
var err_count = 0;
var err_string = "";
unowned GLib.List<TelepathyGLib.Contact> l;
@@ -1330,7 +1336,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
var persona = this._add_persona_from_contact (contact, true);
if (persona != null)
- personas.prepend (persona);
+ personas.add (persona);
}
if (err_count > 0)
@@ -1345,8 +1351,11 @@ public class Tpf.PersonaStore : Folks.PersonaStore
err_count, err_string);
}
- if (personas != null)
- this.personas_changed (personas, null, null, null, 0);
+ if (personas.size > 0)
+ {
+ this.personas_changed (personas, new HashSet<Persona> (),
+ null, null, 0);
+ }
return personas;
}
@@ -1368,6 +1377,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
persona = new Tpf.Persona (contact, this);
this._personas.insert (persona.iid, persona);
+ this._persona_set.add (persona);
this._handle_persona_map[h] = persona;
/* If the handle is a favourite, ensure the persona's marked
@@ -1409,18 +1419,22 @@ public class Tpf.PersonaStore : Folks.PersonaStore
private void _add_new_personas_from_contacts (Contact[] contacts)
{
- GLib.List<Persona> personas = new GLib.List<Persona> ();
+ var personas = new HashSet<Persona> ();
+
foreach (Contact contact in contacts)
{
var persona = this._add_persona_from_contact (contact, true);
if (persona != null)
- personas.prepend (persona);
+ personas.add (persona);
}
this._channel_groups_add_new_personas ();
- if (personas != null)
- this.personas_changed (personas, null, null, null, 0);
+ if (personas.size > 0)
+ {
+ this.personas_changed (personas, new HashSet<Persona> (),
+ null, null, 0);
+ }
}
private void _channel_groups_add_new_personas ()
@@ -1525,9 +1539,15 @@ public class Tpf.PersonaStore : Folks.PersonaStore
/* the persona already existed */
return null;
}
- else if (personas.length () == 1)
+ else if (personas.size == 1)
{
- var persona = personas.data;
+ /* Get the first (and only) Persona */
+ Persona persona = null;
+ foreach (var p in personas)
+ {
+ persona = p;
+ break;
+ }
if (this._subscribe != null)
this._change_standard_contact_list_membership (this._subscribe,
@@ -1550,7 +1570,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
{
/* We ignore the case of an empty list, as it just means the
* contact was already in our roster */
- var num_personas = personas.length ();
+ var num_personas = personas.size;
var message =
ngettext (
/* Translators: the parameter is the number of personas
diff --git a/backends/tracker/lib/trf-persona-store.vala b/backends/tracker/lib/trf-persona-store.vala
index 7cff6c2..9e8ffed 100644
--- a/backends/tracker/lib/trf-persona-store.vala
+++ b/backends/tracker/lib/trf-persona-store.vala
@@ -691,9 +691,14 @@ public class Trf.PersonaStore : Folks.PersonaStore
{
string filter = " FILTER(?_contact = <%s>) ".printf (contact_urn);
string query = this._INITIAL_QUERY.printf (filter);
- GLib.Queue<Persona> ret_personas;
- ret_personas = yield this._do_add_contacts (query);
- ret = ret_personas.pop_head ();
+ var ret_personas = yield this._do_add_contacts (query);
+
+ /* Return the first persona we find in the set */
+ foreach (var p in ret_personas)
+ {
+ ret = p;
+ break;
+ }
}
else
{
@@ -1195,7 +1200,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
private async void _handle_delete_events (owned VariantIter iter_del)
{
- var removed_personas = new GLib.Queue<Persona> ();
+ var removed_personas = new HashSet<Persona> ();
var nco_person_id =
this._prefix_tracker_id.get (Trf.OntologyDefs.NCO_PERSON);
var rdf_type_id = this._prefix_tracker_id.get (Trf.OntologyDefs.RDF_TYPE);
@@ -1213,7 +1218,7 @@ public class Trf.PersonaStore : Folks.PersonaStore
var removed_p = this._personas.lookup (p_id);
if (removed_p != null)
{
- removed_personas.push_tail (removed_p);
+ removed_personas.add (removed_p);
_personas.remove (removed_p.iid);
}
}
@@ -1228,15 +1233,16 @@ public class Trf.PersonaStore : Folks.PersonaStore
}
}
- if (removed_personas.length > 0)
+ if (removed_personas.size > 0)
{
- this.personas_changed (null, removed_personas.head, null, null, 0);
+ this.personas_changed (new HashSet<Persona> (), removed_personas,
+ null, null, 0);
}
}
private async void _handle_insert_events (owned VariantIter iter_ins)
{
- var added_personas = new GLib.Queue<Persona> ();
+ var added_personas = new HashSet<Persona> ();
Event e = Event ();
while (iter_ins.next
@@ -1252,23 +1258,24 @@ public class Trf.PersonaStore : Folks.PersonaStore
{
persona = new Trf.Persona (this, subject_tracker_id);
this._personas.insert (persona.iid, persona);
- added_personas.push_tail (persona);
+ added_personas.add (persona);
}
}
yield this._do_update (persona, e);
}
- if (added_personas.length > 0)
+ if (added_personas.size > 0)
{
- this.personas_changed (added_personas.head, null, null, null, 0);
+ this.personas_changed (added_personas, new HashSet<Persona> (),
+ null, null, 0);
}
}
- private async GLib.Queue<Persona> _do_add_contacts (string query)
+ private async HashSet<Persona> _do_add_contacts (string query)
{
- var added_personas = new GLib.Queue<Persona> ();
+ var added_personas = new HashSet<Persona> ();
- try {
+ try {
Sparql.Cursor cursor = yield this._connection.query_async (query);
while (cursor.next ())
@@ -1280,13 +1287,14 @@ public class Trf.PersonaStore : Folks.PersonaStore
var persona = new Trf.Persona (this,
tracker_id.to_string (), cursor);
this._personas.insert (persona.iid, persona);
- added_personas.push_tail (persona);
+ added_personas.add (persona);
}
}
- if (added_personas.length > 0)
+ if (added_personas.size > 0)
{
- this.personas_changed (added_personas.head, null, null, null, 0);
+ this.personas_changed (added_personas,
+ new HashSet<Persona> (), null, null, 0);
}
} catch (GLib.Error e) {
warning ("Couldn't perform queries: %s %s", query, e.message);
diff --git a/folks/individual-aggregator.vala b/folks/individual-aggregator.vala
index 98a70d4..b062561 100644
--- a/folks/individual-aggregator.vala
+++ b/folks/individual-aggregator.vala
@@ -381,7 +381,7 @@ public class Folks.IndividualAggregator : Object
return type_id + ":" + id;
}
- private void _add_personas (GLib.List<Persona> added,
+ private void _add_personas (Set<Persona> added,
ref GLib.List<Individual> added_individuals,
ref HashMap<Individual, Individual> replaced_individuals,
ref Individual user)
@@ -624,8 +624,8 @@ public class Folks.IndividualAggregator : Object
}
private void _personas_changed_cb (PersonaStore store,
- GLib.List<Persona>? added,
- GLib.List<Persona>? removed,
+ Set<Persona> added,
+ Set<Persona> removed,
string? message,
Persona? actor,
GroupDetails.ChangeReason reason)
@@ -633,9 +633,7 @@ public class Folks.IndividualAggregator : Object
var added_individuals = new GLib.List<Individual> ();
GLib.List<Individual> removed_individuals = null;
var replaced_individuals = new HashMap<Individual, Individual> ();
- GLib.List<Persona> relinked_personas = null;
- var relinked_personas_set = new HashSet<Persona> (direct_hash,
- direct_equal);
+ var relinked_personas = new HashSet<Persona> ();
var removed_personas = new HashSet<Persona> (direct_hash, direct_equal);
/* We store the value of this.user locally and only update it at the end
@@ -643,7 +641,7 @@ public class Folks.IndividualAggregator : Object
* property. */
var user = this.user;
- if (added != null)
+ if (added.size > 0)
{
this._add_personas (added, ref added_individuals,
ref replaced_individuals, ref user);
@@ -651,10 +649,8 @@ public class Folks.IndividualAggregator : Object
debug ("Removing Personas:");
- removed.foreach ((p) =>
+ foreach (var persona in removed)
{
- var persona = (Persona) p;
-
debug (" %s (is user: %s, IID: %s)", persona.uid,
persona.is_user ? "yes" : "no", persona.iid);
@@ -671,7 +667,7 @@ public class Folks.IndividualAggregator : Object
/* Remove the Persona's links from the link map */
this._remove_persona_from_link_map (persona);
- });
+ }
/* Remove the Individuals which were pointed to by the linkable properties
* of the removed Personas. We can then re-link the other Personas in
@@ -694,11 +690,10 @@ public class Folks.IndividualAggregator : Object
foreach (var persona in individual.personas)
{
if (removed_personas.contains (persona) == true ||
- relinked_personas_set.contains (persona) == true)
+ relinked_personas.contains (persona) == true)
continue;
- relinked_personas.prepend (persona);
- relinked_personas_set.add (persona);
+ relinked_personas.add (persona);
/* Remove links to the Persona */
this._remove_persona_from_link_map (persona);
diff --git a/folks/individual.vala b/folks/individual.vala
index 40e5abe..b5fb594 100644
--- a/folks/individual.vala
+++ b/folks/individual.vala
@@ -635,22 +635,20 @@ public class Folks.Individual : Object,
}
private void _store_personas_changed_cb (PersonaStore store,
- GLib.List<Persona>? added,
- GLib.List<Persona>? removed,
+ Set<Persona> added,
+ Set<Persona> removed,
string? message,
Persona? actor,
GroupDetails.ChangeReason reason)
{
var removed_personas = new HashSet<Persona> ();
- removed.foreach ((data) =>
+ foreach (var p in removed)
{
- var p = (Persona) data;
-
if (this._persona_set.remove (p))
{
removed_personas.add (p);
}
- });
+ }
if (removed_personas != null)
this.personas_changed (new HashSet<Persona> (), removed_personas);
diff --git a/folks/persona-store.vala b/folks/persona-store.vala
index f01bc5e..1d15980 100644
--- a/folks/persona-store.vala
+++ b/folks/persona-store.vala
@@ -19,6 +19,7 @@
*/
using GLib;
+using Gee;
/**
* Trust level for a { link PersonaStore}'s { link Persona}s for linking
@@ -189,14 +190,16 @@ public abstract class Folks.PersonaStore : Object
* This will not be emitted until after { link PersonaStore.prepare} has been
* called.
*
- * @param added a list of { link Persona}s which have been removed
- * @param removed a list of { link Persona}s which have been removed
+ * @param added a set of { link Persona}s which have been removed
+ * @param removed a set of { link Persona}s which have been removed
* @param message a string message from the backend, if any
* @param actor the { link Persona} who made the change, if known
* @param reason the reason for the change
+ *
+ * @since UNRELEASED
*/
- public signal void personas_changed (GLib.List<Persona>? added,
- GLib.List<Persona>? removed,
+ public signal void personas_changed (Set<Persona> added,
+ Set<Persona> removed,
string? message,
Persona? actor,
GroupDetails.ChangeReason reason);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]