1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-06-25 10:26:02 +02:00

push device /w token to server upon registration

This commit is contained in:
Kyle Spearrin 2016-06-18 16:20:31 -04:00
parent 3e91510868
commit 0f5b2f5721

View File

@ -16,10 +16,17 @@ namespace Bit.App.Services
{
private bool _showNotification;
private readonly ISyncService _syncService;
private readonly IDeviceApiRepository _deviceApiRepository;
private readonly IAuthService _authService;
public PushNotificationListener(ISyncService syncService)
public PushNotificationListener(
ISyncService syncService,
IDeviceApiRepository deviceApiRepository,
IAuthService authService)
{
_syncService = syncService;
_deviceApiRepository = deviceApiRepository;
_authService = authService;
}
public void OnMessage(JObject values, DeviceType deviceType)
@ -31,6 +38,27 @@ namespace Bit.App.Services
public void OnRegistered(string token, DeviceType deviceType)
{
Debug.WriteLine(string.Format("Push Notification - Device Registered - Token : {0}", token));
if(!_authService.IsAuthenticated)
{
return;
}
var response = _deviceApiRepository.PostAsync(new Models.Api.DeviceRequest
{
Name = deviceType.ToString(),
Type = deviceType,
PushToken = token
}).GetAwaiter().GetResult();
if(response.Succeeded)
{
Debug.WriteLine("Registered device with server.");
}
else
{
Debug.WriteLine("Failed to register device.");
}
}
public void OnUnregistered(DeviceType deviceType)