Commit 23027313 authored by Philip Withnall's avatar Philip Withnall
Browse files

core: Clarify nullability of a few properties

AliasDetails.alias, NameDetails.nickname and NameDetails.full_name must never
be set to null. The empty string represents an unset value for these
properties.
parent 9daadb60
......@@ -266,8 +266,13 @@ public class Edsf.PersonaStore : Folks.PersonaStore
if (k == Folks.PersonaStore.detail_key (
PersonaDetail.FULL_NAME))
{
contact.set (E.Contact.field_id ("full_name"),
v.get_string ());
var full_name = v.get_string ();
if (full_name == "")
{
full_name = null;
}
contact.set (E.Contact.field_id ("full_name"), full_name);
}
else if (k == Folks.PersonaStore.detail_key (
PersonaDetail.EMAIL_ADDRESSES))
......@@ -1296,6 +1301,11 @@ public class Edsf.PersonaStore : Folks.PersonaStore
internal async void _set_full_name (Edsf.Persona persona,
string full_name) throws PropertyError
{
if (full_name == "")
{
full_name = null;
}
if (persona.full_name == full_name)
return;
......@@ -1306,6 +1316,11 @@ public class Edsf.PersonaStore : Folks.PersonaStore
internal async void _set_nickname (Edsf.Persona persona, string nickname)
throws PropertyError
{
if (nickname == "")
{
nickname = null;
}
if (persona.nickname == nickname)
return;
......
......@@ -1008,6 +1008,12 @@ public class Edsf.Persona : Folks.Persona,
private void _update_names ()
{
string full_name = (string) this._get_property ("full_name");
if (full_name == null)
{
full_name = "";
}
if (this._full_name != full_name)
{
this._full_name = full_name;
......@@ -1015,7 +1021,13 @@ public class Edsf.Persona : Folks.Persona,
}
string nickname = (string) this._get_property ("nickname");
if (this.nickname != nickname)
if (nickname == null)
{
nickname = "";
}
if (this._nickname != nickname)
{
this._nickname = nickname;
this.notify_property ("nickname");
......
......@@ -36,7 +36,7 @@ public class Folks.Backends.Kf.Persona : Folks.Persona,
private unowned GLib.KeyFile _key_file;
private HashMultiMap<string, ImFieldDetails> _im_addresses;
private HashMultiMap<string, WebServiceFieldDetails> _web_service_addresses;
private string _alias;
private string _alias = ""; /* must not be null */
private const string[] _linkable_properties =
{
"im-addresses",
......@@ -86,6 +86,12 @@ public class Folks.Backends.Kf.Persona : Folks.Persona,
*/
public async void change_alias (string alias) throws PropertyError
{
/* Deal with badly-behaved callers. */
if (alias == null)
{
alias = "";
}
if (this._alias == alias)
{
return;
......@@ -286,6 +292,12 @@ public class Folks.Backends.Kf.Persona : Folks.Persona,
{
this._alias = this._key_file.get_string (this.display_id,
key);
if (this._alias == null)
{
this._alias = "";
}
debug (" Loaded alias '%s'.", this._alias);
continue;
}
......
......@@ -307,7 +307,13 @@ public class Swf.Persona : Folks.Persona,
public void update (Contact contact)
{
var nickname = contact.get_value ("name");
if (nickname != null && this._nickname != nickname)
if (nickname == null)
{
nickname = "";
}
if (this._nickname != nickname)
{
this._nickname = nickname;
this.notify_property ("nickname");
......@@ -343,6 +349,12 @@ public class Swf.Persona : Folks.Persona,
}
var full_name = contact.get_value ("fn");
if (full_name == null)
{
full_name = "";
}
if (this._full_name != full_name)
{
this._full_name = full_name;
......
......@@ -2086,6 +2086,12 @@ public class Tpf.PersonaStore : Folks.PersonaStore
internal async void change_alias (Tpf.Persona persona, string alias)
{
/* Deal with badly-behaved callers */
if (alias == null)
{
alias = "";
}
debug ("Changing alias of persona %u to '%s'.", persona.contact.handle,
alias);
FolksTpLowlevel.connection_set_contact_alias (this._conn,
......
......@@ -38,7 +38,7 @@ public class Tpf.Persona : Folks.Persona,
private HashSet<string> _groups;
private Set<string> _groups_ro;
private bool _is_favourite;
private string _alias;
private string _alias; /* must never be null */
private HashMultiMap<string, ImFieldDetails> _im_addresses;
private const string[] _linkable_properties = { "im-addresses" };
private const string[] _writeable_properties =
......@@ -316,6 +316,9 @@ public class Tpf.Persona : Folks.Persona,
contact.notify["alias"].connect ((s, p) =>
{
/* Tp guarantees that aliases are always non-null. */
assert (this.contact.alias != null);
if (this._alias != this.contact.alias)
{
this._alias = this.contact.alias;
......@@ -447,6 +450,12 @@ public class Tpf.Persona : Folks.Persona,
this._groups_ro = this._groups.read_only_view;
// Other properties
if (alias == null)
{
/* Deal with badly-behaved callers */
alias = "";
}
this._alias = alias;
this._is_favourite = is_favourite;
this.is_in_contact_list = is_in_contact_list;
......
......@@ -45,7 +45,7 @@ public class Trf.Persona : Folks.Persona,
UrlDetails,
WebServiceDetails
{
private string _nickname;
private string _nickname; /* must never be null */
private bool _is_favourite;
private const string[] _linkable_properties =
{"im-addresses", "local-ids", "web-service-addresses"};
......@@ -525,6 +525,11 @@ public class Trf.Persona : Folks.Persona,
if (cursor != null)
{
fullname = cursor.get_string (Trf.Fields.FULL_NAME).dup ();
if (fullname == null)
{
fullname = "";
}
var contact_urn = cursor.get_string (Trf.Fields.CONTACT_URN);
if (contact_urn == Trf.OntologyDefs.DEFAULT_CONTACT_URN)
{
......@@ -631,7 +636,12 @@ public class Trf.Persona : Folks.Persona,
internal void _update_full_name (string? fn)
{
if (fn != null && this.full_name != fn)
if (fn == null)
{
fn = "";
}
if (this._full_name != fn)
{
this._full_name = fn;
this.notify_property ("full-name");
......@@ -640,7 +650,12 @@ public class Trf.Persona : Folks.Persona,
internal void _update_nickname (string? nickname)
{
if (nickname != null && this._nickname != nickname)
if (nickname == null)
{
nickname = "";
}
if (this._nickname != nickname)
{
this._nickname = nickname;
this.notify_property ("nickname");
......
......@@ -33,6 +33,8 @@ public interface Folks.AliasDetails : Object
*
* An alias is a user-given name, to be used in UIs as the sole way to
* represent the contact to the user.
*
* This may not be `null`: an empty string represents an unset alias.
*/
public abstract string alias { get; set; }
......
......@@ -254,6 +254,9 @@ public interface Folks.NameDetails : Object
* The full name could or could not contain additional names (like a
* middle name), prefixes or suffixes.
*
* The full name must not be `null`: the empty string represents an unset full
* name.
*
* @since 0.3.5
*/
public abstract string full_name { get; set; }
......@@ -289,6 +292,9 @@ public interface Folks.NameDetails : Object
* address book when updating the information a contact has specified about
* themselves.
*
* The nickname must not be `null`: the empty string represents an unset
* nickname.
*
* @since 0.3.5
*/
public abstract string nickname { get; set; }
......
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