-
Notifications
You must be signed in to change notification settings - Fork 19
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: support prepareMessage and sendPreparedMessage #100
Conversation
const prepared = await bobConversation.prepareMessage("hi"); | ||
|
||
// Either of these should work: | ||
await bobConversation.sendPreparedMessage(prepared); | ||
// await bob.sendPreparedMessage(prepared); |
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.
This is the expected typical scenario for JS-only apps -- calling .prepareMessage
immediately upon user input and then attempting .sendPreparedMessage
(or waiting to (re)try when connectivity resumes).
// For native integrations (e.g. if you have native code for a robust | ||
// pending-message queue in a background task) you can load the referenced | ||
// `preparedFileUri` as a serialized `PreparedMessage` with the native SDKs. | ||
// The contained `envelopes` can then be directly `.publish()`ed with the native `Client`. | ||
// e.g. on iOS: | ||
// let preparedFileUrl = URL(string: preparedFileUri) | ||
// let preparedData = try Data(contentsOf: preparedFileUrl) | ||
// let prepared = try PreparedMessage.fromSerializedData(preparedData) | ||
// try await client.publish(envelopes: prepared.envelopes) | ||
// e.g. on Android: | ||
// val preparedFileUri = Uri.parse(preparedFileUri) | ||
// val preparedData = contentResolver.openInputStream(preparedFileUrl)!! | ||
// .use { it.buffered().readBytes() } | ||
// val prepared = PreparedMessage.fromSerializedData(preparedData) | ||
// client.publish(envelopes = prepared.envelopes) | ||
// | ||
// You can also stuff the `preparedData` elsewhere (e.g. in a database) if that | ||
// is more convenient for your use case. |
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.
Some apps implement a native background task for robust pending-message queues (e.g. to gracefully handle outages and restarts outside of a JS context). Here are some pieces of a recipe to handle publishing these prepared messages using the native SDKs.
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.
Thanks for all the extra context added in here! Looks good.
🎉 This PR is included in version 1.12.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This adds support for
.preparedMessage()
to the SDK with a specific eye toward supporting robust pending-message queues.This fixes #82
See also xmtp/xmtp-ios#152 and xmtp/xmtp-android#113