diff --git a/osu.Game/Online/Rooms/Room.cs b/osu.Game/Online/Rooms/Room.cs
index cfb3b30ddb..ea3e8d73fe 100644
--- a/osu.Game/Online/Rooms/Room.cs
+++ b/osu.Game/Online/Rooms/Room.cs
@@ -194,6 +194,15 @@ namespace osu.Game.Online.Rooms
set => SetField(ref currentPlaylistItem, value);
}
+ ///
+ /// The chat channel id for the room. Will be 0 while the room has not yet been created.
+ ///
+ public int ChannelId
+ {
+ get => channelId;
+ private set => SetField(ref channelId, value);
+ }
+
///
/// The current room status.
///
@@ -266,6 +275,9 @@ namespace osu.Game.Online.Rooms
[JsonProperty("current_playlist_item")]
private PlaylistItem? currentPlaylistItem;
+ [JsonProperty("channel_id")]
+ private int channelId;
+
// Not serialised (see: GetRoomsRequest).
private RoomStatus status = new RoomStatusOpen();
@@ -276,10 +288,6 @@ namespace osu.Game.Online.Rooms
[JsonProperty("playlist")]
public readonly BindableList Playlist = new BindableList();
- [Cached]
- [JsonProperty("channel_id")]
- public readonly Bindable ChannelId = new Bindable();
-
[JsonProperty("playlist_item_stats")]
[Cached]
public readonly Bindable PlaylistItemStats = new Bindable();
@@ -313,7 +321,7 @@ namespace osu.Game.Online.Rooms
if (other.Host != null && Host?.Id != other.Host.Id)
Host = other.Host;
- ChannelId.Value = other.ChannelId.Value;
+ ChannelId = other.ChannelId;
Status = other.Status;
Availability = other.Availability;
HasPassword = other.HasPassword;
diff --git a/osu.Game/Screens/OnlinePlay/Match/Components/MatchChatDisplay.cs b/osu.Game/Screens/OnlinePlay/Match/Components/MatchChatDisplay.cs
index ed4f0ad6d8..a81425102d 100644
--- a/osu.Game/Screens/OnlinePlay/Match/Components/MatchChatDisplay.cs
+++ b/osu.Game/Screens/OnlinePlay/Match/Components/MatchChatDisplay.cs
@@ -1,8 +1,8 @@
// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
+using System.ComponentModel;
using osu.Framework.Allocation;
-using osu.Framework.Bindables;
using osu.Game.Online.Chat;
using osu.Game.Online.Rooms;
@@ -10,8 +10,6 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
{
public partial class MatchChatDisplay : StandAloneChatDisplay
{
- private readonly IBindable channelId = new Bindable();
-
[Resolved]
private ChannelManager? channelManager { get; set; }
@@ -29,23 +27,30 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
{
base.LoadComplete();
- // Required for the time being since this component is created prior to the room being joined.
- channelId.BindTo(room.ChannelId);
- channelId.BindValueChanged(_ => updateChannel(), true);
+ room.PropertyChanged += onRoomPropertyChanged;
+ updateChannel();
+ }
+
+ private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName == nameof(Room.ChannelId))
+ updateChannel();
}
private void updateChannel()
{
- if (room.RoomID == null || channelId.Value == 0)
+ if (room.RoomID == null || room.ChannelId == 0)
return;
- Channel.Value = channelManager?.JoinChannel(new Channel { Id = channelId.Value, Type = ChannelType.Multiplayer, Name = $"#lazermp_{room.RoomID.Value}" });
+ Channel.Value = channelManager?.JoinChannel(new Channel { Id = room.ChannelId, Type = ChannelType.Multiplayer, Name = $"#lazermp_{room.RoomID.Value}" });
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
+ room.PropertyChanged -= onRoomPropertyChanged;
+
if (leaveChannelOnDispose)
channelManager?.LeaveChannel(Channel.Value);
}