1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-29 12:45:20 +01:00

Check push registration once per day

This commit is contained in:
Kyle Spearrin 2016-07-01 19:16:47 -04:00
parent 6d6f4b350b
commit 5a34d4cd6d
3 changed files with 22 additions and 7 deletions

View File

@ -7,7 +7,7 @@
public const string SettingLockSeconds = "lockSeconds";
public const string SettingLastBackgroundedDate = "lastBackgroundedDate";
public const string PushPromptShown = "initialPushPromptShown";
public const string PushLastRegistration = "lastPushRegistration";
}
}

View File

@ -82,13 +82,21 @@ namespace Bit.App.Pages
if(_connectivity.IsConnected && Device.OS == TargetPlatform.iOS && !_favorites)
{
if(!_settings.GetValueOrDefault<bool>(Constants.PushPromptShown))
var pushPromptShow = _settings.GetValueOrDefault<bool>(Constants.PushPromptShown);
if(!pushPromptShow)
{
_settings.AddOrUpdateValue(Constants.PushPromptShown, true);
await _userDialogs.AlertAsync("bitwarden keeps your vault automatically synced by using push notifications. For the best possible experience, please select \"Ok\" on the following prompt when asked to enable push notifications.", "Enable Automatic Syncing", "Ok, got it!");
await _userDialogs.AlertAsync(@"bitwarden keeps your vault automatically synced by using push notifications.
For the best possible experience, please select ""Ok"" on the following prompt when asked to enable push notifications.",
"Enable Automatic Syncing", "Ok, got it!");
}
_pushNotification.Register();
// Check push registration once per day
var lastPushRegistration = _settings.GetValueOrDefault<DateTime?>(Constants.PushLastRegistration);
if(!pushPromptShow || !lastPushRegistration.HasValue || (DateTime.UtcNow - lastPushRegistration) > TimeSpan.FromDays(1))
{
_pushNotification.Register();
}
}
}
@ -193,7 +201,7 @@ namespace Bit.App.Pages
{
private VaultListSitesPage _page;
public static readonly BindableProperty SiteParameterProperty = BindableProperty.Create(nameof(SiteParameter),
public static readonly BindableProperty SiteParameterProperty = BindableProperty.Create(nameof(SiteParameter),
typeof(VaultListPageModel.Site), typeof(VaultListViewCell), null);
public VaultListViewCell(VaultListSitesPage page)

View File

@ -5,6 +5,8 @@ using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Bit.App.Abstractions;
using Bit.App.Models;
using Plugin.Settings.Abstractions;
using System;
namespace Bit.App.Services
{
@ -15,17 +17,20 @@ namespace Bit.App.Services
private readonly IDeviceApiRepository _deviceApiRepository;
private readonly IAuthService _authService;
private readonly IAppIdService _appIdService;
private readonly ISettings _settings;
public PushNotificationListener(
ISyncService syncService,
IDeviceApiRepository deviceApiRepository,
IAuthService authService,
IAppIdService appIdService)
IAppIdService appIdService,
ISettings settings)
{
_syncService = syncService;
_deviceApiRepository = deviceApiRepository;
_authService = authService;
_appIdService = appIdService;
_settings = settings;
}
public void OnMessage(JObject values, DeviceType deviceType)
@ -33,7 +38,7 @@ namespace Bit.App.Services
_showNotification = false;
Debug.WriteLine("Message Arrived: {0}", JsonConvert.SerializeObject(values));
var type = (Enums.PushType)values.GetValue("type", System.StringComparison.OrdinalIgnoreCase).ToObject<short>();
var type = (Enums.PushType)values.GetValue("type", StringComparison.OrdinalIgnoreCase).ToObject<short>();
switch(type)
{
case Enums.PushType.SyncCipherUpdate:
@ -71,6 +76,7 @@ namespace Bit.App.Services
if(response.Succeeded)
{
Debug.WriteLine("Registered device with server.");
_settings.AddOrUpdateValue(Constants.PushLastRegistration, DateTime.UtcNow);
}
else
{
@ -81,6 +87,7 @@ namespace Bit.App.Services
public void OnUnregistered(DeviceType deviceType)
{
Debug.WriteLine("Push Notification - Device Unnregistered");
_settings.Remove(Constants.PushLastRegistration);
}
public void OnError(string message, DeviceType deviceType)