mirror of
https://github.com/ppy/osu
synced 2024-12-18 04:46:09 +00:00
Pass in lastMessageId instead of self referencing
This commit is contained in:
parent
6937cf27a7
commit
7b653fab17
@ -84,10 +84,10 @@ namespace osu.Game.Online.Chat
|
||||
CurrentChannel.ValueChanged += currentChannelChanged;
|
||||
|
||||
channelMessagesHandler = new IncomingMessagesHandler(
|
||||
() => new GetMessagesRequest(JoinedChannels.Where(c => c.Target == TargetType.Channel), channelMessagesHandler.LastMessageId), handleChannelMessages);
|
||||
lastId => new GetMessagesRequest(JoinedChannels.Where(c => c.Target == TargetType.Channel), lastId), handleChannelMessages);
|
||||
|
||||
privateMessagesHandler = new IncomingMessagesHandler(
|
||||
() => new GetPrivateMessagesRequest(privateMessagesHandler.LastMessageId),handleUserMessages);
|
||||
lastId => new GetPrivateMessagesRequest(lastId),handleUserMessages);
|
||||
}
|
||||
|
||||
private void currentChannelChanged(Channel channel)
|
||||
|
@ -15,16 +15,18 @@ namespace osu.Game.Online.Chat
|
||||
/// </summary>
|
||||
public class IncomingMessagesHandler
|
||||
{
|
||||
public delegate APIMessagesRequest CreateRequestDelegate(long? lastMessageId);
|
||||
|
||||
public long? LastMessageId { get; private set; }
|
||||
|
||||
private APIMessagesRequest getMessagesRequest;
|
||||
|
||||
private readonly Func<APIMessagesRequest> createRequest;
|
||||
private readonly CreateRequestDelegate createRequest;
|
||||
private readonly Action<List<Message>> onNewMessages;
|
||||
|
||||
public bool CanRequestNewMessages => getMessagesRequest == null;
|
||||
|
||||
public IncomingMessagesHandler([NotNull] Func<APIMessagesRequest> createRequest, [NotNull] Action<List<Message>> onNewMessages)
|
||||
public IncomingMessagesHandler([NotNull] CreateRequestDelegate createRequest, [NotNull] Action<List<Message>> onNewMessages)
|
||||
{
|
||||
this.createRequest = createRequest ?? throw new ArgumentNullException(nameof(createRequest));
|
||||
this.onNewMessages = onNewMessages ?? throw new ArgumentNullException(nameof(onNewMessages));
|
||||
@ -35,7 +37,7 @@ namespace osu.Game.Online.Chat
|
||||
if (!CanRequestNewMessages)
|
||||
throw new InvalidOperationException("Requesting new messages is not possible yet, because the old request is still ongoing.");
|
||||
|
||||
getMessagesRequest = createRequest.Invoke();
|
||||
getMessagesRequest = createRequest.Invoke(LastMessageId);
|
||||
getMessagesRequest.Success += handleNewMessages;
|
||||
getMessagesRequest.Failure += exception =>
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user