Only process push messages for the current logged in user. Do not unregister from push on logout.

This commit is contained in:
Kyle Spearrin 2016-08-20 22:18:05 -04:00
parent 7b9c00cd77
commit fb77747a1b
4 changed files with 21 additions and 6 deletions

View file

@ -56,7 +56,6 @@ namespace Bit.Android
Resolver.Resolve<ISyncService>(), Resolver.Resolve<ISyncService>(),
Resolver.Resolve<IFingerprint>(), Resolver.Resolve<IFingerprint>(),
Resolver.Resolve<ISettings>(), Resolver.Resolve<ISettings>(),
Resolver.Resolve<IPushNotification>(),
Resolver.Resolve<ILockService>(), Resolver.Resolve<ILockService>(),
Resolver.Resolve<IGoogleAnalyticsService>())); Resolver.Resolve<IGoogleAnalyticsService>()));

View file

@ -27,7 +27,6 @@ namespace Bit.App
private readonly IAuthService _authService; private readonly IAuthService _authService;
private readonly IFingerprint _fingerprint; private readonly IFingerprint _fingerprint;
private readonly ISettings _settings; private readonly ISettings _settings;
private readonly IPushNotification _pushNotification;
private readonly ILockService _lockService; private readonly ILockService _lockService;
private readonly IGoogleAnalyticsService _googleAnalyticsService; private readonly IGoogleAnalyticsService _googleAnalyticsService;
@ -39,7 +38,6 @@ namespace Bit.App
ISyncService syncService, ISyncService syncService,
IFingerprint fingerprint, IFingerprint fingerprint,
ISettings settings, ISettings settings,
IPushNotification pushNotification,
ILockService lockService, ILockService lockService,
IGoogleAnalyticsService googleAnalyticsService) IGoogleAnalyticsService googleAnalyticsService)
{ {
@ -50,7 +48,6 @@ namespace Bit.App
_authService = authService; _authService = authService;
_fingerprint = fingerprint; _fingerprint = fingerprint;
_settings = settings; _settings = settings;
_pushNotification = pushNotification;
_lockService = lockService; _lockService = lockService;
_googleAnalyticsService = googleAnalyticsService; _googleAnalyticsService = googleAnalyticsService;
@ -211,7 +208,6 @@ namespace Bit.App
var deviceApiRepository = Resolver.Resolve<IDeviceApiRepository>(); var deviceApiRepository = Resolver.Resolve<IDeviceApiRepository>();
var appIdService = Resolver.Resolve<IAppIdService>(); var appIdService = Resolver.Resolve<IAppIdService>();
_pushNotification.Unregister();
_settings.Remove(Constants.PushLastRegistrationDate); _settings.Remove(Constants.PushLastRegistrationDate);
await Task.Run(() => deviceApiRepository.PutClearTokenAsync(appIdService.AppId)).ConfigureAwait(false); await Task.Run(() => deviceApiRepository.PutClearTokenAsync(appIdService.AppId)).ConfigureAwait(false);
} }

View file

@ -43,6 +43,11 @@ namespace Bit.App.Services
_showNotification = false; _showNotification = false;
Debug.WriteLine("Message Arrived: {0}", JsonConvert.SerializeObject(values)); Debug.WriteLine("Message Arrived: {0}", JsonConvert.SerializeObject(values));
if(!_authService.IsAuthenticated)
{
return;
}
JToken token; JToken token;
if(!values.TryGetValue("type", StringComparison.OrdinalIgnoreCase, out token) || token == null) if(!values.TryGetValue("type", StringComparison.OrdinalIgnoreCase, out token) || token == null)
{ {
@ -55,18 +60,34 @@ namespace Bit.App.Services
case Enums.PushType.SyncCipherUpdate: case Enums.PushType.SyncCipherUpdate:
case Enums.PushType.SyncCipherCreate: case Enums.PushType.SyncCipherCreate:
var createUpdateMessage = values.ToObject<SyncCipherPushNotification>(); var createUpdateMessage = values.ToObject<SyncCipherPushNotification>();
if(createUpdateMessage.UserId != _authService.UserId)
{
break;
}
_syncService.SyncAsync(createUpdateMessage.Id); _syncService.SyncAsync(createUpdateMessage.Id);
break; break;
case Enums.PushType.SyncFolderDelete: case Enums.PushType.SyncFolderDelete:
var folderDeleteMessage = values.ToObject<SyncCipherPushNotification>(); var folderDeleteMessage = values.ToObject<SyncCipherPushNotification>();
if(folderDeleteMessage.UserId != _authService.UserId)
{
break;
}
_syncService.SyncDeleteFolderAsync(folderDeleteMessage.Id, folderDeleteMessage.RevisionDate); _syncService.SyncDeleteFolderAsync(folderDeleteMessage.Id, folderDeleteMessage.RevisionDate);
break; break;
case Enums.PushType.SyncSiteDelete: case Enums.PushType.SyncSiteDelete:
var siteDeleteMessage = values.ToObject<SyncCipherPushNotification>(); var siteDeleteMessage = values.ToObject<SyncCipherPushNotification>();
if(siteDeleteMessage.UserId != _authService.UserId)
{
break;
}
_syncService.SyncDeleteSiteAsync(siteDeleteMessage.Id); _syncService.SyncDeleteSiteAsync(siteDeleteMessage.Id);
break; break;
case Enums.PushType.SyncCiphers: case Enums.PushType.SyncCiphers:
var cipherMessage = values.ToObject<SyncCiphersPushNotification>(); var cipherMessage = values.ToObject<SyncCiphersPushNotification>();
if(cipherMessage.UserId != _authService.UserId)
{
break;
}
_syncService.FullSyncAsync(); _syncService.FullSyncAsync();
break; break;
default: default:

View file

@ -65,7 +65,6 @@ namespace Bit.iOS
Resolver.Resolve<ISyncService>(), Resolver.Resolve<ISyncService>(),
Resolver.Resolve<IFingerprint>(), Resolver.Resolve<IFingerprint>(),
Resolver.Resolve<ISettings>(), Resolver.Resolve<ISettings>(),
Resolver.Resolve<IPushNotification>(),
Resolver.Resolve<ILockService>(), Resolver.Resolve<ILockService>(),
Resolver.Resolve<IGoogleAnalyticsService>())); Resolver.Resolve<IGoogleAnalyticsService>()));