7
7
import androidx .annotation .RestrictTo ;
8
8
import androidx .core .util .ObjectsCompat ;
9
9
10
- import org .json .JSONArray ;
11
10
import org .json .JSONException ;
12
11
import org .json .JSONObject ;
13
12
@@ -24,13 +23,23 @@ public class IterableInAppMessage {
24
23
private final @ NonNull Trigger trigger ;
25
24
private final @ Nullable Boolean saveToInbox ;
26
25
private final @ Nullable InboxMetadata inboxMetadata ;
26
+ private final @ Nullable Long campaignId ;
27
27
private boolean processed = false ;
28
28
private boolean consumed = false ;
29
29
private boolean read = false ;
30
30
private boolean loadedHtmlFromJson = false ;
31
31
private @ Nullable IterableInAppStorage inAppStorageInterface ;
32
32
33
- IterableInAppMessage (@ NonNull String messageId , @ NonNull Content content , @ NonNull JSONObject customPayload , @ NonNull Date createdAt , @ NonNull Date expiresAt , @ NonNull Trigger trigger , @ Nullable Boolean saveToInbox , @ Nullable InboxMetadata inboxMetadata ) {
33
+ IterableInAppMessage (@ NonNull String messageId ,
34
+ @ NonNull Content content ,
35
+ @ NonNull JSONObject customPayload ,
36
+ @ NonNull Date createdAt ,
37
+ @ NonNull Date expiresAt ,
38
+ @ NonNull Trigger trigger ,
39
+ @ Nullable Boolean saveToInbox ,
40
+ @ Nullable InboxMetadata inboxMetadata ,
41
+ @ Nullable Long campaignId ) {
42
+
34
43
this .messageId = messageId ;
35
44
this .content = content ;
36
45
this .customPayload = customPayload ;
@@ -39,6 +48,7 @@ public class IterableInAppMessage {
39
48
this .trigger = trigger ;
40
49
this .saveToInbox = saveToInbox ;
41
50
this .inboxMetadata = inboxMetadata ;
51
+ this .campaignId = campaignId ;
42
52
}
43
53
44
54
static class Trigger {
@@ -193,6 +203,11 @@ public String getMessageId() {
193
203
return messageId ;
194
204
}
195
205
206
+ @ Nullable
207
+ public Long getCampaignId () {
208
+ return campaignId ;
209
+ }
210
+
196
211
@ NonNull
197
212
public Date getCreatedAt () {
198
213
return createdAt ;
@@ -281,6 +296,7 @@ static IterableInAppMessage fromJSONObject(@NonNull JSONObject messageJson, @Nul
281
296
}
282
297
283
298
String messageId = messageJson .optString (IterableConstants .KEY_MESSAGE_ID );
299
+ final Long campaignId = IterableUtil .retrieveValidCampaignIdOrNull (messageJson , IterableConstants .KEY_CAMPAIGN_ID );
284
300
long createdAtLong = messageJson .optLong (IterableConstants .ITERABLE_IN_APP_CREATED_AT );
285
301
Date createdAt = createdAtLong != 0 ? new Date (createdAtLong ) : null ;
286
302
long expiresAtLong = messageJson .optLong (IterableConstants .ITERABLE_IN_APP_EXPIRES_AT );
@@ -306,8 +322,17 @@ static IterableInAppMessage fromJSONObject(@NonNull JSONObject messageJson, @Nul
306
322
JSONObject inboxPayloadJson = messageJson .optJSONObject (IterableConstants .ITERABLE_IN_APP_INBOX_METADATA );
307
323
InboxMetadata inboxMetadata = InboxMetadata .fromJSONObject (inboxPayloadJson );
308
324
309
- IterableInAppMessage message = new IterableInAppMessage (messageId ,
310
- new Content (html , padding , backgroundAlpha ), customPayload , createdAt , expiresAt , trigger , saveToInbox , inboxMetadata );
325
+ IterableInAppMessage message = new IterableInAppMessage (
326
+ messageId ,
327
+ new Content (html , padding , backgroundAlpha ),
328
+ customPayload ,
329
+ createdAt ,
330
+ expiresAt ,
331
+ trigger ,
332
+ saveToInbox ,
333
+ inboxMetadata ,
334
+ campaignId );
335
+
311
336
message .inAppStorageInterface = storageInterface ;
312
337
if (html != null ) {
313
338
message .setLoadedHtmlFromJson (true );
@@ -324,6 +349,9 @@ JSONObject toJSONObject() {
324
349
JSONObject contentJson = new JSONObject ();
325
350
try {
326
351
messageJson .putOpt (IterableConstants .KEY_MESSAGE_ID , messageId );
352
+ if (campaignId != null && IterableUtil .isValidCampaignId (campaignId )) {
353
+ messageJson .put (IterableConstants .KEY_CAMPAIGN_ID , campaignId );
354
+ }
327
355
if (createdAt != null ) {
328
356
messageJson .putOpt (IterableConstants .ITERABLE_IN_APP_CREATED_AT , createdAt .getTime ());
329
357
}
0 commit comments