|
40 | 40 | import com.google.firebase.firestore.model.NoDocument;
|
41 | 41 | import com.google.firebase.firestore.model.SnapshotVersion;
|
42 | 42 | import com.google.firebase.firestore.model.mutation.Mutation;
|
| 43 | +import com.google.firebase.firestore.model.mutation.MutationBatch; |
43 | 44 | import com.google.firebase.firestore.model.mutation.MutationBatchResult;
|
44 | 45 | import com.google.firebase.firestore.remote.Datastore;
|
45 | 46 | import com.google.firebase.firestore.remote.RemoteEvent;
|
@@ -448,12 +449,13 @@ public void registerPendingWritesTask(TaskCompletionSource<Void> userTask) {
|
448 | 449 | if (!remoteStore.canUseNetwork()) {
|
449 | 450 | Logger.debug(
|
450 | 451 | TAG,
|
451 |
| - "The network is disabled. The task returned by 'awaitPendingWrites()' will not complete until the network is enabled."); |
| 452 | + "The network is disabled. The task returned by 'awaitPendingWrites()' will not" |
| 453 | + + " complete until the network is enabled."); |
452 | 454 | }
|
453 | 455 |
|
454 | 456 | int largestPendingBatchId = localStore.getHighestUnacknowledgedBatchId();
|
455 | 457 |
|
456 |
| - if (largestPendingBatchId == 0) { |
| 458 | + if (largestPendingBatchId == MutationBatch.UNKNOWN) { |
457 | 459 | // Complete the task right away if there is no pending writes at the moment.
|
458 | 460 | userTask.setResult(null);
|
459 | 461 | return;
|
@@ -623,10 +625,11 @@ public void handleCredentialChange(User user) {
|
623 | 625 | currentUser = user;
|
624 | 626 |
|
625 | 627 | if (userChanged) {
|
| 628 | + // Fails tasks waiting for pending writes requested by previous user. |
| 629 | + failOutstandingPendingWritesAwaitingTasks(); |
626 | 630 | // Notify local store and emit any resulting events from swapping out the mutation queue.
|
627 | 631 | ImmutableSortedMap<DocumentKey, MaybeDocument> changes = localStore.handleUserChange(user);
|
628 | 632 | emitNewSnapsAndNotifyLocalStore(changes, /*remoteEvent=*/ null);
|
629 |
| - failOutstandingPendingWritesAwaitingTasks(); |
630 | 633 | }
|
631 | 634 |
|
632 | 635 | // Notify remote store so it can restart its streams.
|
|
0 commit comments