Pass in lastMessageId instead of self referencing

This commit is contained in:
Dean Herbert 2018-07-24 18:01:28 +02:00
parent 6937cf27a7
commit 7b653fab17
2 changed files with 7 additions and 5 deletions

View File

@ -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)

View File

@ -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 =>
{