aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Remote
diff options
context:
space:
mode:
authorGravatar zxu123 <zxu@google.com>2017-12-06 16:16:22 -0500
committerGravatar zxu123 <zxu@google.com>2017-12-06 16:16:22 -0500
commit125cdc78c68b322d4ff06a906ed32548ade46003 (patch)
treec02914d8348069572492c416efed1fef755b7d6a /Firestore/Source/Remote
parentef2a0a2acf7f727b50e5acb6b652ff8551124c9d (diff)
refactoring the condition when to warn offline
Diffstat (limited to 'Firestore/Source/Remote')
-rw-r--r--Firestore/Source/Remote/FSTRemoteStore.m12
1 files changed, 9 insertions, 3 deletions
diff --git a/Firestore/Source/Remote/FSTRemoteStore.m b/Firestore/Source/Remote/FSTRemoteStore.m
index 42dab58..063e487 100644
--- a/Firestore/Source/Remote/FSTRemoteStore.m
+++ b/Firestore/Source/Remote/FSTRemoteStore.m
@@ -110,6 +110,9 @@ static const int kOnlineAttemptsBeforeFailure = 2;
/** A count of consecutive failures to open the stream. */
@property(nonatomic, assign) int watchStreamFailures;
+/** Whether the client should fire offline warning. */
+@property(nonatomic, assign) BOOL shouldWarnOffline;
+
#pragma mark Write Stream
// The writeStream is null when the network is disabled. The non-null check is performed by
// isNetworkEnabled.
@@ -146,6 +149,7 @@ static const int kOnlineAttemptsBeforeFailure = 2;
_lastBatchSeen = kFSTBatchIDUnknown;
_watchStreamOnlineState = FSTOnlineStateUnknown;
+ _shouldWarnOffline = YES;
_pendingWrites = [NSMutableArray array];
}
return self;
@@ -157,6 +161,7 @@ static const int kOnlineAttemptsBeforeFailure = 2;
}
- (void)setOnlineStateToHealthy {
+ self.shouldWarnOffline = NO;
[self updateAndNotifyAboutOnlineState:FSTOnlineStateHealthy];
}
@@ -179,6 +184,10 @@ static const int kOnlineAttemptsBeforeFailure = 2;
} else {
self.watchStreamFailures++;
if (self.watchStreamFailures >= kOnlineAttemptsBeforeFailure) {
+ if (self.shouldWarnOffline) {
+ FSTWarn(@"Could not reach Firestore backend.");
+ self.shouldWarnOffline = NO;
+ }
[self updateAndNotifyAboutOnlineState:FSTOnlineStateFailed];
}
}
@@ -188,9 +197,6 @@ static const int kOnlineAttemptsBeforeFailure = 2;
BOOL didChange = (watchStreamOnlineState != self.watchStreamOnlineState);
self.watchStreamOnlineState = watchStreamOnlineState;
if (didChange) {
- if (watchStreamOnlineState == FSTOnlineStateFailed) {
- FSTWarn(@"Could not reach Firestore backend.");
- }
[self.onlineStateDelegate watchStreamDidChangeOnlineState:watchStreamOnlineState];
}
}