1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 04:13:11 +08:00

Move private channel constructor to own class

This commit is contained in:
Dean Herbert 2018-07-23 20:46:44 +02:00
parent 2726d91594
commit 0aacde836a
5 changed files with 36 additions and 21 deletions

View File

@ -88,7 +88,7 @@ namespace osu.Game.Tests.Visual
if (users == null || users.Count == 0) if (users == null || users.Count == 0)
return; return;
chatTabControl.AddItem(new Channel(users[RNG.Next(0, users.Count - 1)])); chatTabControl.AddItem(new PrivateChannel { User = users[RNG.Next(0, users.Count - 1)] });
} }
private void addChannel(string name) private void addChannel(string name)

View File

@ -18,7 +18,7 @@ namespace osu.Game.Online.API.Requests
if (channels == null) if (channels == null)
throw new ArgumentNullException(nameof(channels)); throw new ArgumentNullException(nameof(channels));
if (channels.Any(c => c.Target != TargetType.Channel)) if (channels.Any(c => c.Target != TargetType.Channel))
throw new ArgumentException("All channels in the argument channels must have the targettype Channel"); throw new ArgumentException($"All channels in the argument channels must have the {nameof(Channel.Target)} Channel");
this.channels = channels; this.channels = channels;
} }

View File

@ -20,6 +20,7 @@ namespace osu.Game.Online.Chat
/// Contains every joined user except the current logged in user. /// Contains every joined user except the current logged in user.
/// </summary> /// </summary>
public readonly ObservableCollection<User> JoinedUsers = new ObservableCollection<User>(); public readonly ObservableCollection<User> JoinedUsers = new ObservableCollection<User>();
public readonly SortedList<Message> Messages = new SortedList<Message>(Comparer<Message>.Default); public readonly SortedList<Message> Messages = new SortedList<Message>(Comparer<Message>.Default);
private readonly List<LocalEchoMessage> pendingMessages = new List<LocalEchoMessage>(); private readonly List<LocalEchoMessage> pendingMessages = new List<LocalEchoMessage>();
@ -28,7 +29,7 @@ namespace osu.Game.Online.Chat
public event Action<Message> MessageRemoved; public event Action<Message> MessageRemoved;
public readonly Bindable<bool> Joined = new Bindable<bool>(); public readonly Bindable<bool> Joined = new Bindable<bool>();
public TargetType Target { get; } public TargetType Target { get; protected set; }
public bool ReadOnly => false; //todo not yet used. public bool ReadOnly => false; //todo not yet used.
public override string ToString() => Name; public override string ToString() => Name;
@ -49,19 +50,6 @@ namespace osu.Game.Online.Chat
{ {
} }
/// <summary>
/// Contructs a private channel
/// TODO this class needs to be serialized from something like channels/private, instead of creating from the contructor
/// </summary>
/// <param name="user">The user</param>
public Channel(User user)
{
Target = TargetType.User;
Name = user.Username;
Id = user.Id;
JoinedUsers.Add(user);
}
public void AddLocalEcho(LocalEchoMessage message) public void AddLocalEcho(LocalEchoMessage message)
{ {
pendingMessages.Add(message); pendingMessages.Add(message);
@ -113,7 +101,5 @@ namespace osu.Game.Online.Chat
if (messageCount > MaxHistory) if (messageCount > MaxHistory)
Messages.RemoveRange(0, messageCount - MaxHistory); Messages.RemoveRange(0, messageCount - MaxHistory);
} }
} }
} }

View File

@ -69,7 +69,7 @@ namespace osu.Game.Online.Chat
throw new ArgumentNullException(nameof(user)); throw new ArgumentNullException(nameof(user));
CurrentChannel.Value = JoinedChannels.FirstOrDefault(c => c.Target == TargetType.User && c.Id == user.Id) CurrentChannel.Value = JoinedChannels.FirstOrDefault(c => c.Target == TargetType.User && c.Id == user.Id)
?? new Channel(user); ?? new PrivateChannel { User = user };
} }
public ChannelManager() public ChannelManager()
@ -214,7 +214,7 @@ namespace osu.Game.Online.Chat
if (channel == null) if (channel == null)
{ {
channel = new Channel(targetUser); channel = new PrivateChannel { User = targetUser };
JoinedChannels.Add(channel); JoinedChannels.Add(channel);
joinedUserChannels.Add(channel); joinedUserChannels.Add(channel);
} }
@ -234,7 +234,7 @@ namespace osu.Game.Online.Chat
userReq.Failure += exception => Logger.Error(exception, "Failed to get user informations."); userReq.Failure += exception => Logger.Error(exception, "Failed to get user informations.");
userReq.Success += user => userReq.Success += user =>
{ {
var channel = new Channel(user); var channel = new PrivateChannel { User = user };
channel.AddNewMessages(withoutReplyGroup.ToArray()); channel.AddNewMessages(withoutReplyGroup.ToArray());
JoinedChannels.Add(channel); JoinedChannels.Add(channel);

View File

@ -0,0 +1,29 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Users;
namespace osu.Game.Online.Chat
{
public class PrivateChannel : Channel
{
public User User
{
set
{
Name = value.Username;
Id = value.Id;
JoinedUsers.Add(value);
}
}
/// <summary>
/// Contructs a private channel
/// </summary>
/// <param name="user">The user</param>
public PrivateChannel()
{
Target = TargetType.User;
}
}
}