Пример #1
0
        private IDisposable BindInfo(
            Target target, IAvatarLoader avatarLoader)
        {
            switch (target)
            {
            case Chat chat:
                Model.IsVisible = true;
                Model.Title     = chat.ChatData.Title;
                Model.Label     = chat.ChatData.Title;
                return(avatarLoader.LoadAvatar(chat.ChatData)
                       .SubscribeOn(TaskPoolScheduler.Default)
                       .ObserveOn(RxApp.MainThreadScheduler)
                       .Subscribe(avatar =>
                {
                    Model.Avatar = avatar;
                }));

            case Aggregate aggregate:
                Model.Title = aggregate.Id.ToString();
                Model.Label = aggregate.Id.ToString();
                return(Disposable.Empty);
            }

            return(Disposable.Empty);
        }
Пример #2
0
 public NavigationModel(
     IAvatarLoader avatarLoader,
     IUserLoader userLoader)
 {
     LoadAvatar(userLoader, avatarLoader)
     .DisposeWith(_modelDisposable);
 }
Пример #3
0
 /// <summary>
 /// Subscribe to updates for individual entries
 /// </summary>
 private IDisposable BindEntryUpdates(
     IChatLoader chatLoader,
     IChatUpdater chatUpdater,
     IAvatarLoader avatarLoader
     )
 {
     return(chatUpdater.GetChatUpdates()
            .Buffer(TimeSpan.FromSeconds(1))
            .SelectMany(chats => chats)
            .Select(chat => new
     {
         Chat = chat,
         Entry = GetChatEntryModel(chat)
     })
            .SelectMany(item => LoadAvatar(avatarLoader, item.Entry)
                        .Select(avatar => new
     {
         Chat = item.Chat,
         Entry = item.Entry,
         Avatar = avatar
     }))
            .SubscribeOn(TaskPoolScheduler.Default)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(item =>
     {
         UpdateChatEntryModel(item.Entry, item.Chat, item.Avatar);
     }));
 }
Пример #4
0
 public NavigationController(
     IAvatarLoader avatarLoader,
     IUserLoader userLoader)
 {
     BindAvatar(userLoader, avatarLoader)
     .DisposeWith(this);
 }
Пример #5
0
 /// <summary>
 /// Load chats into observable cache
 /// </summary>
 private IDisposable LoadChats(IChatLoader chatLoader, IAvatarLoader avatarLoader)
 {
     return(chatLoader.LoadChats()
            .Select(GetChatEntryModel)
            .Aggregate(new List <EntryModel>(), (list, model) =>
     {
         model.Order = list.Count;
         list.Add(model);
         return list;
     })
            .Synchronize(_chats)
            .Do(entries =>
     {
         _chats.EditDiff(entries, (m1, m2) => m1.Id == m2.Id);
         _chats.Refresh();
     })
            .SelectMany(entries => entries)
            .SelectMany(entry => LoadAvatar(avatarLoader, entry)
                        .Select(avatar => new
     {
         Entry = entry,
         Avatar = avatar
     }))
            .SubscribeOn(TaskPoolScheduler.Default)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(item =>
     {
         var entry = item.Entry;
         var avatar = item.Avatar;
         entry.Avatar = avatar;
     }));
 }
Пример #6
0
 public InformerController(
     Target target,
     IAvatarLoader avatarLoader)
 {
     BindInfo(target, avatarLoader)
     .DisposeWith(this);
 }
Пример #7
0
 public InformerModel(
     IAvatarLoader avatarLoader,
     Target target
     )
 {
     BindInfo(avatarLoader, target)
     .DisposeWith(_modelDisposable);
 }
Пример #8
0
        public static IDisposable BindInformer(
            this InformerModel model,
            Aggregate aggregate,
            IAvatarLoader avatarLoader)
        {
            model.Title = aggregate.Id.ToString();
            model.Label = aggregate.Id.ToString();

            return(Disposable.Empty);
        }
Пример #9
0
 private IDisposable LoadAvatar(IUserLoader userLoader, IAvatarLoader avatarLoader)
 {
     return(userLoader
            .GetMe()
            .SelectMany(user => avatarLoader.LoadAvatar(user.UserData, AvatarSize.Big))
            .SubscribeOn(TaskPoolScheduler.Default)
            .ObserveOn(AvaloniaScheduler.Instance)
            .Subscribe(avatar =>
     {
         Avatar = avatar;
     }));
 }
Пример #10
0
        private static IObservable <Avatar> LoadAvatar(IAvatarLoader avatarLoader, MessageModel entry)
        {
            if (entry.Message?.UserData != null)
            {
                return(avatarLoader.LoadAvatar(entry.Message.UserData, AvatarSize.Regular));
            }

            if (entry.Message?.ChatData != null)
            {
                return(avatarLoader.LoadAvatar(entry.Message.ChatData, AvatarSize.Regular));
            }

            return(Observable.Empty <Avatar>());
        }
Пример #11
0
 private IDisposable BindAvatar(
     IUserLoader userLoader,
     IAvatarLoader avatarLoader)
 {
     return(userLoader
            .GetMe()
            .SelectMany(user => avatarLoader.LoadAvatar(user.UserData))
            .SubscribeOn(TaskPoolScheduler.Default)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(avatar =>
     {
         Model.Avatar = avatar;
     }));
 }
Пример #12
0
        private static Avatar GetAvatar(IAvatarLoader avatarLoader, MessageModel entry)
        {
            if (entry.Message?.UserData != null)
            {
                return(avatarLoader.GetAvatar(entry.Message.UserData, AvatarSize.Regular));
            }

            if (entry.Message?.ChatData != null)
            {
                return(avatarLoader.GetAvatar(entry.Message.ChatData, AvatarSize.Regular));
            }

            return(null);
        }
Пример #13
0
 public static IDisposable BindUserAvatar(
     this NavigationModel model,
     IAvatarLoader avatarLoader,
     IUserLoader userLoader)
 {
     return(userLoader
            .GetMe()
            .SelectMany(user => avatarLoader.LoadAvatar(user.UserData, AvatarSize.Regular))
            .SubscribeOn(RxApp.TaskpoolScheduler)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Accept(avatar =>
     {
         model.Avatar = avatar;
     }));
 }
Пример #14
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>());
        }
Пример #15
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);
        }
Пример #16
0
        public CatalogProvider(
            IChatLoader chatLoader,
            IChatUpdater chatUpdater,
            IAvatarLoader avatarLoader
            )
        {
            _entryStore = new Dictionary <long, EntryModel>();
            _chats      = new SourceCache <EntryModel, long>(m => m.Id);

            LoadChats(chatLoader, avatarLoader)
            .DisposeWith(_serviceDisposable);
            BindOrderUpdates(chatLoader, chatUpdater, avatarLoader)
            .DisposeWith(_serviceDisposable);
            BindEntryUpdates(chatLoader, chatUpdater, avatarLoader)
            .DisposeWith(_serviceDisposable);
        }
Пример #17
0
        public static IDisposable BindInformer(
            this InformerModel model,
            Chat chat,
            IAvatarLoader avatarLoader)
        {
            model.Title = chat.ChatData.Title;
            model.Label = chat.ChatData.Title;

            return(avatarLoader.LoadAvatar(chat.ChatData, AvatarSize.Regular)
                   .SubscribeOn(RxApp.TaskpoolScheduler)
                   .ObserveOn(RxApp.MainThreadScheduler)
                   .Accept(avatar =>
            {
                model.Avatar = avatar;
            }));
        }
Пример #18
0
 /// <summary>
 /// Subscribe to updates that involve order change
 /// </summary>
 private IDisposable BindOrderUpdates(
     IChatLoader chatLoader,
     IChatUpdater chatUpdater,
     IAvatarLoader avatarLoader
     )
 {
     return(chatUpdater.GetOrderUpdates()
            .Buffer(TimeSpan.FromSeconds(1))
            .SubscribeOn(TaskPoolScheduler.Default)
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(changes =>
     {
         if (changes.Count > 0)
         {
             LoadChats(chatLoader, avatarLoader).DisposeWith(_serviceDisposable);
         }
     }));
 }
        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);
        }
Пример #20
0
        private IObservable <Avatar> LoadAvatar(IAvatarLoader avatarLoader, EntryModel entry)
        {
            if (entry.Avatar != null)
            {
                return(Observable.Return(entry.Avatar));
            }

            switch (entry.Target)
            {
            case Chat chat:
                return(avatarLoader.LoadAvatar(chat.ChatData));

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

            return(Observable.Return <Avatar>(null));
        }
Пример #21
0
        private IObservable <Avatar> LoadAvatar(IAvatarLoader avatarLoader, EntryModel entry)
        {
            if (entry.Avatar != null)
            {
                return(Observable.Return(entry.Avatar));
            }

            switch (entry)
            {
            case ChatEntryModel chatEntry:
                return(avatarLoader.LoadAvatar(chatEntry.Chat.ChatData, AvatarSize.Small));

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

            return(Observable.Return <Avatar>(null));
        }
        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);
        }
Пример #23
0
        public static IDisposable BindAvatarLoading(
            this MessageModel model,
            IAvatarLoader avatarLoader)
        {
            if (model.Avatar == null)
            {
                model.Avatar = GetAvatar(avatarLoader, model);

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

            return(Disposable.Empty);
        }
Пример #24
0
        private IDisposable BindInfo(IAvatarLoader avatarLoader, Target target)
        {
            switch (target)
            {
            case Chat chat:
                Title = chat.ChatData.Title;
                Label = chat.ChatData.Title;
                return(avatarLoader.LoadAvatar(chat.ChatData, AvatarSize.Big)
                       .SubscribeOn(TaskPoolScheduler.Default)
                       .ObserveOn(RxApp.MainThreadScheduler)
                       .Subscribe(avatar =>
                {
                    Avatar = avatar;
                }));

            case Aggregate aggregate:
                Title = aggregate.Id.ToString();
                Label = aggregate.Id.ToString();
                return(Disposable.Empty);
            }

            return(Disposable.Empty);
        }
 public AvatarViewComponent(IAvatarLoader avatarProvider)
 => this.avatarProvider = avatarProvider;
Пример #26
0
 public AvatarManager(
     IAvatarLoader avatarLoader)
 {
     _avatarLoader = avatarLoader;
 }