1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 15:33:05 +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)
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)

View File

@ -18,7 +18,7 @@ namespace osu.Game.Online.API.Requests
if (channels == null)
throw new ArgumentNullException(nameof(channels));
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;
}

View File

@ -20,6 +20,7 @@ namespace osu.Game.Online.Chat
/// Contains every joined user except the current logged in user.
/// </summary>
public readonly ObservableCollection<User> JoinedUsers = new ObservableCollection<User>();
public readonly SortedList<Message> Messages = new SortedList<Message>(Comparer<Message>.Default);
private readonly List<LocalEchoMessage> pendingMessages = new List<LocalEchoMessage>();
@ -28,7 +29,7 @@ namespace osu.Game.Online.Chat
public event Action<Message> MessageRemoved;
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 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)
{
pendingMessages.Add(message);
@ -113,7 +101,5 @@ namespace osu.Game.Online.Chat
if (messageCount > MaxHistory)
Messages.RemoveRange(0, messageCount - MaxHistory);
}
}
}

View File

@ -69,7 +69,7 @@ namespace osu.Game.Online.Chat
throw new ArgumentNullException(nameof(user));
CurrentChannel.Value = JoinedChannels.FirstOrDefault(c => c.Target == TargetType.User && c.Id == user.Id)
?? new Channel(user);
?? new PrivateChannel { User = user };
}
public ChannelManager()
@ -214,7 +214,7 @@ namespace osu.Game.Online.Chat
if (channel == null)
{
channel = new Channel(targetUser);
channel = new PrivateChannel { User = targetUser };
JoinedChannels.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.Success += user =>
{
var channel = new Channel(user);
var channel = new PrivateChannel { User = user };
channel.AddNewMessages(withoutReplyGroup.ToArray());
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;
}
}
}