Пример #1
0
        private static IObservable <Avatar> LoadAvatar(IAvatarLoader avatarLoader, EntryModel entry)
        {
            switch (entry)
            {
            case ChatEntryModel chatEntryModel:
                return(avatarLoader.LoadAvatar(chatEntryModel.Chat.ChatData));

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

            return(Observable.Empty <Avatar>());
        }
Пример #2
0
        private static Avatar GetAvatar(IAvatarLoader avatarLoader, EntryModel entry)
        {
            switch (entry)
            {
            case ChatEntryModel chatEntryModel:
                return(avatarLoader.GetAvatar(chatEntryModel.Chat.ChatData));

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

            return(null);
        }
        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);
        }
        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);
        }