/// <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 CatalogProvider( IChatLoader chatLoader, IChatUpdater chatUpdater ) { _chatLoader = chatLoader; _chatUpdater = chatUpdater; _entryStore = new Dictionary <long, EntryModel>(); _chats = new SourceCache <EntryModel, long>(m => m.Id); }
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); }
/// <summary> /// Subscribe to updates for individual entries /// </summary> private IDisposable BindEntryUpdates( IChatLoader chatLoader, IChatUpdater chatUpdater) { return(chatUpdater.GetChatUpdates() .Buffer(TimeSpan.FromSeconds(1)) .SelectMany(chats => chats) .Select(chat => new { Chat = chat, Entry = GetChatEntryModel(chat) }) .Accept(item => { UpdateChatEntryModel((ChatEntryModel)item.Entry, item.Chat); })); }
/// <summary> /// Subscribe to updates that involve order change /// </summary> private IDisposable BindOrderUpdates( IChatLoader chatLoader, IChatUpdater chatUpdater) { return(chatUpdater.GetOrderUpdates() .Buffer(TimeSpan.FromSeconds(1)) .SubscribeOn(RxApp.TaskpoolScheduler) .ObserveOn(RxApp.MainThreadScheduler) .Accept(changes => { if (changes.Count > 0) { LoadChats(chatLoader) .DisposeWith(_serviceDisposable); } })); }