Skip to content

Commit

Permalink
the rest of the implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
codabrink committed Dec 16, 2024
1 parent 7ad6163 commit 6ae1179
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use xmtp_id::{
},
InboxId,
};
use xmtp_mls::groups::device_sync::preference_sync::UserPreferenceUpdate;
use xmtp_mls::groups::scoped_client::LocalScopedGroupClient;
use xmtp_mls::groups::HmacKey;
use xmtp_mls::storage::group::ConversationType;
Expand Down Expand Up @@ -1088,13 +1089,15 @@ impl FfiConversations {
&self,
callback: Arc<dyn FfiPreferenceCallback>,
) -> FfiStreamCloser {
let handle =
RustXmtpClient::stream_consent_with_callback(self.inner_client.clone(), move |msg| {
match msg {
Ok(m) => callback.on_preference_update(m.into_iter().map(Into::into).collect()),
Err(e) => callback.on_error(e.into()),
}
});
let handle = RustXmtpClient::stream_preferences_with_callback(
self.inner_client.clone(),
move |msg| match msg {
Ok(m) => callback.on_preference_update(
m.into_iter().filter_map(|v| v.try_into().ok()).collect(),
),
Err(e) => callback.on_error(e.into()),
},
);

FfiStreamCloser::new(handle)
}
Expand All @@ -1110,6 +1113,20 @@ impl From<FfiConversationType> for ConversationType {
}
}

impl TryFrom<UserPreferenceUpdate> for FfiPreferenceUpdate {
type Error = GenericError;
fn try_from(value: UserPreferenceUpdate) -> Result<Self, Self::Error> {
match value {
UserPreferenceUpdate::HmacKeyUpdate { key } => Ok(FfiPreferenceUpdate::HMAC { key }),
// These are filtered out in the stream and should not be here
// We're keeping preference update and consent streams separate right now.
UserPreferenceUpdate::ConsentUpdate(_) => Err(GenericError::Generic {
err: "Consent updates should be filtered out.".to_string(),
}),
}
}
}

#[derive(uniffi::Object)]
pub struct FfiConversation {
inner: MlsGroup<RustXmtpClient>,
Expand Down

0 comments on commit 6ae1179

Please sign in to comment.