-
Notifications
You must be signed in to change notification settings - Fork 42
[SDK-235] Add ability to sync and get messages #797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: loren/embedded/SDK-240-ios-add-ability-to-start-and-end-a-session
Are you sure you want to change the base?
Changes from all commits
217b712
a5cf683
a9d8198
c15a057
41e080a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -507,6 +507,36 @@ import React | |
| EmbeddedSessionManager.shared.endSession() | ||
| } | ||
|
|
||
| @objc(syncEmbeddedMessages) | ||
| public func syncEmbeddedMessages() { | ||
| ITBInfo() | ||
| IterableAPI.embeddedManager.syncMessages { } | ||
| } | ||
|
|
||
| @objc(getEmbeddedMessages:resolver:rejecter:) | ||
| public func getEmbeddedMessages( | ||
| placementIds: [NSNumber]?, resolver: RCTPromiseResolveBlock, rejecter: RCTPromiseRejectBlock | ||
| ) { | ||
| ITBInfo() | ||
| var messages: [IterableEmbeddedMessage] = [] | ||
|
|
||
| if let placementIds = placementIds, !placementIds.isEmpty { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need a comment here to explain why if placementIds is nil or empty we just do IterableAPI.embeddedManager.getMessages(). Would the messages array be coherent in both cases.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be coherent for both. Added a comment regarding this, but not 100% sure if this is what you meant. Please let me know if it is not. |
||
| // Get messages for specific placement IDs | ||
| for placementId in placementIds { | ||
| let placementMessages = IterableAPI.embeddedManager.getMessages( | ||
| for: placementId.intValue | ||
| ) | ||
| messages.append(contentsOf: placementMessages) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if placementMessages is nil
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would return an empty array |
||
| } | ||
| } else { | ||
| // Get all messages from all placements | ||
| // getMessages() without parameters flattens all placement messages into a single array | ||
| messages = IterableAPI.embeddedManager.getMessages() | ||
| } | ||
|
|
||
| resolver(messages.map { $0.toDict() }) | ||
| } | ||
|
|
||
| // MARK: Private | ||
| private var shouldEmit = false | ||
| private let _methodQueue = DispatchQueue(label: String(describing: ReactIterableAPI.self)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -283,3 +283,33 @@ extension InboxImpressionTracker.RowInfo { | |
| return rows.compactMap(InboxImpressionTracker.RowInfo.from(dict:)) | ||
| } | ||
| } | ||
|
|
||
| extension IterableEmbeddedMessage { | ||
| func toDict() -> [AnyHashable: Any]? { | ||
| var dict = [AnyHashable: Any]() | ||
|
|
||
| // CRITICAL: Metadata is required - fail if missing | ||
| guard let metadataDict = SerializationUtil.encodableToDictionary(encodable: metadata) else { | ||
| ITBError("Failed to serialize embedded message metadata. Dropping invalid message.") | ||
| return nil | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if serialization fails but the metadata is partially encodable.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Updated this so that it would fail if the encoding fails so that the error isn't swallowed. |
||
| dict["metadata"] = metadataDict | ||
|
|
||
| // IMPORTANT: Elements are optional, but if present and fail to serialize, that's bad | ||
| if let elements = elements { | ||
| if let elementsDict = SerializationUtil.encodableToDictionary(encodable: elements) { | ||
| dict["elements"] = elementsDict | ||
| } else { | ||
| ITBError("Failed to serialize embedded message elements. Message will not be displayable.") | ||
| return nil | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is serialization fails but the elementsDict is partially encodable.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated this -- let me know if this works |
||
|
|
||
| // Payload doesn't need serialization - it's already a dictionary | ||
| if let payload = payload { | ||
| dict["payload"] = payload | ||
| } | ||
|
|
||
| return dict | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when syncMessages fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it would swallow it. I would love to add success/error callbacks, but unfortunately Android does not seem to expose them, so I would only be able to do so for iOS. As RN needs to have similar capabilities for both, I kind of have to forgo the error handling here as I can't seem to figure it out properly in Android.
@Ayyanchira -- please let me know if I misunderstood this!