Commit 3a3ddc16 authored by Travis Reitter's avatar Travis Reitter
Browse files

Support UrlDetails for the Telepathy backend.

parent c3909745
......@@ -10,6 +10,7 @@ API changes:
* Implement PhoneDetails on Tpf.Persona
* Implement NameDetails on Tpf.Persona
* Implement EmailDetails on Tpf.Persona
* Implement UrlDetails on Tpf.Persona
Overview of changes from libfolks 0.6.3.1 to libfolks 0.6.3.2
=============================================================
......
......@@ -36,7 +36,8 @@ public class Tpf.Persona : Folks.Persona,
ImDetails,
NameDetails,
PhoneDetails,
PresenceDetails
PresenceDetails,
UrlDetails
{
private HashSet<string> _groups;
private Set<string> _groups_ro;
......@@ -423,6 +424,32 @@ public class Tpf.Persona : Folks.Persona,
this._phone_numbers, "tel");
}
private HashSet<UrlFieldDetails> _urls;
private Set<UrlFieldDetails> _urls_ro;
/**
* {@inheritDoc}
*
* @since UNRELEASED
*/
[CCode (notify = false)]
public Set<UrlFieldDetails> urls
{
get { return this._urls_ro; }
set { this.change_urls.begin (value); }
}
/**
* {@inheritDoc}
*
* @since UNRELEASED
*/
public async void change_urls (Set<UrlFieldDetails> urls) throws PropertyError
{
yield this._change_details<UrlFieldDetails> (urls,
this._urls, "url");
}
private async void _change_details<T> (
Set<AbstractFieldDetails<string>> details,
Set<AbstractFieldDetails<string>> member_set,
......@@ -538,6 +565,10 @@ public class Tpf.Persona : Folks.Persona,
(GLib.HashFunc) PhoneFieldDetails.hash,
(GLib.EqualFunc) PhoneFieldDetails.equal);
this._phone_numbers_ro = this._phone_numbers.read_only_view;
this._urls = new HashSet<UrlFieldDetails> (
(GLib.HashFunc) UrlFieldDetails.hash,
(GLib.EqualFunc) UrlFieldDetails.equal);
this._urls_ro = this._urls.read_only_view;
contact.notify["avatar-file"].connect ((s, p) =>
{
......@@ -614,6 +645,8 @@ public class Tpf.Persona : Folks.Persona,
this._writeable_properties += "full-name";
if ("tel" in tpf_store.supported_fields)
this._writeable_properties += "phone-numbers";
if ("url" in tpf_store.supported_fields)
this._writeable_properties += "urls";
}
private void _contact_notify_contact_info ()
......@@ -625,6 +658,9 @@ public class Tpf.Persona : Folks.Persona,
var new_phone_numbers = new HashSet<PhoneFieldDetails> (
(GLib.HashFunc) PhoneFieldDetails.hash,
(GLib.EqualFunc) PhoneFieldDetails.equal);
var new_urls = new HashSet<UrlFieldDetails> (
(GLib.HashFunc) UrlFieldDetails.hash,
(GLib.EqualFunc) UrlFieldDetails.equal);
var contact_info = this.contact.get_contact_info ();
foreach (var info in contact_info)
......@@ -652,6 +688,15 @@ public class Tpf.Persona : Folks.Persona,
new_phone_numbers.add (phone_fd);
}
}
else if (info.field_name == "url")
{
foreach (var url in info.field_value)
{
var parameters = this._afd_params_from_strv (info.parameters);
var url_fd = new UrlFieldDetails (url, parameters);
new_urls.add (url_fd);
}
}
}
if (!Folks.Internal.equal_sets<EmailFieldDetails> (new_email_addresses,
......@@ -675,6 +720,13 @@ public class Tpf.Persona : Folks.Persona,
this._phone_numbers_ro = new_phone_numbers.read_only_view;
this.notify_property ("phone-numbers");
}
if (!Folks.Internal.equal_sets<UrlFieldDetails> (new_urls, this._urls))
{
this._urls = new_urls;
this._urls_ro = new_urls.read_only_view;
this.notify_property ("urls");
}
}
private MultiMap<string, string> _afd_params_from_strv (string[] parameters)
......
......@@ -430,6 +430,13 @@ conn_contact_info_properties_getter (GObject *object,
G_TYPE_UINT, 0,
G_TYPE_UINT, G_MAXUINT32,
G_TYPE_INVALID));
g_ptr_array_add (supported_fields, tp_value_array_build (4,
G_TYPE_STRING, "url",
G_TYPE_STRV, NULL,
G_TYPE_UINT, 0,
G_TYPE_UINT, G_MAXUINT32,
G_TYPE_INVALID));
}
g_value_set_boxed (value, supported_fields);
}
......
......@@ -527,6 +527,11 @@ receive_contact_lists (gpointer p)
_insert_contact_field (d->contact_info, "email", NULL,
(const gchar * const *) values);
}
{
const gchar * values[] = { "ocrete.example.com", NULL };
_insert_contact_field (d->contact_info, "url", NULL,
(const gchar * const *) values);
}
tp_handle_unref (self->priv->contact_repo, handle);
id = "travis@example.com";
......
......@@ -113,6 +113,7 @@ public class IndividualPropertiesTests : Folks.TestCase
assert (("full-name" in tpf_persona.writeable_properties));
assert (
("phone-numbers" in tpf_persona.writeable_properties));
assert ("urls" in tpf_persona.writeable_properties);
/* Check ContactInfo-provided properties */
assert (i.full_name == "");
......@@ -156,6 +157,7 @@ public class IndividualPropertiesTests : Folks.TestCase
assert (!("full-name" in tpf_persona.writeable_properties));
assert (
!("phone-numbers" in tpf_persona.writeable_properties));
assert (!("urls" in tpf_persona.writeable_properties));
/* Check ContactInfo-provided properties */
assert (new PhoneFieldDetails ("+15142345678")
......@@ -163,6 +165,7 @@ public class IndividualPropertiesTests : Folks.TestCase
assert (i.full_name == "Olivier Crete");
assert (new EmailFieldDetails ("olivier@example.com")
in i.email_addresses);
assert (new UrlFieldDetails ("ocrete.example.com") in i.urls);
}
}
......@@ -355,6 +358,7 @@ public class IndividualPropertiesTests : Folks.TestCase
this._changes_pending.add ("email-addresses");
this._changes_pending.add ("phone-numbers");
this._changes_pending.add ("full-name");
this._changes_pending.add ("urls");
/* Set up the aggregator */
var aggregator = new IndividualAggregator ();
......@@ -394,6 +398,9 @@ public class IndividualPropertiesTests : Folks.TestCase
var new_phone_fd = new PhoneFieldDetails ("+112233445566");
new_phone_fd.set_parameter (AbstractFieldDetails.PARAM_TYPE,
AbstractFieldDetails.PARAM_TYPE_HOME);
var new_url_fd = new UrlFieldDetails ("aperturescience.com/cave");
new_url_fd.set_parameter (AbstractFieldDetails.PARAM_TYPE,
AbstractFieldDetails.PARAM_TYPE_WORK);
var new_full_name = "Cave Johnson";
foreach (Individual i in added)
......@@ -404,6 +411,7 @@ public class IndividualPropertiesTests : Folks.TestCase
assert (!(new_email_fd in i.email_addresses));
assert (new_full_name != i.full_name);
assert (!(new_phone_fd in i.phone_numbers));
assert (!(new_url_fd in i.urls));
i.notify["email-addresses"].connect ((s, p) =>
{
......@@ -436,6 +444,17 @@ public class IndividualPropertiesTests : Folks.TestCase
}
});
i.notify["urls"].connect ((s, p) =>
{
/* we can't re-use i here due to Vala's implementation */
var ind = (Individual) s;
if (new_url_fd in ind.urls)
{
this._changes_pending.remove ("urls");
}
});
/* the contact list this aggregator is based upon has exactly 1
* Tpf.Persona per Individual */
Folks.Persona persona = null;
......@@ -454,6 +473,10 @@ public class IndividualPropertiesTests : Folks.TestCase
(GLib.HashFunc) PhoneFieldDetails.hash,
(GLib.EqualFunc) PhoneFieldDetails.equal);
phones.add (new_phone_fd);
var urls = new HashSet<UrlFieldDetails> (
(GLib.HashFunc) UrlFieldDetails.hash,
(GLib.EqualFunc) UrlFieldDetails.equal);
urls.add (new_url_fd);
/* set the extended info through Telepathy's ContactInfo interface and
* wait for it to hit our notification callback above */
......@@ -503,6 +526,20 @@ public class IndividualPropertiesTests : Folks.TestCase
uncaught_errors--;
}
if (!i.is_user)
uncaught_errors++;
try
{
yield ((Tpf.Persona) persona).change_urls (urls);
}
catch (PropertyError e3)
{
/* setting the extended info on a non-user is invalid for the
* Telepathy backend */
if (!i.is_user)
uncaught_errors--;
}
if (!i.is_user)
{
assert (uncaught_errors == 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment