@@ -251,40 +251,47 @@ export class IndexedDbPersistence implements Persistence {
251
251
txn : SimpleDbTransaction
252
252
) : PersistencePromise < boolean > {
253
253
const store = ownerStore ( txn ) ;
254
- return store . get ( 'owner' ) . next ( currentPrimary => {
255
- const currentLeaseIsValid =
256
- currentPrimary !== null &&
257
- this . isWithinMaxAge ( currentPrimary . leaseTimestampMs ) &&
258
- currentPrimary . ownerId !== this . getZombiedClientId ( ) ;
259
-
260
- if ( currentLeaseIsValid ) {
261
- return this . isLocalClient ( currentPrimary ) ;
262
- }
263
- // Check if this client is eligible for a primary lease based on its
264
- // visibility state and the visibility state of all active clients. A
265
- // client can obtain the primary lease if it is either in the foreground
266
- // or if this client and all other clients are in the background.
267
- if ( this . inForeground ) {
268
- return true ;
269
- }
254
+ return store
255
+ . get ( 'owner' )
256
+ . next ( currentPrimary => {
257
+ const currentLeaseIsValid =
258
+ currentPrimary !== null &&
259
+ this . isWithinMaxAge ( currentPrimary . leaseTimestampMs ) &&
260
+ currentPrimary . ownerId !== this . getZombiedClientId ( ) ;
261
+
262
+ if ( currentLeaseIsValid ) {
263
+ return this . isLocalClient ( currentPrimary ) ;
264
+ }
265
+ // Check if this client is eligible for a primary lease based on its
266
+ // visibility state and the visibility state of all active clients. A
267
+ // client can obtain the primary lease if it is either in the foreground
268
+ // or if this client and all other clients are in the background.
269
+ if ( this . inForeground ) {
270
+ return true ;
271
+ }
270
272
271
- let canActAsPrimary = true ;
272
- return clientMetadataStore ( txn )
273
- . iterate ( ( key , value , control ) => {
274
- if ( this . clientKey !== value . clientKey ) {
275
- if ( this . isWithinMaxAge ( value . updateTimeMs ) && value . inForeground ) {
276
- canActAsPrimary = false ;
277
- control . done ( ) ;
273
+ let canActAsPrimary = true ;
274
+ return clientMetadataStore ( txn )
275
+ . iterate ( ( key , value , control ) => {
276
+ if ( this . clientKey !== value . clientKey ) {
277
+ if (
278
+ this . isWithinMaxAge ( value . updateTimeMs ) &&
279
+ value . inForeground
280
+ ) {
281
+ canActAsPrimary = false ;
282
+ control . done ( ) ;
283
+ }
278
284
}
279
- }
280
- } ) . next ( ( ) => canActAsPrimary )
281
- } ) . next ( canActAsPrimary => {
285
+ } )
286
+ . next ( ( ) => canActAsPrimary ) ;
287
+ } )
288
+ . next ( canActAsPrimary => {
282
289
if ( this . isPrimary !== canActAsPrimary ) {
283
290
log . debug (
284
- LOG_TAG ,
285
- `Client ${
286
- canActAsPrimary ? 'is' : 'is not'
287
- } eligible for a primary lease.`
291
+ LOG_TAG ,
292
+ `Client ${
293
+ canActAsPrimary ? 'is' : 'is not'
294
+ } eligible for a primary lease.`
288
295
) ;
289
296
}
290
297
return canActAsPrimary ;
0 commit comments