/// <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); })); }
/// <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 InitMessageLoader( IChatLoader chatLoader, IMessageLoader messageLoader, IMessageModelFactory messageModelFactory) { _chatLoader = chatLoader; _messageLoader = messageLoader; _messageModelFactory = messageModelFactory; }
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); } })); }
/// <summary> /// Load chats into observable cache /// </summary> private IDisposable LoadChats( IChatLoader chatLoader) { return(chatLoader.LoadChats() .Select(GetChatEntryModel) .Aggregate(new List <EntryModel>(), (list, model) => { model.Order = list.Count; list.Add(model); return list; }) .Synchronize(_chats) .Accept(entries => { _chats.EditDiff(entries, (m1, m2) => m1.Id == m2.Id); _chats.Refresh(); })); }
public static IDisposable BindPromoted( this HomeModel model, IChatLoader chatLoader, IMessageLoader messageLoader, IMessageModelFactory messageModelFactory) { model.PromotedMessages = new ObservableCollectionExtended <MessageModel>(); return(chatLoader.LoadPromo() .SelectSeq(chat => { return messageLoader.LoadNextMessages(chat, 0, 10); }) .Accept(message => { var messageModel = messageModelFactory.CreateMessage(message); model.PromotedMessages.Add(messageModel); })); }