Fix potential crash when highlighting chat messages

Test failed locally in `TestPublicChannelMention`. This test seems to
specify that the same message may arrive twice with the same ID, so
rather than overthinking this one I propose we just use `FirstOrDefault`.

```csharp
TearDown : System.AggregateException : One or more errors occurred.
(Sequence contains more than one matching element)
  ----> System.InvalidOperationException : Sequence contains more than
one matching element
--TearDown
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean
includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout,
CancellationToken cancellationToken)
   at osu.Framework.Extensions.TaskExtensions.WaitSafely(Task task)
   at osu.Framework.Testing.TestScene.checkForErrors()
--InvalidOperationException
   at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
   at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source,
Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1
source, Func`2 predicate)
   at
osu.Game.Overlays.Chat.DrawableChannel.<processMessageHighlighting>b__14_0()
in
/Users/dean/Projects/osu/osu.Game/Overlays/Chat/DrawableChannel.cs:line
102
   at osu.Framework.Threading.ScheduledDelegate.RunTaskInternal()
```
This commit is contained in:
Dean Herbert 2022-03-16 18:38:01 +09:00
parent 7e8aa77b2b
commit 603527d72d
1 changed files with 1 additions and 1 deletions

View File

@ -99,7 +99,7 @@ private void processMessageHighlighting() => SchedulerAfterChildren.AddOnce(() =
if (highlightedMessage.Value == null)
return;
var chatLine = chatLines.SingleOrDefault(c => c.Message.Equals(highlightedMessage.Value));
var chatLine = chatLines.FirstOrDefault(c => c.Message.Equals(highlightedMessage.Value));
if (chatLine == null)
return;