internal void AddPreviousMessages(IEnumerable <ChatMessageViewModel> messages) { bool hasUpdates = false; _messages.IsNotifying = false; foreach (var chatMessage in messages.Reverse()) { chatMessage.HasBeenSeen = true; var firstMessageGroup = _messages.FirstOrDefault() as ChatMessageGroupViewModel; if (firstMessageGroup == null || !firstMessageGroup.TryAddPreviousMessage(chatMessage)) { var groupMessage = new ChatMessageGroupViewModel(chatMessage); _messages.Insert(0, groupMessage); hasUpdates = true; } } _messages.IsNotifying = true; if (hasUpdates) { _messages.Refresh(); } IsRequestingPreviousMessages = false; }
public static void Replace <T>(this IObservableCollection <T> collection, IEnumerable <T> items) { collection.IsNotifying = false; collection.Clear(); collection.AddRange(items); collection.IsNotifying = true; collection.Refresh(); }