public async Task RequestRosterAsync() { var rosterIq = await xmppClient.RequestRosterAsync(); var rosterItems = rosterIq .Query .Cast <Roster>() .GetRoster(); await Observable.Start(() => { foreach (var ri in rosterItems) { var contact = mapper.Map <Contact>(ri); if (userAvatarStorage.HasUserAvatar(contact.Jid)) { var hash = userAvatarStorage.GetUserAvatar(contact.Jid).Hash; contact.AvatarBytes = avatarStorage.GetAvatar(hash)?.ImageBytes; } contacts.AddOrReplace(contact, c => c.Jid == contact.Jid); } }, RxApp.MainThreadScheduler); }
public AvatarCollectionHandler( IAvatarStorage avatarStorage, IUserAvatarStorage userAvatarStorage, ViewModel.Account account, ViewModel.Contacts contacts) { this.avatarStorage = avatarStorage; this.userAvatarStorage = userAvatarStorage; this.contacts = contacts; Handle( el => el.OfType <Message>() && el.HasDescendants <Event>() && el.HasDescendants <Metadata>(), async(context, el) => { var msg = el.Cast <Message>(); var metaData = el.Descendants <Metadata>().First(); if (metaData.Info != null) { var id = metaData.Info.Id; var from = msg.From.Bare; if (!avatarStorage.HasAvatar(id)) { await RequestAvatar(from, id); } if (contacts.Contains(from)) { // avatar of a contact contacts[from].AvatarBytes = avatarStorage.GetAvatar(id)?.ImageBytes; } else if (account.XmppId == from) { //our own avatar account.AvatarBytes = avatarStorage.GetAvatar(id)?.ImageBytes; } } }); }