Ejemplo n.º 1
0
        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;
                    }
                }
            });
        }
Ejemplo n.º 2
0
        public PresenceCollectionHandler(ViewModel.Account account, IMapper mapper)
        {
            // handle self presence
            Handle(
                el =>
                el.OfType <Presence>() &&
                el.Cast <Presence>().Type == PresenceType.Available &&
                el.Cast <Presence>().From.Equals(account.XmppId, new BareJidComparer()),

                async(context, xmppXElement) =>
            {
                var pres = xmppXElement.Cast <Presence>();
                if (pres.From.Resource == account.Resource)
                {
                    // this is our client
                    await Observable.Start(() =>
                                           account.Presence = mapper.Map <ViewModel.Presence>(pres),
                                           RxApp.MainThreadScheduler);
                }
            });
        }