mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 14:46:38 +09:00
Update chat to work with new API version
This commit is contained in:
@ -2,34 +2,19 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.IO.Network;
|
||||
using osu.Game.Online.Chat;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetMessagesRequest : APIRequest<List<Message>>
|
||||
{
|
||||
private readonly List<Channel> channels;
|
||||
private readonly long? since;
|
||||
private readonly Channel channel;
|
||||
|
||||
public GetMessagesRequest(List<Channel> channels, long? sinceId)
|
||||
public GetMessagesRequest(Channel channel)
|
||||
{
|
||||
this.channels = channels;
|
||||
since = sinceId;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
protected override WebRequest CreateWebRequest()
|
||||
{
|
||||
string channelString = string.Join(",", channels.Select(x => x.Id));
|
||||
|
||||
var req = base.CreateWebRequest();
|
||||
req.AddParameter(@"channels", channelString);
|
||||
if (since.HasValue) req.AddParameter(@"since", since.Value.ToString());
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
protected override string Target => @"chat/messages";
|
||||
protected override string Target => $@"chat/channels/{channel.Id}/messages";
|
||||
}
|
||||
}
|
||||
|
32
osu.Game/Online/API/Requests/GetUpdatesRequest.cs
Normal file
32
osu.Game/Online/API/Requests/GetUpdatesRequest.cs
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.IO.Network;
|
||||
using osu.Game.Online.Chat;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetUpdatesRequest : APIRequest<GetUpdatesResponse>
|
||||
{
|
||||
private readonly long since;
|
||||
private readonly Channel channel;
|
||||
|
||||
public GetUpdatesRequest(long sinceId, [CanBeNull] Channel channel = null)
|
||||
{
|
||||
this.channel = channel;
|
||||
since = sinceId;
|
||||
}
|
||||
|
||||
protected override WebRequest CreateWebRequest()
|
||||
{
|
||||
var req = base.CreateWebRequest();
|
||||
if (channel != null) req.AddParameter(@"channel", channel.Id.ToString());
|
||||
req.AddParameter(@"since", since.ToString());
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
protected override string Target => @"chat/updates";
|
||||
}
|
||||
}
|
14
osu.Game/Online/API/Requests/GetUpdatesResponse.cs
Normal file
14
osu.Game/Online/API/Requests/GetUpdatesResponse.cs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Online.Chat;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetUpdatesResponse
|
||||
{
|
||||
public List<Channel> Presence;
|
||||
public List<Message> Messages;
|
||||
}
|
||||
}
|
31
osu.Game/Online/API/Requests/JoinChannelRequest.cs
Normal file
31
osu.Game/Online/API/Requests/JoinChannelRequest.cs
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Net.Http;
|
||||
using osu.Framework.IO.Network;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class JoinChannelRequest : APIRequest<Channel>
|
||||
{
|
||||
private readonly Channel channel;
|
||||
private readonly User user;
|
||||
|
||||
public JoinChannelRequest(Channel channel, User user)
|
||||
{
|
||||
this.channel = channel;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
protected override WebRequest CreateWebRequest()
|
||||
{
|
||||
var req = base.CreateWebRequest();
|
||||
req.Method = HttpMethod.Put;
|
||||
return req;
|
||||
}
|
||||
|
||||
protected override string Target => $@"chat/channels/{channel.Id}/users/{user.Id}";
|
||||
}
|
||||
}
|
31
osu.Game/Online/API/Requests/LeaveChannelRequest.cs
Normal file
31
osu.Game/Online/API/Requests/LeaveChannelRequest.cs
Normal file
@ -0,0 +1,31 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Net.Http;
|
||||
using osu.Framework.IO.Network;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class LeaveChannelRequest : APIRequest
|
||||
{
|
||||
private readonly Channel channel;
|
||||
private readonly User user;
|
||||
|
||||
public LeaveChannelRequest(Channel channel, User user)
|
||||
{
|
||||
this.channel = channel;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
protected override WebRequest CreateWebRequest()
|
||||
{
|
||||
var req = base.CreateWebRequest();
|
||||
req.Method = HttpMethod.Delete;
|
||||
return req;
|
||||
}
|
||||
|
||||
protected override string Target => $@"chat/channels/{channel.Id}/users/{user.Id}";
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
// 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.Framework.Extensions;
|
||||
using System.Net.Http;
|
||||
using osu.Framework.IO.Network;
|
||||
using osu.Game.Online.Chat;
|
||||
|
||||
@ -20,15 +20,13 @@ namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
var req = base.CreateWebRequest();
|
||||
|
||||
req.Method = HttpMethod.POST;
|
||||
req.AddParameter(@"target_type", message.TargetType.GetDescription());
|
||||
req.AddParameter(@"target_id", message.TargetId.ToString());
|
||||
req.Method = HttpMethod.Post;
|
||||
req.AddParameter(@"is_action", message.IsAction.ToString().ToLowerInvariant());
|
||||
req.AddParameter(@"message", message.Content);
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
protected override string Target => @"chat/messages";
|
||||
protected override string Target => $@"chat/channels/{message.TargetId}/messages";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user