add convenience API to get a Persona by its UID
Submitted by Simon McVittie
Assigned to fol..@..e.bugs
Link to original bug (#696215)
Description
Individual.id's documentation says:
- If an identifier is required which will be used for a long-lived link
- between different stored data, it may be more desirable to use the
- {@link Persona.uid} of the most relevant {@link Persona} in the Individual
So, suppose I saved a uid in a file last time my application ran. Now I'm running it again and I want to get the Persona for that saved UID.
According to comments in Persona, the UID might look like telepathy:jabber:foo@xmpp.example.org or key-file:relationships.ini:joe@example.org.
Using Persona.split_uid() I can split it into its three colon-separated parts, and unescape them. So far so good.
As far as I can tell, the first part is a backend ID, which I can resolve to a Backend with:
var backend = BackendStore.dup ().dup_backend_by_name (part1)
The second part is a persona store ID, which I can resolve to a PersonaStore with:
var persona_store = backend.persona_stores[part2]
(It might be less Gee-centric and more introspectable if there was a method "PersonaStore? Backend.dup_persona_store()" here.)
... but it stops there. The third part is a "Persona ID" which does not seem to be the same thing as a Persona.iid. PersonaStore.personas is keyed by Persona.iid, so unless I'm missing something, I can't look up a Persona by its "Persona ID", except via:
foreach (var persona in persona_store.personas)
{
if (persona.id == part3)
return persona;
}
which hardly seems optimal!
In the e-d-s backend, the IID happens to be "eds:" + the third part of the Persona.uid (which, confusingly, is also called a UID in e-d-s jargon) but in the Telepathy backend it's the Telepathy protocol name (e.g. jabber) + ":" + the third part of the uid.
Straw-man API proposal: any of these:
/* takes the uid, throws away the first two components or perhaps
* asserts/g_return_if_fails that they match it */
Persona? PersonaStore.dup_persona_by_uid (string uid);
/* takes only the third component */
Persona? PersonaStore.dup_persona_by_id (string id);
/* not necessarily very good: if null, you can't tell why you failed */
Persona? BackendStore.get_persona_by_uid (string uid);
Persona? BackendStore.get_persona_by_uid (string uid,
out Backend? backend, out PersonaStore? persona_store);
Version: git master