Implemented missing method and typing notifier

This commit is contained in:
RogueException
2016-10-06 01:04:04 -03:00
parent 2f3831dd6e
commit dcd94381fc
3 changed files with 47 additions and 7 deletions

View File

@@ -207,8 +207,6 @@ namespace Discord.Rest
//Typing
public static IDisposable EnterTypingState(IChannel channel, BaseDiscordClient client)
{
throw new NotImplementedException(); //TODO: Impl
}
=> new TypingNotifier(client, channel);
}
}

View File

@@ -0,0 +1,44 @@
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Discord.Rest
{
internal class TypingNotifier : IDisposable
{
private readonly BaseDiscordClient _client;
private readonly CancellationTokenSource _cancelToken;
private readonly ulong _channelId;
public TypingNotifier(BaseDiscordClient discord, IChannel channel)
{
_client = discord;
_cancelToken = new CancellationTokenSource();
_channelId = channel.Id;
var _ = Run();
}
private async Task Run()
{
try
{
var token = _cancelToken.Token;
while (!_cancelToken.IsCancellationRequested)
{
try
{
await _client.ApiClient.TriggerTypingIndicatorAsync(_channelId);
}
catch { }
await Task.Delay(4500, token);
}
}
catch (OperationCanceledException) { }
}
public void Dispose()
{
_cancelToken.Cancel();
}
}
}