mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 06:23:20 +08:00
Merge branch 'master' into logo-shockwave
This commit is contained in:
commit
83a8a27161
@ -38,9 +38,9 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
public event Action<IEnumerable<Message>> NewMessagesArrived;
|
||||
|
||||
public void AddNewMessages(IEnumerable<Message> messages)
|
||||
public void AddNewMessages(params Message[] messages)
|
||||
{
|
||||
messages = messages.Except(Messages).ToList();
|
||||
messages = messages.Except(Messages).ToArray();
|
||||
|
||||
Messages.AddRange(messages);
|
||||
|
||||
|
25
osu.Game/Online/Chat/ErrorMessage.cs
Normal file
25
osu.Game/Online/Chat/ErrorMessage.cs
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Online.Chat
|
||||
{
|
||||
public class ErrorMessage : Message
|
||||
{
|
||||
private static int errorId = -1;
|
||||
|
||||
public ErrorMessage(string message) : base(errorId--)
|
||||
{
|
||||
Timestamp = DateTime.Now;
|
||||
Content = message;
|
||||
|
||||
Sender = new User
|
||||
{
|
||||
Username = @"system",
|
||||
Colour = @"ff0000",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -37,6 +37,11 @@ namespace osu.Game.Online.Chat
|
||||
{
|
||||
}
|
||||
|
||||
public Message(long id)
|
||||
{
|
||||
Id = id;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var objMessage = obj as Message;
|
||||
|
@ -245,7 +245,7 @@ namespace osu.Game.Overlays
|
||||
addChannel(channels.Find(c => c.Name == @"#lobby"));
|
||||
});
|
||||
|
||||
messageRequest = Scheduler.AddDelayed(() => fetchNewMessages(), 1000, true);
|
||||
messageRequest = Scheduler.AddDelayed(fetchNewMessages, 1000, true);
|
||||
};
|
||||
|
||||
api.Queue(req);
|
||||
@ -289,24 +289,41 @@ namespace osu.Game.Overlays
|
||||
channelTabs.AddItem(channel);
|
||||
|
||||
// we need to get a good number of messages initially for each channel we care about.
|
||||
fetchNewMessages(channel);
|
||||
fetchInitialMessages(channel);
|
||||
|
||||
if (CurrentChannel == null)
|
||||
CurrentChannel = channel;
|
||||
}
|
||||
|
||||
private void fetchNewMessages(Channel specificChannel = null)
|
||||
private void fetchInitialMessages(Channel channel)
|
||||
{
|
||||
var req = new GetMessagesRequest(new List<Channel> { channel }, null);
|
||||
|
||||
req.Success += delegate (List<Message> messages)
|
||||
{
|
||||
channel.AddNewMessages(messages.ToArray());
|
||||
Debug.Write("success!");
|
||||
};
|
||||
req.Failure += delegate
|
||||
{
|
||||
Debug.Write("failure!");
|
||||
};
|
||||
|
||||
api.Queue(req);
|
||||
}
|
||||
|
||||
private void fetchNewMessages()
|
||||
{
|
||||
if (fetchReq != null) return;
|
||||
|
||||
fetchReq = new GetMessagesRequest(specificChannel != null ? new List<Channel> { specificChannel } : careChannels, lastMessageId);
|
||||
fetchReq = new GetMessagesRequest(careChannels, lastMessageId);
|
||||
fetchReq.Success += delegate (List<Message> messages)
|
||||
{
|
||||
var ids = messages.Where(m => m.TargetType == TargetType.Channel).Select(m => m.TargetId).Distinct();
|
||||
|
||||
//batch messages per channel.
|
||||
foreach (var id in ids)
|
||||
careChannels.Find(c => c.Id == id)?.AddNewMessages(messages.Where(m => m.TargetId == id));
|
||||
careChannels.Find(c => c.Id == id)?.AddNewMessages(messages.Where(m => m.TargetId == id).ToArray());
|
||||
|
||||
lastMessageId = messages.LastOrDefault()?.Id ?? lastMessageId;
|
||||
|
||||
@ -326,10 +343,18 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
var postText = textbox.Text;
|
||||
|
||||
if (!string.IsNullOrEmpty(postText) && api.LocalUser.Value != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(postText) || api.LocalUser.Value == null) return;
|
||||
|
||||
if (currentChannel == null) return;
|
||||
|
||||
if (postText[0] == '/')
|
||||
{
|
||||
// TODO: handle commands
|
||||
currentChannel.AddNewMessages(new ErrorMessage("Chat commands are not supported yet!"));
|
||||
textbox.Text = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
var message = new Message
|
||||
{
|
||||
Sender = api.LocalUser.Value,
|
||||
@ -350,7 +375,7 @@ namespace osu.Game.Overlays
|
||||
|
||||
req.Success += m =>
|
||||
{
|
||||
currentChannel.AddNewMessages(new[] { m });
|
||||
currentChannel.AddNewMessages(m);
|
||||
|
||||
textbox.ReadOnly = false;
|
||||
textbox.Text = string.Empty;
|
||||
@ -360,4 +385,3 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,6 +75,7 @@
|
||||
<Compile Include="Beatmaps\Drawables\BeatmapBackgroundSprite.cs" />
|
||||
<Compile Include="Beatmaps\DifficultyCalculator.cs" />
|
||||
<Compile Include="Online\API\Requests\PostMessageRequest.cs" />
|
||||
<Compile Include="Online\Chat\ErrorMessage.cs" />
|
||||
<Compile Include="Overlays\Chat\ChatTabControl.cs" />
|
||||
<Compile Include="Overlays\Music\FilterControl.cs" />
|
||||
<Compile Include="Overlays\Music\PlaylistItem.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user