[folks] Support the Persona.is_user property in the telepathy backend
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] Support the Persona.is_user property in the telepathy backend
- Date: Tue, 21 Sep 2010 09:22:32 +0000 (UTC)
commit 95a282dc35afcaea7534bde0fff2831d25957f83
Author: Philip Withnall <philip withnall collabora co uk>
Date: Mon Aug 23 17:26:35 2010 +0100
Support the Persona.is_user property in the telepathy backend
Closes: bgo#627402
NEWS | 3 +
backends/telepathy/lib/tpf-persona-store.vala | 72 ++++++++++++++++++++++++-
backends/telepathy/lib/tpf-persona.vala | 6 ++-
folks/persona-store.vala | 8 +++
4 files changed, 86 insertions(+), 3 deletions(-)
---
diff --git a/NEWS b/NEWS
index 64709a4..a9b4dd9 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ Major changes:
* Bumped gobject-introspection dependency to 0.9.6
* Ensured IM addresses are normalised before being compared
* Made the folks-import build optional through a configure argument
+* Added support for a â??selfâ?? individual
API changes:
* Added IMable.normalise_im_address()
@@ -22,6 +23,7 @@ API changes:
* Added Individual::is-user
* Added Persona::is-user
* Added IndividualAggregator::user
+* Added PersonaStoreError.UNSUPPORTED_ON_USER
Bugs fixed:
* Bug 629452 â?? [Patch] Add missing gio linking for import-tool
@@ -31,6 +33,7 @@ Bugs fixed:
* Bug 629666 â?? libfolks should not hard autodetect libxml
* Bug 628970 â?? Folks API needs a way to determine whether a specific type of
PersonaStore is available
+* Bug 627402 â?? Support marking FolksPersonas as "me"
Overview of changes from libfolks 0.1.16 to libfolks 0.1.17
===========================================================
diff --git a/backends/telepathy/lib/tpf-persona-store.vala b/backends/telepathy/lib/tpf-persona-store.vala
index 99d3690..637a1d6 100644
--- a/backends/telepathy/lib/tpf-persona-store.vala
+++ b/backends/telepathy/lib/tpf-persona-store.vala
@@ -55,6 +55,7 @@ public class Tpf.PersonaStore : Folks.PersonaStore
private TpLowlevel ll;
private AccountManager account_manager;
private Logger logger;
+ private Contact self_contact;
internal signal void group_members_changed (string group,
GLib.List<Persona>? added, GLib.List<Persona>? removed);
@@ -393,10 +394,70 @@ public class Tpf.PersonaStore : Folks.PersonaStore
this.add_standard_channel (c, "subscribe");
this.conn = c;
+ /* Add the local user */
+ conn.notify["self-handle"].connect (this.self_handle_changed_cb);
+ if (conn.self_handle != 0)
+ this.self_handle_changed_cb (conn, null);
+
/* We can only initialise the favourite contacts once conn is prepared */
this.initialise_favourite_contacts.begin ();
}
+ private void self_handle_changed_cb (Object s, ParamSpec? p)
+ {
+ Connection c = (Connection) s;
+
+ /* Remove the old self persona */
+ if (this.self_contact != null)
+ this.ignore_by_handle (this.self_contact.handle, null, null, 0);
+
+ /* Add the new self persona */
+ ContactFeature[] features =
+ {
+ ALIAS,
+ /* XXX: also avatar token? */
+ PRESENCE
+ };
+
+ if (c.self_handle == 0)
+ return;
+
+ uint[] contact_handles = { c.self_handle };
+
+ /* We have to do it this way instead of using
+ * TpLowleve.get_contacts_by_handle_async() as we're in a notification
+ * callback */
+ c.get_contacts_by_handle (contact_handles, (uint[]) features,
+ (conn, contacts, failed, error, weak_object) =>
+ {
+ if (error != null)
+ {
+ warning ("Failed to create contact for self handle '%u': %s",
+ conn.self_handle, error.message);
+ return;
+ }
+
+ /* Add the local user */
+ Contact contact = contacts[0];
+ try
+ {
+ Persona persona = this.add_persona_from_contact (contact);
+
+ GLib.List<Persona> personas = new GLib.List<Persona> ();
+ personas.prepend (persona);
+
+ this.self_contact = contact;
+ this.personas_changed (personas, null, null, null, 0);
+ }
+ catch (Tpf.PersonaError e)
+ {
+ warning ("Failed to create self persona from contact '%s' " +
+ "(%p)", contact.alias, contact);
+ }
+ },
+ this);
+ }
+
private void new_group_channels_cb (TelepathyGLib.Channel? channel,
GLib.AsyncResult? result)
{
@@ -644,6 +705,9 @@ public class Tpf.PersonaStore : Folks.PersonaStore
debug ("Ignoring handle %u (persona: %p)", handle, persona);
+ if (this.self_contact != null && this.self_contact.handle == handle)
+ this.self_contact = null;
+
/*
* remove all handle-keyed entries
*/
@@ -685,9 +749,16 @@ public class Tpf.PersonaStore : Folks.PersonaStore
* See { link Folks.PersonaStore.remove_persona}.
*/
public override async void remove_persona (Folks.Persona persona)
+ throws Folks.PersonaStoreError
{
var tp_persona = (Tpf.Persona) persona;
+ if (tp_persona.contact == this.self_contact)
+ {
+ throw new PersonaStoreError.UNSUPPORTED_ON_USER (
+ "Personas representing the local user may not be removed.");
+ }
+
try
{
this.ll.channel_group_change_membership (this.stored,
@@ -1017,7 +1088,6 @@ public class Tpf.PersonaStore : Folks.PersonaStore
return null;
}
-
private void add_new_personas_from_contacts (Contact[] contacts)
{
GLib.List<Persona> personas = new GLib.List<Persona> ();
diff --git a/backends/telepathy/lib/tpf-persona.vala b/backends/telepathy/lib/tpf-persona.vala
index d830c5c..a8eba61 100644
--- a/backends/telepathy/lib/tpf-persona.vala
+++ b/backends/telepathy/lib/tpf-persona.vala
@@ -213,7 +213,8 @@ public class Tpf.Persona : Folks.Persona,
throw new Tpf.PersonaError.INVALID_ARGUMENT ("contact has an " +
"invalid ID");
- var account = account_for_connection (contact.get_connection ());
+ unowned Connection connection = contact.get_connection ();
+ var account = account_for_connection (connection);
string uid = this.build_uid ("telepathy", account.get_protocol (), id);
var alias = contact.get_alias ();
@@ -233,7 +234,8 @@ public class Tpf.Persona : Folks.Persona,
iid: account.get_protocol () + ":" + id,
uid: uid,
store: store,
- linkable_properties: linkable_properties);
+ linkable_properties: linkable_properties,
+ is_user: contact.handle == connection.self_handle);
debug ("Creating new Tpf.Persona '%s' for service-specific UID '%s': %p",
uid, id, this);
diff --git a/folks/persona-store.vala b/folks/persona-store.vala
index fa5a2d8..f1e6e3a 100644
--- a/folks/persona-store.vala
+++ b/folks/persona-store.vala
@@ -76,6 +76,14 @@ public errordomain Folks.PersonaStoreError
* Creation of a { link Persona} failed.
*/
CREATE_FAILED,
+
+ /**
+ * Such an operation may not be performed on a { link Persona} with
+ * { link Persona.is_user} set to `true`.
+ *
+ * @since 0.3.0
+ */
+ UNSUPPORTED_ON_USER,
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]