Skip to content
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

feat: add shouldPush to contentTypes messages #235

Closed
wants to merge 7 commits into from

Conversation

kele-leanes
Copy link
Contributor

@kele-leanes kele-leanes commented Feb 2, 2024

depends on xmtp/xmtp-ios#231 & xmtp/xmtp-android#184

closes #236

  • added shouldPush to ContentCodec type
  • added shouldPush method to Codecs
  • send and get the value from native

@kele-leanes kele-leanes self-assigned this Feb 2, 2024
@@ -13,6 +13,7 @@ struct DecodedMessageWrapper {
"senderAddress": model.senderAddress,
"sent": UInt64(model.sentAt.timeIntervalSince1970 * 1000),
"fallback": model.encodedContent.fallback,
"shouldPush": model.shouldPush
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kele-leanes I think here instead of calling model.shouldPush maybe you can copy how the test does it

		let message = try await MessageV2.encode(
			client: client,
			content: model.encodedContentt,
			topic: model.topic,
			keyMaterial: Data(model.keyMaterial),
			codec: model.encodedContent.contentType // MAP THIS TO A CODEC?
		)

then it would be message.shouldPush

Or something along these lines to get the push without having to make changes to the iOS sdk directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To do that I need to make MessageV2 and codecRegistry public and add keyMaterial to model which is not currently sent

Copy link
Contributor Author

@kele-leanes kele-leanes Feb 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and making this method async/await would add more complexity where this method is called

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no issue with MessageV2 and codecRegistry being public. @nakajima do you have any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides that, since the codec registry in RN lives on the JS side, the MessageV2.encode method can not access the codecs from RN.
e.g: If I register a custom codec, which returns true from the shouldPush method, the native side can’t get this flag.
Is the reason why I suggest sending the value encoded as in this PR or sending it as a part of a SendOption object

Copy link
Contributor Author

@kele-leanes kele-leanes Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the behavior in iOS, shouldPush is already established and calculated based on the CodecTypes existing on the iOS side. However, in React Native (RN), CodecTypes are generated and stored on the JavaScript side. Consequently, the determination of this flag should occur on the JS side and then communicated to iOS. I've devised two solutions:

  1. Include the shouldPush value as part of the EncodedContent using the proto, similar to how we currently send the fallback. This value can then be decoded and set when a MessageV2 is created. (Link to PR)

  2. Send the shouldPush value as a plain Boolean, as proposed in this PR, and include it as an optional part of the SendOption.

The latter approach deviates from the convention of maintaining methods as similar as possible across platforms.

Copy link
Contributor

@richardhuaaa richardhuaaa Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! Thanks for explaining.

So I don't think we should do (1) - it muddies the protocol, and the protos are shared across all of the platforms as well as sent over the network.

in React Native (RN), CodecTypes are generated and stored on the JavaScript side

More of a long-term question/not blocking this PR, but why is this the case? Is there a reason we can't push that down to the native platform?

The latter approach deviates from the convention of maintaining methods as similar as possible across platforms.

So the issue is that we are deriving shouldPush from the non-encoded content, however the SDK is structured so that only the encoded content is sent down today, which means iOS is unable to derive shouldPush? If so, then does that mean RN Android has the same issue and would also benefit from this?

It seems like we have no choice with the current design but to do the sendOption thing even if it's a little ugly. Another question - given the contentType is in the SendOptions already, would it be feasible to have iOS construct the codec based on the content type, and then determine the shouldPush value from that? That way we are not giving app developers a way to set shouldPush directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a long-term question/not blocking this PR, but why is this the case? Is there a reason we can't push that down to the native platform?

I'm not fully aware of the impact of this change, but the structure of a contentType has methods that you can not pass down to the native platform. This would solve our issues

Would it be feasible to have iOS construct the codec based on the content type, and then determine the shouldPush value from that?

We are not able to construct the codec since the contentType resides on the JS side. Specifically the custom ones. When the platform (in this case iOS) is trying to get the codec from a contentTypeId it searches throughout the generics codecs which are on the native side.

These changes must be added to the Android as well

Copy link
Contributor

@richardhuaaa richardhuaaa Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. In that case it seems that adding shouldPush to the SendOptions is the only way for now. Perhaps we can name it something that makes it clear that it is internal-use only, like __shouldPush or something.

Long-term, there will probably be more cases like this where the RN SDK wants some functionality from the iOS SDK that we don't actually want to expose publicly. I wonder if it makes sense to define an iOS type/interface that is internal-use only, that we don't document or provide any guarantees about publicly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved in ccceabe

@kele-leanes kele-leanes marked this pull request as ready for review February 20, 2024 23:36
@kele-leanes kele-leanes requested a review from a team as a code owner February 20, 2024 23:36
@kele-leanes kele-leanes marked this pull request as draft March 12, 2024 15:56
@kele-leanes kele-leanes closed this Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add sender HMAC to MessageV2
3 participants