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); }
public NavigationModel( IAvatarLoader avatarLoader, IUserLoader userLoader) { LoadAvatar(userLoader, avatarLoader) .DisposeWith(_modelDisposable); }
/// <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); })); }
public NavigationController( IAvatarLoader avatarLoader, IUserLoader userLoader) { BindAvatar(userLoader, avatarLoader) .DisposeWith(this); }
/// <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; })); }
public InformerController( Target target, IAvatarLoader avatarLoader) { BindInfo(target, avatarLoader) .DisposeWith(this); }
public InformerModel( IAvatarLoader avatarLoader, Target target ) { BindInfo(avatarLoader, target) .DisposeWith(_modelDisposable); }
public static IDisposable BindInformer( this InformerModel model, Aggregate aggregate, IAvatarLoader avatarLoader) { model.Title = aggregate.Id.ToString(); model.Label = aggregate.Id.ToString(); return(Disposable.Empty); }
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; })); }
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>()); }
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; })); }
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); }
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; })); }
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>()); }
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 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); }
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; })); }
/// <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); }
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)); }
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); }
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); }
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;
public AvatarManager( IAvatarLoader avatarLoader) { _avatarLoader = avatarLoader; }