Beispiel #1
0
        public static IDisposable BindAvatarLoading(
            this EntryModel model,
            IAvatarLoader avatarLoader)
        {
            if (model.Avatar == null)
            {
                model.Avatar = GetAvatar(avatarLoader, model);

                if (model.Avatar == null || model.Avatar.IsFallback)
                {
                    return(LoadAvatar(avatarLoader, model)
                           .Accept(avatar =>
                    {
                        model.Avatar = avatar;
                    }));
                }
            }

            return(Disposable.Empty);
        }
Beispiel #2
0
        private static IObservable <Avatar> LoadAvatar(IAvatarLoader avatarLoader, EntryModel entry)
        {
            switch (entry)
            {
            case HomeEntryModel _:
                return(avatarLoader.LoadAvatar(
                           AvatarKind.Home,
                           AvatarSize.Small));

            case ChatEntryModel chatEntryModel:
                return(avatarLoader.LoadAvatar(chatEntryModel.Chat.ChatData, AvatarSize.Small));

            case AggregateEntryModel aggregateEntryModel:
                return(avatarLoader.LoadAvatar(new TdApi.Chat
                {
                    Id = aggregateEntryModel.Aggregate.Id
                },
                                               AvatarSize.Small));
            }

            return(Observable.Empty <Avatar>());
        }
Beispiel #3
0
        private static Avatar GetAvatar(IAvatarLoader avatarLoader, EntryModel entry)
        {
            switch (entry)
            {
            case HomeEntryModel _:
                return(avatarLoader.GetAvatar(
                           AvatarKind.Home,
                           AvatarSize.Small));

            case ChatEntryModel chatEntryModel:
                return(avatarLoader.GetAvatar(chatEntryModel.Chat.ChatData, AvatarSize.Small));

            case AggregateEntryModel aggregateEntryModel:
                return(avatarLoader.GetAvatar(new TdApi.Chat
                {
                    Id = aggregateEntryModel.Aggregate.Id
                },
                                              AvatarSize.Small));
            }

            return(null);
        }