* See bgo#630822. */
private HashSet<string> _favourite_ids = new HashSet<string> ();
+ /* Mapping from Persona IIDs to their avatars. This allows avatars to persist
+ * between the cached (offline) personas and the online personas. Note that
+ * this should *not* be cleared in _reset(). */
+ private HashMap<string, File> _avatars = new HashMap<string, File> ();
+
private Connection _conn;
private AccountManager? _account_manager; /* only null before prepare() */
private Logger _logger;
debug.unindent ();
+ debug.print_line (domain, level, "Cached avatars for %u personas:",
+ this._avatars.size);
+ debug.indent ();
+
+ foreach (var id in this._avatars.keys)
+ {
+ debug.print_line (domain, level, "%s", id);
+ }
+
+ debug.unindent ();
+
debug.print_line (domain, level, "");
}
Internal.profiling_point ("created account manager in " +
"Tpf.PersonaStore (ID: %s)", this.id);
+ this._avatars.clear ();
+
this._favourite_ids.clear ();
this._logger = new Logger (this.id);
this._logger.invalidated.connect (
this._reset ();
}
+ internal void _update_avatar_cache (string persona_iid, File? avatar_file)
+ {
+ if (avatar_file == null)
+ {
+ this._avatars.unset (persona_iid);
+ }
+ else
+ {
+ this._avatars.set (persona_iid, (!) avatar_file);
+ }
+ }
+
+ internal File? _query_avatar_cache (string persona_iid)
+ {
+ return this._avatars.get (persona_iid);
+ }
+
private bool _add_persona (Persona p)
{
if (this._persona_set.add (p))
this._alias = alias;
this._is_favourite = is_favourite;
this.is_in_contact_list = is_in_contact_list;
- this._avatar = avatar;
this._birthday = birthday;
this._full_name = full_name;
+ // Avatars
+ this._avatar = avatar;
+ var avatar_file =
+ (avatar != null) ? ((FileIcon) avatar).get_file () : null;
+ ((Tpf.PersonaStore) store)._update_avatar_cache (iid, avatar_file);
+
// Make the persona appear offline
this.presence_type = PresenceType.OFFLINE;
this.presence_message = "";
private void _contact_notify_avatar ()
{
var file = this.contact.avatar_file;
+ var token = this.contact.avatar_token;
Icon? icon = null;
+ var from_cache = false;
+
+ /* Handle all the different cases of avatars. */
+ if (token == "")
+ {
+ /* Definitely know there's no avatar. */
+ file = null;
+ from_cache = false;
+ }
+ else if (token != null && file != null)
+ {
+ /* Definitely know there's some avatar, so leave the file alone. */
+ from_cache = false;
+ }
+ else
+ {
+ /* Not sure about the avatar; fall back to any cached avatar. */
+ file = ((Tpf.PersonaStore) this.store)._query_avatar_cache (this.iid);
+ from_cache = true;
+ }
if (file != null)
- icon = new FileIcon (file);
+ {
+ icon = new FileIcon (file);
+ }
- if (this._avatar == null || icon == null || !this._avatar.equal (icon))
+ if ((this._avatar == null) != (icon == null) || !this._avatar.equal (icon))
{
this._avatar = (LoadableIcon) icon;
this.notify_property ("avatar");
- /* Mark the persona cache as needing to be updated. */
- ((Tpf.PersonaStore) this.store)._set_cache_needs_update ();
+
+ if (from_cache == false)
+ {
+ /* Mark the persona cache as needing to be updated. */
+ ((Tpf.PersonaStore) this.store)._set_cache_needs_update ();
+
+ /* Update the avatar cache. */
+ ((Tpf.PersonaStore) this.store)._update_avatar_cache (this.iid,
+ file);
+ }
}
}