mirror of
https://github.com/bitwarden/android.git
synced 2024-12-21 00:31:58 +03:00
push device /w token to server upon registration
This commit is contained in:
parent
3e91510868
commit
0f5b2f5721
1 changed files with 29 additions and 1 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue