Skip to content

Commit a11a2fa

Browse files
authored
Merge pull request #552 from Iterable/evan/MOB-5848-auto-fetch-boundary
[MOB-5848] auto fetch boundary
2 parents a9c43c5 + d53ffed commit a11a2fa

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableEmbeddedManager.kt

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,29 +202,33 @@ public class IterableEmbeddedManager: IterableActivityMonitor.AppStateCallback{
202202

203203
fun scheduleSync() {
204204
IterableLogger.printInfo()
205-
if (canSyncEmbeddedMessages()) {
206-
IterableLogger.v(TAG, "Can sync now.. Syncing now")
207-
IterableLogger.v(TAG, "setting isSyncScheduled to false in first if")
208-
getSyncedEmbeddedMessages()
205+
if(autoFetchDuration > 0) {
206+
if (canSyncEmbeddedMessages()) {
207+
IterableLogger.v(TAG, "Can sync now.. Syncing now")
208+
IterableLogger.v(TAG, "setting isSyncScheduled to false in first if")
209+
getSyncedEmbeddedMessages()
209210

210-
} else {
211-
if (!isAppInBackground) {
212-
IterableLogger.v(
213-
TAG,
214-
"Scheduling sync after ${autoFetchDuration - getSecondsSinceLastFetch()} seconds"
215-
)
216-
Handler(Looper.getMainLooper()).postDelayed(
217-
{
218-
getSyncedEmbeddedMessages()
219-
IterableLogger.v(TAG, "inside looper setting isSyncScheduled to false")
220-
},
221-
((autoFetchDuration - getSecondsSinceLastFetch()) * 1000).toLong()
222-
)
223-
IterableLogger.v(TAG, "setting isSyncScheduled to true")
224211
} else {
225-
IterableLogger.v(TAG, "Not scheduling a sync.. App is in background")
226-
lastSync = autoFetchDuration.toLong()
212+
if (!isAppInBackground) {
213+
IterableLogger.v(
214+
TAG,
215+
"Scheduling sync after ${autoFetchDuration - getSecondsSinceLastFetch()} seconds"
216+
)
217+
Handler(Looper.getMainLooper()).postDelayed(
218+
{
219+
getSyncedEmbeddedMessages()
220+
IterableLogger.v(TAG, "inside looper setting isSyncScheduled to false")
221+
},
222+
((autoFetchDuration - getSecondsSinceLastFetch()) * 1000).toLong()
223+
)
224+
IterableLogger.v(TAG, "setting isSyncScheduled to true")
225+
} else {
226+
IterableLogger.v(TAG, "Not scheduling a sync.. App is in background")
227+
lastSync = autoFetchDuration.toLong()
228+
}
227229
}
230+
} else {
231+
IterableLogger.v(TAG, "embedded messaging automatic fetching not started since autoFetchDuration is <= 0")
228232
}
229233
}
230234

0 commit comments

Comments
 (0)