protected internal void OnBubbleUpdated(VisualBubble bubble, BubbleGroup group) { if (Bubbles.Count >= BubblesCapSize) { Bubbles.RemoveAt(0); } var addedToEnd = false; var unreadIndicatorGuid = BubbleGroupSettingsManager.GetUnreadIndicatorGuid(this); for (int i = Bubbles.Count - 1; i >= 0; i--) { var nBubble = Bubbles[i]; var unreadIndicatorIndex = -1; if (unreadIndicatorGuid != null && unreadIndicatorGuid == nBubble.ID) { unreadIndicatorIndex = i; } if (nBubble.Time <= bubble.Time) { // adding it to the end, we can do a simple contract if (i == Bubbles.Count - 1) { addedToEnd = true; Bubbles.Add(bubble); if (bubble.Direction == Bubble.BubbleDirection.Incoming) { BubbleGroupSettingsManager.SetUnread(this, true); } } // inserting, do a full contract else { Bubbles.Insert(i + 1, bubble); } if (i >= unreadIndicatorIndex && bubble.Direction == Bubble.BubbleDirection.Outgoing) { BubbleGroupSettingsManager.SetUnreadIndicatorGuid(this, bubble.ID, false); } break; } // could not find a valid place to insert, then skip insertion. if (i == 0) { return; } } if (SendingGroup != group && addedToEnd) { SendingGroup = group; BubbleGroupEvents.RaiseSendingServiceChange(this); } RaiseBubbleInserted(bubble); }