mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:12:54 +08:00
Merge pull request #9231 from peppy/fetch-private-chat-history
Fetch existing private message channels on re-joining
This commit is contained in:
commit
e837528ddf
34
osu.Game/Online/API/Requests/CreateChannelRequest.cs
Normal file
34
osu.Game/Online/API/Requests/CreateChannelRequest.cs
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using osu.Framework.IO.Network;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Chat;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class CreateChannelRequest : APIRequest<APIChatChannel>
|
||||
{
|
||||
private readonly Channel channel;
|
||||
|
||||
public CreateChannelRequest(Channel channel)
|
||||
{
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
protected override WebRequest CreateWebRequest()
|
||||
{
|
||||
var req = base.CreateWebRequest();
|
||||
req.Method = HttpMethod.Post;
|
||||
|
||||
req.AddParameter("type", $"{ChannelType.PM}");
|
||||
req.AddParameter("target_id", $"{channel.Users.First().Id}");
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
protected override string Target => @"chat/channels";
|
||||
}
|
||||
}
|
18
osu.Game/Online/API/Requests/Responses/APIChatChannel.cs
Normal file
18
osu.Game/Online/API/Requests/Responses/APIChatChannel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Online.Chat;
|
||||
|
||||
namespace osu.Game.Online.API.Requests.Responses
|
||||
{
|
||||
public class APIChatChannel
|
||||
{
|
||||
[JsonProperty(@"channel_id")]
|
||||
public int? ChannelID { get; set; }
|
||||
|
||||
[JsonProperty(@"recent_messages")]
|
||||
public List<Message> RecentMessages { get; set; }
|
||||
}
|
||||
}
|
@ -84,7 +84,8 @@ namespace osu.Game.Online.Chat
|
||||
public long? LastReadId;
|
||||
|
||||
/// <summary>
|
||||
/// Signalles if the current user joined this channel or not. Defaults to false.
|
||||
/// Signals if the current user joined this channel or not. Defaults to false.
|
||||
/// Note that this does not guarantee a join has completed. Check Id > 0 for confirmation.
|
||||
/// </summary>
|
||||
public Bindable<bool> Joined = new Bindable<bool>();
|
||||
|
||||
|
@ -86,7 +86,7 @@ namespace osu.Game.Online.Chat
|
||||
return;
|
||||
|
||||
CurrentChannel.Value = JoinedChannels.FirstOrDefault(c => c.Type == ChannelType.PM && c.Users.Count == 1 && c.Users.Any(u => u.Id == user.Id))
|
||||
?? new Channel(user);
|
||||
?? JoinChannel(new Channel(user));
|
||||
}
|
||||
|
||||
private void currentChannelChanged(ValueChangedEvent<Channel> e)
|
||||
@ -140,7 +140,7 @@ namespace osu.Game.Online.Chat
|
||||
target.AddLocalEcho(message);
|
||||
|
||||
// if this is a PM and the first message, we need to do a special request to create the PM channel
|
||||
if (target.Type == ChannelType.PM && !target.Joined.Value)
|
||||
if (target.Type == ChannelType.PM && target.Id == 0)
|
||||
{
|
||||
var createNewPrivateMessageRequest = new CreateNewPrivateMessageRequest(target.Users.First(), message);
|
||||
|
||||
@ -356,26 +356,35 @@ namespace osu.Game.Online.Chat
|
||||
// ensure we are joined to the channel
|
||||
if (!channel.Joined.Value)
|
||||
{
|
||||
channel.Joined.Value = true;
|
||||
|
||||
switch (channel.Type)
|
||||
{
|
||||
case ChannelType.Multiplayer:
|
||||
// join is implicit. happens when you join a multiplayer game.
|
||||
// this will probably change in the future.
|
||||
channel.Joined.Value = true;
|
||||
joinChannel(channel, fetchInitialMessages);
|
||||
return channel;
|
||||
|
||||
case ChannelType.Private:
|
||||
// can't do this yet.
|
||||
case ChannelType.PM:
|
||||
var createRequest = new CreateChannelRequest(channel);
|
||||
createRequest.Success += resChannel =>
|
||||
{
|
||||
if (resChannel.ChannelID.HasValue)
|
||||
{
|
||||
channel.Id = resChannel.ChannelID.Value;
|
||||
|
||||
handleChannelMessages(resChannel.RecentMessages);
|
||||
channel.MessagesLoaded = true; // this will mark the channel as having received messages even if there were none.
|
||||
}
|
||||
};
|
||||
|
||||
api.Queue(createRequest);
|
||||
break;
|
||||
|
||||
default:
|
||||
var req = new JoinChannelRequest(channel, api.LocalUser.Value);
|
||||
req.Success += () =>
|
||||
{
|
||||
channel.Joined.Value = true;
|
||||
joinChannel(channel, fetchInitialMessages);
|
||||
};
|
||||
req.Success += () => joinChannel(channel, fetchInitialMessages);
|
||||
req.Failure += ex => LeaveChannel(channel);
|
||||
api.Queue(req);
|
||||
return channel;
|
||||
|
Loading…
Reference in New Issue
Block a user