void UpdateViewWithMessage(YamsterMessage message) { bool shouldBeInView = false; if (CompiledFunc != null) { var executionContext = new YqlExecutionContext(this.appContext); executionContext.Message = message; shouldBeInView = CompiledFunc(executionContext); } ViewedMessage viewedMessage = null; bool isInView = viewedMessagesById.TryGetValue(message.MessageId, out viewedMessage); bool statisticsChanged = false; if (isInView) { if (!shouldBeInView) { this.RemoveViewedMessage(viewedMessage); NotifyViewChanged(YamsterViewChangeType.ModelLeaveView, message); // TotalItemCount changed statisticsChanged = true; } else { if (message.Read != viewedMessage.Read) { this.readMessageCount += message.Read ? +1 : -1; viewedMessage.Read = message.Read; statisticsChanged = true; } } } else { if (shouldBeInView) { AddViewedMessage(new ViewedMessage(message)); NotifyViewChanged(YamsterViewChangeType.ModelEnterView, message); // TotalItemCount changed statisticsChanged = true; } } if (statisticsChanged) { NotifyViewChanged(YamsterViewChangeType.StatisticsChanged, null); } }
void UpdateViewWithThread(YamsterThread thread) { bool shouldBeInView = false; if (CompiledFunc != null) { var executionContext = new YqlExecutionContext(this.appContext); executionContext.Thread = thread; shouldBeInView = CompiledFunc(executionContext); } ViewedThread viewedThread = null; bool isInView = viewedThreadsById.TryGetValue(thread.ThreadId, out viewedThread); bool statisticsChanged = false; if (isInView) { if (!shouldBeInView) { this.RemoveViewedThread(viewedThread); NotifyViewChanged(YamsterViewChangeType.ModelLeaveView, thread); // TotalItemCount changed statisticsChanged = true; } else { if (thread.Read != viewedThread.Read) { this.readThreadCount += thread.Read ? +1 : -1; viewedThread.Read = thread.Read; statisticsChanged = true; } } } else { if (shouldBeInView) { AddViewedThread(new ViewedThread(thread)); NotifyViewChanged(YamsterViewChangeType.ModelEnterView, thread); // TotalItemCount changed statisticsChanged = true; } } if (statisticsChanged) { NotifyViewChanged(YamsterViewChangeType.StatisticsChanged, null); } }
protected override void OnValidate() // abstract { var executionContext = new YqlExecutionContext(appContext); Debug.Assert(viewedMessagesById.Count == 0); foreach (var message in appContext.YamsterCache.GetAllMessages()) { executionContext.Message = message; if (CompiledFunc(executionContext)) { this.AddViewedMessage(new ViewedMessage(message)); } } }
protected override void OnValidate() // abstract { var executionContext = new YqlExecutionContext(appContext); Debug.Assert(viewedThreadsById.Count == 0); foreach (var thread in appContext.YamsterCache.GetAllThreads()) { executionContext.Thread = thread; if (CompiledFunc(executionContext)) { this.AddViewedThread(new ViewedThread(thread)); } } }