mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 13:53:34 +00:00
[PM-10381] Fix waiting for last sync - Browser Refresh (#10438)
* [PM-10381] Add activeUserLastSync$ to SyncService * [PM-10381] Introduce waitUtil operator * [PM-10381] Use new activeUserLastSync$ observable to wait until a sync completes before attempting to get decrypted ciphers * [PM-10381] Fix failing test --------- Co-authored-by: bnagawiecki <107435978+bnagawiecki@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { firstValueFrom, map, of, switchMap } from "rxjs";
|
||||
import { firstValueFrom, map, Observable, of, switchMap } from "rxjs";
|
||||
|
||||
import { ApiService } from "../../abstractions/api.service";
|
||||
import { AccountService } from "../../auth/abstractions/account.service";
|
||||
@@ -67,6 +67,17 @@ export abstract class CoreSyncService implements SyncService {
|
||||
return this.stateProvider.getUser(userId, LAST_SYNC_DATE).state$;
|
||||
}
|
||||
|
||||
activeUserLastSync$(): Observable<Date | null> {
|
||||
return this.accountService.activeAccount$.pipe(
|
||||
switchMap((a) => {
|
||||
if (a == null) {
|
||||
return of(null);
|
||||
}
|
||||
return this.lastSync$(a.id);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async setLastSync(date: Date, userId: UserId): Promise<void> {
|
||||
await this.stateProvider.getUser(userId, LAST_SYNC_DATE).update(() => date);
|
||||
}
|
||||
|
||||
@@ -34,6 +34,12 @@ export abstract class SyncService {
|
||||
*/
|
||||
abstract lastSync$(userId: UserId): Observable<Date | null>;
|
||||
|
||||
/**
|
||||
* Retrieves a stream of the currently active user's last sync date.
|
||||
* Or null if there is no current active user or the active user has not synced before.
|
||||
*/
|
||||
abstract activeUserLastSync$(): Observable<Date | null>;
|
||||
|
||||
/**
|
||||
* Optionally does a full sync operation including going to the server to gather the source
|
||||
* of truth and set that data to state.
|
||||
|
||||
Reference in New Issue
Block a user