Skip to content

Commit

Permalink
Expose Message Kind (#621)
Browse files Browse the repository at this point in the history
* cargo lock keeps changing

* set the message kind

* get it compiling correctly

* run cargo fmt to reformat it
  • Loading branch information
nplasterer authored Apr 6, 2024
1 parent c4150df commit 4068715
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use xmtp_mls::{
client::Client as MlsClient,
groups::MlsGroup,
storage::{
group_message::StoredGroupMessage, EncryptedMessageStore, EncryptionKey, StorageOption,
group_message::GroupMessageKind, group_message::StoredGroupMessage, EncryptedMessageStore,
EncryptionKey, StorageOption,
},
types::Address,
};
Expand Down Expand Up @@ -224,7 +225,10 @@ impl FfiConversations {
Ok(out)
}

pub fn process_streamed_welcome_message(&self, envelope_bytes: Vec<u8>) -> Result<Arc<FfiGroup>, GenericError> {
pub fn process_streamed_welcome_message(
&self,
envelope_bytes: Vec<u8>,
) -> Result<Arc<FfiGroup>, GenericError> {
let inner = self.inner_client.as_ref();
let group = inner.process_streamed_welcome_message(envelope_bytes)?;

Expand Down Expand Up @@ -365,23 +369,32 @@ impl FfiGroup {
);

let messages: Vec<FfiMessage> = group
.find_messages(None, opts.sent_before_ns, opts.sent_after_ns, None, opts.limit)?
.find_messages(
None,
opts.sent_before_ns,
opts.sent_after_ns,
None,
opts.limit,
)?
.into_iter()
.map(|msg| msg.into())
.collect();

Ok(messages)
}

pub async fn process_streamed_group_message(&self, envelope_bytes: Vec<u8>) -> Result<FfiMessage, GenericError> {
pub async fn process_streamed_group_message(
&self,
envelope_bytes: Vec<u8>,
) -> Result<FfiMessage, GenericError> {
let group = MlsGroup::new(
self.inner_client.as_ref(),
self.group_id.clone(),
self.created_at_ns,
);
let message = group.process_streamed_group_message(envelope_bytes).await?;
let ffi_message = message.into();

Ok(ffi_message)
}

Expand Down Expand Up @@ -484,13 +497,29 @@ impl FfiGroup {
}
}

#[derive(uniffi::Enum)]
pub enum FfiGroupMessageKind {
Application,
MembershipChange,
}

impl From<GroupMessageKind> for FfiGroupMessageKind {
fn from(kind: GroupMessageKind) -> Self {
match kind {
GroupMessageKind::Application => FfiGroupMessageKind::Application,
GroupMessageKind::MembershipChange => FfiGroupMessageKind::MembershipChange,
}
}
}

#[derive(uniffi::Record)]
pub struct FfiMessage {
pub id: Vec<u8>,
pub sent_at_ns: i64,
pub convo_id: Vec<u8>,
pub addr_from: String,
pub content: Vec<u8>,
pub kind: FfiGroupMessageKind,
}

impl From<StoredGroupMessage> for FfiMessage {
Expand All @@ -501,6 +530,7 @@ impl From<StoredGroupMessage> for FfiMessage {
convo_id: msg.group_id,
addr_from: msg.sender_account_address,
content: msg.decrypted_message_bytes,
kind: msg.kind.into(),
}
}
}
Expand Down

0 comments on commit 4068715

Please sign in to comment.