mirror of
https://github.com/osukey/osukey.git
synced 2025-05-25 23:47:30 +09: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;
|
public long? LastReadId;
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public Bindable<bool> Joined = new Bindable<bool>();
|
public Bindable<bool> Joined = new Bindable<bool>();
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ namespace osu.Game.Online.Chat
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
CurrentChannel.Value = JoinedChannels.FirstOrDefault(c => c.Type == ChannelType.PM && c.Users.Count == 1 && c.Users.Any(u => u.Id == user.Id))
|
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)
|
private void currentChannelChanged(ValueChangedEvent<Channel> e)
|
||||||
@ -140,7 +140,7 @@ namespace osu.Game.Online.Chat
|
|||||||
target.AddLocalEcho(message);
|
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 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);
|
var createNewPrivateMessageRequest = new CreateNewPrivateMessageRequest(target.Users.First(), message);
|
||||||
|
|
||||||
@ -356,26 +356,35 @@ namespace osu.Game.Online.Chat
|
|||||||
// ensure we are joined to the channel
|
// ensure we are joined to the channel
|
||||||
if (!channel.Joined.Value)
|
if (!channel.Joined.Value)
|
||||||
{
|
{
|
||||||
|
channel.Joined.Value = true;
|
||||||
|
|
||||||
switch (channel.Type)
|
switch (channel.Type)
|
||||||
{
|
{
|
||||||
case ChannelType.Multiplayer:
|
case ChannelType.Multiplayer:
|
||||||
// join is implicit. happens when you join a multiplayer game.
|
// join is implicit. happens when you join a multiplayer game.
|
||||||
// this will probably change in the future.
|
// this will probably change in the future.
|
||||||
channel.Joined.Value = true;
|
|
||||||
joinChannel(channel, fetchInitialMessages);
|
joinChannel(channel, fetchInitialMessages);
|
||||||
return channel;
|
return channel;
|
||||||
|
|
||||||
case ChannelType.Private:
|
case ChannelType.PM:
|
||||||
// can't do this yet.
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
var req = new JoinChannelRequest(channel, api.LocalUser.Value);
|
var req = new JoinChannelRequest(channel, api.LocalUser.Value);
|
||||||
req.Success += () =>
|
req.Success += () => joinChannel(channel, fetchInitialMessages);
|
||||||
{
|
|
||||||
channel.Joined.Value = true;
|
|
||||||
joinChannel(channel, fetchInitialMessages);
|
|
||||||
};
|
|
||||||
req.Failure += ex => LeaveChannel(channel);
|
req.Failure += ex => LeaveChannel(channel);
|
||||||
api.Queue(req);
|
api.Queue(req);
|
||||||
return channel;
|
return channel;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user