From 0f5b2f572138b3805e7080b9f050d124a3d3e471 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Sat, 18 Jun 2016 16:20:31 -0400 Subject: [PATCH] push device /w token to server upon registration --- src/App/Services/PushNotificationListener.cs | 30 +++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/App/Services/PushNotificationListener.cs b/src/App/Services/PushNotificationListener.cs index 4dbd8f816..d0a2b74f2 100644 --- a/src/App/Services/PushNotificationListener.cs +++ b/src/App/Services/PushNotificationListener.cs @@ -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)