diff options
author | Philip Withnall <philip.withnall@collabora.co.uk> | 2010-12-17 18:36:45 +0000 |
---|---|---|
committer | Philip Withnall <philip.withnall@collabora.co.uk> | 2011-02-06 11:04:52 +0000 |
commit | 05cca833976054240e62b4d0df00954059440580 (patch) | |
tree | 0a36e7007d325c8893e921bd519988de2237bcf4 | |
parent | c7071fb3c49984f858820129e46b457cf3430114 (diff) |
Bug 640901 — Allow to determine whether a Tpf.Persona's in the contact list
Add Tpf.Persona.is-in-contact-list, which is true iff the persona's in the
user's contact list. Closes: bgo#640901
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | backends/telepathy/lib/tpf-persona-store.vala | 66 | ||||
-rw-r--r-- | backends/telepathy/lib/tpf-persona.vala | 12 |
3 files changed, 71 insertions, 10 deletions
@@ -11,6 +11,7 @@ API changes: * IMable.im_addresses is now a mapping of string to LinkedHashSet. * Rename the HasAvatar interface to AvatarOwner * Rename the HasPresence interface to PresenceOwner +* Add Tpf.Persona.is_in_contact_list Bugs fixed: * Bug 637240 — libfolks-telepathy.so exports private symbols @@ -25,6 +26,8 @@ Bugs fixed: * Bug 639742 — Logger service unavailable in make check * Bug 640213 — Add tests for LinkedHashSet * Bug 627397 — Use better interface names +* Bug 640901 — Allow it to be determined whether a user Tpf.Persona is in the + contact list Overview of changes from libfolks 0.3.2 to libfolks 0.3.3 ========================================================= diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala index 0a95cd5..8fcda26 100644 --- a/backends/telepathy/lib/tpf-persona-store.vala +++ b/backends/telepathy/lib/tpf-persona-store.vala @@ -606,9 +606,11 @@ public class Tpf.PersonaStore : Folks.PersonaStore return; } + debug ("Creating persona from self-handle"); + /* Add the local user */ Contact contact = contacts[0]; - Persona persona = this._add_persona_from_contact (contact); + Persona persona = this._add_persona_from_contact (contact, false); GLib.List<Persona> personas = new GLib.List<Persona> (); personas.prepend (persona); @@ -972,7 +974,8 @@ public class Tpf.PersonaStore : Folks.PersonaStore { var tp_persona = (Tpf.Persona) persona; - if (tp_persona.contact == this._self_contact) + if (tp_persona.contact == this._self_contact && + tp_persona.is_in_contact_list == false) { throw new PersonaStoreError.UNSUPPORTED_ON_USER ( _("Personas representing the local user may not be removed.")); @@ -1209,9 +1212,24 @@ public class Tpf.PersonaStore : Folks.PersonaStore { var channel_handle = (Handle) channel_handles.index (i); var contact_handle = channel.group_get_handle_owner (channel_handle); + Persona? persona = this._handle_persona_map[contact_handle]; - if (this._handle_persona_map[contact_handle] == null) - contact_handles += contact_handle; + if (persona == null) + { + contact_handles += contact_handle; + } + else + { + /* Mark the persona as having been seen in the contact list. + * The persona might have originally been discovered by querying + * the Telepathy connection's self-handle; in this case, its + * is-in-contact-list property will originally be false, as a + * contact could be exposed as the self-handle, but not actually + * be in the user's contact list. */ + debug ("Setting is-in-contact-list for '%s' to true", + persona.uid); + persona.is_in_contact_list = true; + } } try @@ -1266,7 +1284,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore debug ("Creating persona from contact '%s'", contact.identifier); - var persona = this._add_persona_from_contact (contact); + var persona = this._add_persona_from_contact (contact, true); if (persona != null) personas.prepend (persona); } @@ -1292,15 +1310,18 @@ public class Tpf.PersonaStore : Folks.PersonaStore return null; } - private Tpf.Persona? _add_persona_from_contact (Contact contact) + private Tpf.Persona? _add_persona_from_contact (Contact contact, + bool from_contact_list) { var h = contact.get_handle (); + Persona? persona = null; debug ("Adding persona from contact '%s'", contact.identifier); - if (this._handle_persona_map[h] == null) + persona = this._handle_persona_map[h]; + if (persona == null) { - var persona = new Tpf.Persona (contact, this); + persona = new Tpf.Persona (contact, this); this._personas.insert (persona.iid, persona); this._handle_persona_map[h] = persona; @@ -1311,10 +1332,35 @@ public class Tpf.PersonaStore : Folks.PersonaStore * favourite. */ persona.is_favourite = this._favourite_handles.contains (h); + /* Only emit this debug message in the false case to reduce debug + * spam (see https://bugzilla.gnome.org/show_bug.cgi?id=640901#c2). */ + if (from_contact_list == false) + { + debug (" Setting is-in-contact-list to false"); + } + + persona.is_in_contact_list = from_contact_list; + return persona; } + else + { + debug (" ...already exists."); + + /* Mark the persona as having been seen in the contact list. + * The persona might have originally been discovered by querying + * the Telepathy connection's self-handle; in this case, its + * is-in-contact-list property will originally be false, as a + * contact could be exposed as the self-handle, but not actually + * be in the user's contact list. */ + if (persona.is_in_contact_list == false && from_contact_list == true) + { + debug (" Setting is-in-contact-list to true"); + persona.is_in_contact_list = true; + } - return null; + return null; + } } private void _add_new_personas_from_contacts (Contact[] contacts) @@ -1322,7 +1368,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore GLib.List<Persona> personas = new GLib.List<Persona> (); foreach (Contact contact in contacts) { - var persona = this._add_persona_from_contact (contact); + var persona = this._add_persona_from_contact (contact, true); if (persona != null) personas.prepend (persona); } diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala index 4666842..6b8151d 100644 --- a/backends/telepathy/lib/tpf-persona.vala +++ b/backends/telepathy/lib/tpf-persona.vala @@ -48,6 +48,18 @@ public class Tpf.Persona : Folks.Persona, private bool _is_constructed = false; /** + * Whether the Persona is in the user's contact list. + * + * This will be true for most {@link Folks.Persona}s, but may not be true for + * personas where {@link Folks.Persona.is_user} is true. If it's false in + * this case, it means that the persona has been retrieved from the Telepathy + * connection, but has not been added to the user's contact list. + * + * @since 0.3.UNRELEASED + */ + public bool is_in_contact_list { get; set; } + + /** * An avatar for the Persona. * * See {@link Folks.AvatarOwner.avatar}. |