1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-12 10:04:43 +01:00

Set push token state values to be user-specific (#2200)

* Changed the current push token and last registration time to be user-based

* Fixed compile error.

* Fixed interface implementation.

* Fixed compile error for Android.

* Refactored to handle getting active user ID within state service

* Refactored methods allow existing logic to handle getting the active user.

* Updated to reconcile options.

* Updated naming and fixed issue with UserId.

* Removed space between constants.
This commit is contained in:
Todd Martin 2022-12-14 16:07:04 -05:00 committed by GitHub
parent 37dab0928b
commit ebf65ecb96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 24 deletions

View File

@ -19,9 +19,7 @@ namespace Bit.App.Services
Constants.AddSitePromptShownKey, Constants.AddSitePromptShownKey,
Constants.PushInitialPromptShownKey, Constants.PushInitialPromptShownKey,
Constants.LastFileCacheClearKey, Constants.LastFileCacheClearKey,
Constants.PushLastRegistrationDateKey,
Constants.PushRegisteredTokenKey, Constants.PushRegisteredTokenKey,
Constants.PushCurrentTokenKey,
Constants.LastBuildKey, Constants.LastBuildKey,
Constants.ClearCiphersCacheKey, Constants.ClearCiphersCacheKey,
Constants.BiometricIntegrityKey, Constants.BiometricIntegrityKey,

View File

@ -119,12 +119,12 @@ namespace Bit.Core.Abstractions
Task SetAddSitePromptShownAsync(bool? value, string userId = null); Task SetAddSitePromptShownAsync(bool? value, string userId = null);
Task<bool?> GetPushInitialPromptShownAsync(); Task<bool?> GetPushInitialPromptShownAsync();
Task SetPushInitialPromptShownAsync(bool? value); Task SetPushInitialPromptShownAsync(bool? value);
Task<DateTime?> GetPushLastRegistrationDateAsync(); Task<DateTime?> GetPushLastRegistrationDateAsync(string userId = null);
Task SetPushLastRegistrationDateAsync(DateTime? value); Task SetPushLastRegistrationDateAsync(DateTime? value, string userId = null);
Task<string> GetPushInstallationRegistrationErrorAsync(); Task<string> GetPushInstallationRegistrationErrorAsync();
Task SetPushInstallationRegistrationErrorAsync(string value); Task SetPushInstallationRegistrationErrorAsync(string value);
Task<string> GetPushCurrentTokenAsync(); Task<string> GetPushCurrentTokenAsync(string userId = null);
Task SetPushCurrentTokenAsync(string value); Task SetPushCurrentTokenAsync(string value, string userId = null);
Task<List<EventData>> GetEventCollectionAsync(); Task<List<EventData>> GetEventCollectionAsync();
Task SetEventCollectionAsync(List<EventData> value); Task SetEventCollectionAsync(List<EventData> value);
Task<Dictionary<string, FolderData>> GetEncryptedFoldersAsync(string userId = null); Task<Dictionary<string, FolderData>> GetEncryptedFoldersAsync(string userId = null);

View File

@ -12,8 +12,6 @@
public static string LastFileCacheClearKey = "lastFileCacheClear"; public static string LastFileCacheClearKey = "lastFileCacheClear";
public static string AutofillTileAdded = "autofillTileAdded"; public static string AutofillTileAdded = "autofillTileAdded";
public static string PushRegisteredTokenKey = "pushRegisteredToken"; public static string PushRegisteredTokenKey = "pushRegisteredToken";
public static string PushCurrentTokenKey = "pushCurrentToken";
public static string PushLastRegistrationDateKey = "pushLastRegistrationDate";
public static string PushInitialPromptShownKey = "pushInitialPromptShown"; public static string PushInitialPromptShownKey = "pushInitialPromptShown";
public static string PushInstallationRegistrationErrorKey = "pushInstallationRegistrationError"; public static string PushInstallationRegistrationErrorKey = "pushInstallationRegistrationError";
public static string LastBuildKey = "lastBuild"; public static string LastBuildKey = "lastBuild";
@ -96,6 +94,8 @@
public static string BiometricUnlockKey(string userId) => $"biometricUnlock_{userId}"; public static string BiometricUnlockKey(string userId) => $"biometricUnlock_{userId}";
public static string ApprovePasswordlessLoginsKey(string userId) => $"approvePasswordlessLogins_{userId}"; public static string ApprovePasswordlessLoginsKey(string userId) => $"approvePasswordlessLogins_{userId}";
public static string UsernameGenOptionsKey(string userId) => $"usernameGenerationOptions_{userId}"; public static string UsernameGenOptionsKey(string userId) => $"usernameGenerationOptions_{userId}";
public static string PushLastRegistrationDateKey(string userId) => $"pushLastRegistrationDate_{userId}";
public static string PushCurrentTokenKey(string userId) => $"pushCurrentToken_{userId}";
public static string ShouldConnectToWatchKey(string userId) => $"shouldConnectToWatch_{userId}"; public static string ShouldConnectToWatchKey(string userId) => $"shouldConnectToWatch_{userId}";
} }
} }

View File

@ -1009,18 +1009,18 @@ namespace Bit.Core.Services
await SetValueAsync(key, value, options); await SetValueAsync(key, value, options);
} }
public async Task<DateTime?> GetPushLastRegistrationDateAsync() public async Task<DateTime?> GetPushLastRegistrationDateAsync(string userId = null)
{ {
var options = await GetDefaultStorageOptionsAsync(); var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync());
var key = Constants.PushLastRegistrationDateKey; var key = Constants.PushLastRegistrationDateKey(reconciledOptions.UserId);
return await GetValueAsync<DateTime?>(key, options); return await GetValueAsync<DateTime?>(key, reconciledOptions);
} }
public async Task SetPushLastRegistrationDateAsync(DateTime? value) public async Task SetPushLastRegistrationDateAsync(DateTime? value, string userId = null)
{ {
var options = await GetDefaultStorageOptionsAsync(); var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync());
var key = Constants.PushLastRegistrationDateKey; var key = Constants.PushLastRegistrationDateKey(reconciledOptions.UserId);
await SetValueAsync(key, value, options); await SetValueAsync(key, value, reconciledOptions);
} }
public async Task<string> GetPushInstallationRegistrationErrorAsync() public async Task<string> GetPushInstallationRegistrationErrorAsync()
@ -1037,18 +1037,18 @@ namespace Bit.Core.Services
await SetValueAsync(key, value, options); await SetValueAsync(key, value, options);
} }
public async Task<string> GetPushCurrentTokenAsync() public async Task<string> GetPushCurrentTokenAsync(string userId = null)
{ {
var options = await GetDefaultStorageOptionsAsync(); var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync());
var key = Constants.PushCurrentTokenKey; var key = Constants.PushCurrentTokenKey(reconciledOptions.UserId);
return await GetValueAsync<string>(key, options); return await GetValueAsync<string>(key, reconciledOptions);
} }
public async Task SetPushCurrentTokenAsync(string value) public async Task SetPushCurrentTokenAsync(string value, string userId = null)
{ {
var options = await GetDefaultStorageOptionsAsync(); var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId }, await GetDefaultStorageOptionsAsync());
var key = Constants.PushCurrentTokenKey; var key = Constants.PushCurrentTokenKey(reconciledOptions.UserId);
await SetValueAsync(key, value, options); await SetValueAsync(key, value, reconciledOptions);
} }
public async Task<List<EventData>> GetEventCollectionAsync() public async Task<List<EventData>> GetEventCollectionAsync()