1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-05 03:13:22 +08:00

Ensure events are unbound on disposal as a safety

This commit is contained in:
Dean Herbert 2024-11-27 15:46:55 +09:00
parent 17347563ee
commit 4fcc76270a
No known key found for this signature in database

View File

@ -171,10 +171,12 @@ namespace osu.Game.Overlays.Chat.ChannelList
public partial class ChannelGroup : FillFlowContainer
{
private readonly bool sortByRecent;
public readonly ChannelListItemFlow ItemFlow;
public ChannelGroup(LocalisableString label, bool sortByRecent)
{
this.sortByRecent = sortByRecent;
Direction = FillDirection.Vertical;
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
@ -217,21 +219,39 @@ namespace osu.Game.Overlays.Chat.ChannelList
{
ItemFlow.Add(item);
item.Channel.NewMessagesArrived += newMessagesArrived;
item.Channel.PendingMessageResolved += pendingMessageResolved;
if (sortByRecent)
{
item.Channel.NewMessagesArrived += newMessagesArrived;
item.Channel.PendingMessageResolved += pendingMessageResolved;
}
ItemFlow.Reflow();
}
public void RemoveChannel(ChannelListItem item)
{
item.Channel.NewMessagesArrived -= newMessagesArrived;
item.Channel.PendingMessageResolved -= pendingMessageResolved;
if (sortByRecent)
{
item.Channel.NewMessagesArrived -= newMessagesArrived;
item.Channel.PendingMessageResolved -= pendingMessageResolved;
}
ItemFlow.Remove(item, true);
}
private void pendingMessageResolved(LocalEchoMessage _, Message __) => ItemFlow.Reflow();
private void newMessagesArrived(IEnumerable<Message> _) => ItemFlow.Reflow();
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
foreach (var item in ItemFlow)
{
item.Channel.NewMessagesArrived -= newMessagesArrived;
item.Channel.PendingMessageResolved -= pendingMessageResolved;
}
}
}
private partial class ChannelSearchTextBox : BasicSearchTextBox