@@ -31,6 +31,7 @@ public class IterableInAppMessage {
31
31
private boolean loadedHtmlFromJson = false ;
32
32
private boolean markedForDeletion = false ;
33
33
private @ Nullable IterableInAppStorage inAppStorageInterface ;
34
+ private final boolean jsonOnly ;
34
35
35
36
IterableInAppMessage (@ NonNull String messageId ,
36
37
@ NonNull Content content ,
@@ -41,7 +42,8 @@ public class IterableInAppMessage {
41
42
@ NonNull Double priorityLevel ,
42
43
@ Nullable Boolean saveToInbox ,
43
44
@ Nullable InboxMetadata inboxMetadata ,
44
- @ Nullable Long campaignId ) {
45
+ @ Nullable Long campaignId ,
46
+ boolean jsonOnly ) {
45
47
46
48
this .messageId = messageId ;
47
49
this .content = content ;
@@ -50,9 +52,10 @@ public class IterableInAppMessage {
50
52
this .expiresAt = expiresAt ;
51
53
this .trigger = trigger ;
52
54
this .priorityLevel = priorityLevel ;
53
- this .saveToInbox = saveToInbox ;
55
+ this .saveToInbox = saveToInbox != null ? ( saveToInbox && ! jsonOnly ) : null ;
54
56
this .inboxMetadata = inboxMetadata ;
55
57
this .campaignId = campaignId ;
58
+ this .jsonOnly = jsonOnly ;
56
59
}
57
60
58
61
static class Trigger {
@@ -246,7 +249,7 @@ public Date getExpiresAt() {
246
249
247
250
@ NonNull
248
251
public Content getContent () {
249
- if (content .html == null ) {
252
+ if (content .html == null && ! jsonOnly ) {
250
253
content .html = inAppStorageInterface .getHTML (messageId );
251
254
}
252
255
return content ;
@@ -322,70 +325,87 @@ public void markForDeletion(boolean delete) {
322
325
this .markedForDeletion = delete ;
323
326
}
324
327
328
+ public boolean isJsonOnly () {
329
+ return jsonOnly ;
330
+ }
331
+
325
332
static IterableInAppMessage fromJSONObject (@ NonNull JSONObject messageJson , @ Nullable IterableInAppStorage storageInterface ) {
326
333
327
334
if (messageJson == null ) {
328
335
return null ;
329
336
}
330
337
331
- JSONObject contentJson = messageJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_CONTENT );
332
- if (contentJson == null ) {
333
- return null ;
334
- }
335
-
336
338
String messageId = messageJson .optString (IterableConstants .KEY_MESSAGE_ID );
337
339
final Long campaignId = IterableUtil .retrieveValidCampaignIdOrNull (messageJson , IterableConstants .KEY_CAMPAIGN_ID );
340
+ boolean jsonOnly = messageJson .optBoolean (IterableConstants .ITERABLE_IN_APP_JSON_ONLY , false );
341
+
342
+ JSONObject customPayload = messageJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_CUSTOM_PAYLOAD );
343
+ if (customPayload == null && jsonOnly ) {
344
+ customPayload = new JSONObject ();
345
+ }
346
+
347
+ Content content ;
348
+ if (jsonOnly ) {
349
+ content = new Content ("" , new Rect (), 0.0 , false , new InAppDisplaySettings (false , new InAppBgColor (null , 0.0f )));
350
+ } else {
351
+ JSONObject contentJson = messageJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_CONTENT );
352
+ if (contentJson == null ) {
353
+ return null ;
354
+ }
355
+ if (customPayload == null ) {
356
+ customPayload = contentJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_LEGACY_PAYLOAD );
357
+ }
358
+
359
+ String html = contentJson .optString (IterableConstants .ITERABLE_IN_APP_HTML , null );
360
+ JSONObject inAppDisplaySettingsJson = contentJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_DISPLAY_SETTINGS );
361
+ Rect padding = getPaddingFromPayload (inAppDisplaySettingsJson );
362
+ double backgroundAlpha = contentJson .optDouble (IterableConstants .ITERABLE_IN_APP_BACKGROUND_ALPHA , 0 );
363
+ boolean shouldAnimate = inAppDisplaySettingsJson .optBoolean (IterableConstants .ITERABLE_IN_APP_SHOULD_ANIMATE , false );
364
+ JSONObject bgColorJson = inAppDisplaySettingsJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_BGCOLOR );
365
+
366
+ String bgColorInHex = null ;
367
+ double bgAlpha = 0.0f ;
368
+ if (bgColorJson != null ) {
369
+ bgColorInHex = bgColorJson .optString (IterableConstants .ITERABLE_IN_APP_BGCOLOR_HEX );
370
+ bgAlpha = bgColorJson .optDouble (IterableConstants .ITERABLE_IN_APP_BGCOLOR_ALPHA );
371
+ }
372
+
373
+ InAppDisplaySettings inAppDisplaySettings = new InAppDisplaySettings (shouldAnimate , new InAppBgColor (bgColorInHex , bgAlpha ));
374
+ content = new Content (html , padding , backgroundAlpha , shouldAnimate , inAppDisplaySettings );
375
+ }
376
+
338
377
long createdAtLong = messageJson .optLong (IterableConstants .ITERABLE_IN_APP_CREATED_AT );
339
378
Date createdAt = createdAtLong != 0 ? new Date (createdAtLong ) : null ;
340
379
long expiresAtLong = messageJson .optLong (IterableConstants .ITERABLE_IN_APP_EXPIRES_AT );
341
380
Date expiresAt = expiresAtLong != 0 ? new Date (expiresAtLong ) : null ;
342
381
343
- String html = contentJson .optString (IterableConstants .ITERABLE_IN_APP_HTML , null );
344
- JSONObject inAppDisplaySettingsJson = contentJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_DISPLAY_SETTINGS );
345
- Rect padding = getPaddingFromPayload (inAppDisplaySettingsJson );
346
- double backgroundAlpha = contentJson .optDouble (IterableConstants .ITERABLE_IN_APP_BACKGROUND_ALPHA , 0 );
347
- boolean shouldAnimate = inAppDisplaySettingsJson .optBoolean (IterableConstants .ITERABLE_IN_APP_SHOULD_ANIMATE , false );
348
- JSONObject bgColorJson = inAppDisplaySettingsJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_BGCOLOR );
349
-
350
- String bgColorInHex = null ;
351
- double bgAlpha = 0.0f ;
352
- if (bgColorJson != null ) {
353
- bgColorInHex = bgColorJson .optString (IterableConstants .ITERABLE_IN_APP_BGCOLOR_HEX );
354
- bgAlpha = bgColorJson .optDouble (IterableConstants .ITERABLE_IN_APP_BGCOLOR_ALPHA );
355
- }
356
-
357
- InAppDisplaySettings inAppDisplaySettings = new InAppDisplaySettings (shouldAnimate , new InAppBgColor (bgColorInHex , bgAlpha ));
358
382
JSONObject triggerJson = messageJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_TRIGGER );
359
383
Trigger trigger = Trigger .fromJSONObject (triggerJson );
360
- JSONObject customPayload = messageJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_CUSTOM_PAYLOAD );
361
- if (customPayload == null ) {
362
- customPayload = contentJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_LEGACY_PAYLOAD );
363
- }
364
- if (customPayload == null ) {
365
- customPayload = new JSONObject ();
366
- }
367
384
368
- double priorityLevel = messageJson .optDouble (IterableConstants .ITERABLE_IN_APP_PRIORITY_LEVEL , IterableConstants .ITERABLE_IN_APP_PRIORITY_LEVEL_UNASSIGNED );
385
+ double priorityLevel = messageJson .optDouble (IterableConstants .ITERABLE_IN_APP_PRIORITY_LEVEL ,
386
+ IterableConstants .ITERABLE_IN_APP_PRIORITY_LEVEL_UNASSIGNED );
387
+
388
+ Boolean saveToInbox = messageJson .has (IterableConstants .ITERABLE_IN_APP_SAVE_TO_INBOX ) ?
389
+ messageJson .optBoolean (IterableConstants .ITERABLE_IN_APP_SAVE_TO_INBOX ) : null ;
369
390
370
- Boolean saveToInbox = messageJson .has (IterableConstants .ITERABLE_IN_APP_SAVE_TO_INBOX ) ? messageJson .optBoolean (IterableConstants .ITERABLE_IN_APP_SAVE_TO_INBOX ) : null ;
371
391
JSONObject inboxPayloadJson = messageJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_INBOX_METADATA );
372
392
InboxMetadata inboxMetadata = InboxMetadata .fromJSONObject (inboxPayloadJson );
373
393
374
-
375
394
IterableInAppMessage message = new IterableInAppMessage (
376
395
messageId ,
377
- new Content ( html , padding , backgroundAlpha , shouldAnimate , inAppDisplaySettings ) ,
396
+ content ,
378
397
customPayload ,
379
398
createdAt ,
380
399
expiresAt ,
381
400
trigger ,
382
401
priorityLevel ,
383
402
saveToInbox ,
384
403
inboxMetadata ,
385
- campaignId );
404
+ campaignId ,
405
+ jsonOnly );
386
406
387
407
message .inAppStorageInterface = storageInterface ;
388
- if (html != null ) {
408
+ if (! jsonOnly && content . html != null && ! content . html . isEmpty () ) {
389
409
message .setLoadedHtmlFromJson (true );
390
410
}
391
411
message .processed = messageJson .optBoolean (IterableConstants .ITERABLE_IN_APP_PROCESSED , false );
@@ -410,6 +430,9 @@ JSONObject toJSONObject() {
410
430
if (expiresAt != null ) {
411
431
messageJson .putOpt (IterableConstants .ITERABLE_IN_APP_EXPIRES_AT , expiresAt .getTime ());
412
432
}
433
+ if (jsonOnly ) {
434
+ messageJson .put (IterableConstants .ITERABLE_IN_APP_JSON_ONLY , 1 );
435
+ }
413
436
414
437
messageJson .putOpt (IterableConstants .ITERABLE_IN_APP_TRIGGER , trigger .toJSONObject ());
415
438
@@ -435,7 +458,7 @@ JSONObject toJSONObject() {
435
458
messageJson .putOpt (IterableConstants .ITERABLE_IN_APP_CUSTOM_PAYLOAD , customPayload );
436
459
437
460
if (saveToInbox != null ) {
438
- messageJson .putOpt (IterableConstants .ITERABLE_IN_APP_SAVE_TO_INBOX , saveToInbox );
461
+ messageJson .putOpt (IterableConstants .ITERABLE_IN_APP_SAVE_TO_INBOX , saveToInbox && ! jsonOnly );
439
462
}
440
463
if (inboxMetadata != null ) {
441
464
messageJson .putOpt (IterableConstants .ITERABLE_IN_APP_INBOX_METADATA , inboxMetadata .toJSONObject ());
@@ -472,6 +495,9 @@ private void onChanged() {
472
495
* @return
473
496
*/
474
497
static Rect getPaddingFromPayload (JSONObject paddingOptions ) {
498
+ if (paddingOptions == null ) {
499
+ return new Rect (0 , 0 , 0 , 0 );
500
+ }
475
501
Rect rect = new Rect ();
476
502
rect .top = decodePadding (paddingOptions .optJSONObject ("top" ));
477
503
rect .left = decodePadding (paddingOptions .optJSONObject ("left" ));
@@ -529,4 +555,4 @@ static JSONObject encodePadding(int padding) throws JSONException {
529
555
}
530
556
return paddingJson ;
531
557
}
532
- }
558
+ }
0 commit comments