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

Change stream methods to async fn in uniffi #912

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ impl FfiConversations {
Ok(convo_list)
}

pub fn stream(&self, callback: Box<dyn FfiConversationCallback>) -> FfiStreamCloser {
pub async fn stream(&self, callback: Box<dyn FfiConversationCallback>) -> FfiStreamCloser {
let client = self.inner_client.clone();
let handle =
RustXmtpClient::stream_conversations_with_callback(client.clone(), move |convo| {
Expand All @@ -629,7 +629,7 @@ impl FfiConversations {
FfiStreamCloser::new(handle)
}

pub fn stream_all_messages(
pub async fn stream_all_messages(
&self,
message_callback: Box<dyn FfiMessageCallback>,
) -> FfiStreamCloser {
Expand Down Expand Up @@ -1117,7 +1117,7 @@ impl FfiGroup {
Ok(())
}

pub fn stream(&self, message_callback: Box<dyn FfiMessageCallback>) -> FfiStreamCloser {
pub async fn stream(&self, message_callback: Box<dyn FfiMessageCallback>) -> FfiStreamCloser {
let inner_client = Arc::clone(&self.inner_client);
let handle = MlsGroup::stream_with_callback(
inner_client,
Expand Down Expand Up @@ -1266,7 +1266,7 @@ impl FfiStreamCloser {
}
}

#[uniffi::export]
#[uniffi::export(async_runtime = "tokio")]
impl FfiStreamCloser {
/// Signal the stream to end
/// Does not wait for the stream to end.
Expand Down Expand Up @@ -2010,7 +2010,8 @@ mod tests {
let message_callbacks = RustStreamCallback::default();
let stream_messages = bo
.conversations()
.stream_all_messages(Box::new(message_callbacks.clone()));
.stream_all_messages(Box::new(message_callbacks.clone()))
.await;
stream_messages.wait_for_ready().await;

// Create group and send first message
Expand Down Expand Up @@ -2067,7 +2068,8 @@ mod tests {
let message_callbacks = RustStreamCallback::default();
let stream_messages = bo
.conversations()
.stream_all_messages(Box::new(message_callbacks.clone()));
.stream_all_messages(Box::new(message_callbacks.clone()))
.await;
stream_messages.wait_for_ready().await;

let first_msg_check = 2;
Expand Down Expand Up @@ -2140,7 +2142,8 @@ mod tests {

let stream = bola
.conversations()
.stream(Box::new(stream_callback.clone()));
.stream(Box::new(stream_callback.clone()))
.await;

amal.conversations()
.create_group(
Expand Down Expand Up @@ -2188,7 +2191,8 @@ mod tests {

let stream = caro
.conversations()
.stream_all_messages(Box::new(stream_callback.clone()));
.stream_all_messages(Box::new(stream_callback.clone()))
.await;
stream.wait_for_ready().await;

alix_group.send("first".as_bytes().to_vec()).await.unwrap();
Expand Down Expand Up @@ -2234,7 +2238,7 @@ mod tests {
let bola_group = bola.group(amal_group.group_id.clone()).unwrap();

let stream_callback = RustStreamCallback::default();
let stream_closer = bola_group.stream(Box::new(stream_callback.clone()));
let stream_closer = bola_group.stream(Box::new(stream_callback.clone())).await;

stream_closer.wait_for_ready().await;

Expand Down Expand Up @@ -2273,7 +2277,8 @@ mod tests {
let stream_callback = RustStreamCallback::default();
let stream_closer = bola
.conversations()
.stream_all_messages(Box::new(stream_callback.clone()));
.stream_all_messages(Box::new(stream_callback.clone()))
.await;
stream_closer.wait_for_ready().await;

amal_group.send(b"hello1".to_vec()).await.unwrap();
Expand Down Expand Up @@ -2368,11 +2373,15 @@ mod tests {
// Stream all group messages
let message_callback = RustStreamCallback::default();
let group_callback = RustStreamCallback::default();
let stream_groups = bo.conversations().stream(Box::new(group_callback.clone()));
let stream_groups = bo
.conversations()
.stream(Box::new(group_callback.clone()))
.await;

let stream_messages = bo
.conversations()
.stream_all_messages(Box::new(message_callback.clone()));
.stream_all_messages(Box::new(message_callback.clone()))
.await;
stream_messages.wait_for_ready().await;

// Create group and send first message
Expand Down
Loading