Skip to content

Commit 58d15a9

Browse files
authored
Merge pull request #332 from Iterable/MOB-2762-BUG-fix-In-App-Read-State
[MOB-2762] - Bug fix - In App read state
2 parents fedfa58 + 9bc7533 commit 58d15a9

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppManager.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ public void execute(String payload) {
181181
} catch (JSONException e) {
182182
IterableLogger.e(TAG, e.toString());
183183
}
184+
} else {
185+
scheduleProcessing();
184186
}
185187
}
186188
});
@@ -428,9 +430,10 @@ private void handleIterableCustomAction(String actionName, IterableInAppMessage
428430

429431
@Override
430432
public void onSwitchToForeground() {
431-
scheduleProcessing();
432433
if (IterableUtil.currentTimeMillis() - lastSyncTime > MOVE_TO_FOREGROUND_SYNC_INTERVAL_MS) {
433434
syncInApp();
435+
} else {
436+
scheduleProcessing();
434437
}
435438
}
436439

iterableapi/src/test/java/com/iterable/iterableapi/IterableInAppManagerTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,14 @@ public void testReset() throws Exception {
163163
@Test
164164
public void testProcessAfterForeground() throws Exception {
165165
dispatcher.enqueueResponse("/inApp/getMessages", new MockResponse().setBody(IterableTestUtils.getResourceString("inapp_payload_single.json")));
166-
IterableInAppManager inAppManager = IterableApi.getInstance().getInAppManager();
167-
assertEquals(0, inAppManager.getMessages().size());
168166

169-
inAppManager.syncInApp();
167+
ActivityController<Activity> activityController = Robolectric.buildActivity(Activity.class).create().start().resume();
170168
shadowOf(getMainLooper()).idle();
171-
assertEquals(1, inAppManager.getMessages().size());
169+
shadowOf(getMainLooper()).runToEndOfTasks();
172170

173-
ActivityController<Activity> activityController = Robolectric.buildActivity(Activity.class).create().start().resume();
171+
IterableInAppManager inAppManager = IterableApi.getInstance().getInAppManager();
174172
shadowOf(getMainLooper()).idle();
173+
assertEquals(1, inAppManager.getMessages().size());
175174

176175
ArgumentCaptor<IterableInAppMessage> inAppMessageCaptor = ArgumentCaptor.forClass(IterableInAppMessage.class);
177176
verify(inAppHandler).onNewInApp(inAppMessageCaptor.capture());

iterableapi/src/test/java/com/iterable/iterableapi/IterableInboxTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,9 @@ public IterableConfig.Builder run(IterableConfig.Builder builder) {
127127
return builder.setInAppHandler(inAppHandler).setCustomActionHandler(customActionHandler).setUrlHandler(urlHandler);
128128
}
129129
});
130-
inAppManager.syncInApp();
131-
shadowOf(getMainLooper()).idle();
132-
133-
assertEquals(2, inAppManager.getInboxMessages().size());
134-
assertEquals(2, inAppManager.getUnreadInboxMessagesCount());
135130

136131
Robolectric.buildActivity(Activity.class).create().start().resume();
132+
shadowOf(getMainLooper()).idle();
137133

138134
verify(inAppDisplayerMock).showMessage(any(IterableInAppMessage.class), eq(IterableInAppLocation.IN_APP), any(IterableHelper.IterableUrlCallback.class));
139135

iterableapi/src/test/resources/inapp_payload_inbox_show.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"inAppMessages": [
33
{
44
"messageId": "message1",
5+
"read": false,
56
"trigger": {
67
"type": "immediate"
78
},
@@ -28,6 +29,7 @@
2829
}
2930
},{
3031
"messageId": "message2",
32+
"read": false,
3133
"trigger": {
3234
"type": "immediate"
3335
},

iterableapi/src/test/resources/inapp_payload_single.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{
44
"messageId": "7kx2MmoGdCpuZao9fDueuQoXVAZuDaVV",
55
"expiresAt": 1949157312395,
6+
"read": false,
67
"trigger": {
78
"type": "immediate"
89
},

0 commit comments

Comments
 (0)