-
Notifications
You must be signed in to change notification settings - Fork 43
[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
Changes from 3 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,35 @@ 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 | ||
| 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,27 @@ extension InboxImpressionTracker.RowInfo { | |
| return rows.compactMap(InboxImpressionTracker.RowInfo.from(dict:)) | ||
| } | ||
| } | ||
|
|
||
| extension IterableEmbeddedMessage { | ||
| func toDict() -> [AnyHashable: Any] { | ||
| var dict = [AnyHashable: Any]() | ||
|
|
||
| // Serialize metadata (which is Codable) | ||
| if let metadataDict = SerializationUtil.encodableToDictionary(encodable: metadata) { | ||
| dict["metadata"] = metadataDict | ||
| } | ||
|
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. |
||
|
|
||
| // Serialize elements if present (which is Codable) | ||
| if let elements = elements, | ||
| let elementsDict = SerializationUtil.encodableToDictionary(encodable: elements) { | ||
| dict["elements"] = elementsDict | ||
| } | ||
|
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 |
||
|
|
||
| // Add payload directly | ||
| 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!