Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 8 additions & 10 deletions bindings_ffi/src/mls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,7 @@ impl FfiConversation {
) -> Result<Vec<FfiMessage>, GenericError> {
let delivery_status = opts.delivery_status.map(|status| status.into());
let direction = opts.direction.map(|dir| dir.into());
let kind = match self.conversation_type().await? {
let kind = match self.conversation_type() {
FfiConversationType::Group => None,
FfiConversationType::Dm => None,
FfiConversationType::Sync => None,
Expand All @@ -2079,13 +2079,13 @@ impl FfiConversation {
Ok(messages)
}

pub async fn find_messages_with_reactions(
pub fn find_messages_with_reactions(
&self,
opts: FfiListMessagesOptions,
) -> Result<Vec<FfiMessageWithReactions>, GenericError> {
let delivery_status = opts.delivery_status.map(|status| status.into());
let direction = opts.direction.map(|dir| dir.into());
let kind = match self.conversation_type().await? {
let kind = match self.conversation_type() {
FfiConversationType::Group => None,
FfiConversationType::Dm => None,
FfiConversationType::Sync => None,
Expand Down Expand Up @@ -2437,11 +2437,6 @@ impl FfiConversation {
Ok(hmac_map)
}

pub async fn conversation_type(&self) -> Result<FfiConversationType, GenericError> {
let conversation_type = self.inner.conversation_type().await?;
Ok(conversation_type.into())
}

pub async fn conversation_debug_info(&self) -> Result<FfiConversationDebugInfo, GenericError> {
let debug_info = self.inner.debug_info().await?;
Ok(debug_info.into())
Expand All @@ -2462,6 +2457,10 @@ impl FfiConversation {
pub fn id(&self) -> Vec<u8> {
self.inner.group_id.clone()
}

pub fn conversation_type(&self) -> FfiConversationType {
self.inner.conversation_type.into()
}
}

#[derive(uniffi::Enum, PartialEq, Debug, Clone)]
Expand All @@ -2479,7 +2478,7 @@ impl From<GroupMessageKind> for FfiConversationMessageKind {
}
}

#[derive(uniffi::Enum, PartialEq, Debug)]
#[derive(uniffi::Enum, PartialEq, Debug, Clone)]
pub enum FfiConversationType {
Group,
Dm,
Expand Down Expand Up @@ -7764,7 +7763,6 @@ mod tests {
// Test find_messages_with_reactions query
let messages_with_reactions: Vec<FfiMessageWithReactions> = alix_conversation
.find_messages_with_reactions(FfiListMessagesOptions::default())
.await
.unwrap();
assert_eq!(messages_with_reactions.len(), 2);
let message_with_reactions = &messages_with_reactions[1];
Expand Down
1 change: 1 addition & 0 deletions bindings_node/src/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ impl Conversation {
self.inner_group.context.clone(),
self.group_id.clone(),
self.dm_id.clone(),
self.inner_group.conversation_type,
self.created_at_ns,
)
}
Expand Down
1 change: 1 addition & 0 deletions bindings_wasm/src/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl Conversation {
self.inner_group.context.clone(),
self.group_id.clone(),
self.dm_id.clone(),
self.inner_group.conversation_type,
self.created_at_ns,
)
}
Expand Down
16 changes: 16 additions & 0 deletions xmtp_db/src/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ pub trait QueryGroup<C: ConnectionExt> {

/// Get conversation IDs for all conversations that require a remote commit log publish (DMs and groups where user is super admin, excluding sync groups)
fn get_conversation_ids_for_remote_log(&self) -> Result<Vec<Vec<u8>>, crate::ConnectionError>;

fn get_conversation_type(
&self,
group_id: &[u8],
) -> Result<ConversationType, crate::ConnectionError>;
}

impl<C: ConnectionExt> QueryGroup<C> for DbConnection<C> {
Expand Down Expand Up @@ -662,6 +667,17 @@ impl<C: ConnectionExt> QueryGroup<C> for DbConnection<C> {

self.raw_query_read(|conn| query.load::<Vec<u8>>(conn))
}

fn get_conversation_type(
&self,
group_id: &[u8],
) -> Result<ConversationType, crate::ConnectionError> {
let query = dsl::groups
.filter(dsl::id.eq(group_id))
.select(dsl::conversation_type);
let conversation_type = self.raw_query_read(|conn| query.first(conn))?;
Ok(conversation_type)
}
}

#[repr(i32)]
Expand Down
2 changes: 2 additions & 0 deletions xmtp_db/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::group::ConversationType;
use crate::local_commit_log::LocalCommitLog;
use std::sync::{
Arc,
Expand Down Expand Up @@ -225,6 +226,7 @@ mock! {

fn has_duplicate_dm(&self, group_id: &[u8]) -> Result<bool, crate::ConnectionError>;
fn get_conversation_ids_for_remote_log(&self) -> Result<Vec<Vec<u8>>, crate::ConnectionError>;
fn get_conversation_type(&self, group_id: &[u8]) -> Result<ConversationType, crate::ConnectionError>;
}

impl<C: ConnectionExt + 'static> QueryGroupVersion<C> for DbQuery<C> {
Expand Down
24 changes: 22 additions & 2 deletions xmtp_mls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ where
let group: MlsGroup<Context> = MlsGroup::create_and_insert(
self.context.clone(),
GroupMembershipState::Allowed,
ConversationType::Group,
permissions_policy_set.unwrap_or_default(),
opts.unwrap_or_default(),
)?;
Expand Down Expand Up @@ -550,6 +551,7 @@ where
self.context.clone(),
group.id,
group.dm_id,
group.conversation_type,
group.created_at_ns,
));
}
Expand All @@ -574,7 +576,15 @@ where
let conn = self.context.db();
let stored_group = conn.fetch_stitched(group_id)?;
stored_group
.map(|g| MlsGroup::new(self.context.clone(), g.id, g.dm_id, g.created_at_ns))
.map(|g| {
MlsGroup::new(
self.context.clone(),
g.id,
g.dm_id,
g.conversation_type,
g.created_at_ns,
)
})
.ok_or(NotFound::GroupById(group_id.to_vec()))
.map_err(Into::into)
}
Expand Down Expand Up @@ -621,6 +631,7 @@ where
self.context.clone(),
group.id,
group.dm_id,
group.conversation_type,
group.created_at_ns,
))
}
Expand Down Expand Up @@ -687,6 +698,7 @@ where
self.context.clone(),
conversation_item.id,
conversation_item.dm_id,
conversation_item.conversation_type,
conversation_item.created_at_ns,
),
last_message: message,
Expand Down Expand Up @@ -788,7 +800,15 @@ where
.db()
.all_sync_groups()?
.into_iter()
.map(|g| MlsGroup::new(self.context.clone(), g.id, g.dm_id, g.created_at_ns))
.map(|g| {
MlsGroup::new(
self.context.clone(),
g.id,
g.dm_id,
g.conversation_type,
g.created_at_ns,
)
})
.collect();
let active_groups_count = self.sync_all_groups(groups).await?;

Expand Down
1 change: 1 addition & 0 deletions xmtp_mls/src/groups/mls_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ where
self.context.clone(),
other_dm.id,
other_dm.dm_id.clone(),
other_dm.conversation_type,
other_dm.created_at_ns,
);
other_dm.sync_with_conn().await?;
Expand Down
49 changes: 43 additions & 6 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const MAX_GROUP_IMAGE_URL_LENGTH: usize = 2048;
pub struct MlsGroup<Context> {
pub group_id: Vec<u8>,
pub dm_id: Option<String>,
pub conversation_type: ConversationType,
pub created_at_ns: i64,
pub context: Context,
mls_commit_lock: Arc<GroupCommitLock>,
Expand Down Expand Up @@ -156,6 +157,7 @@ impl<Context: XmtpSharedContext> Clone for MlsGroup<Context> {
Self {
group_id: self.group_id.clone(),
dm_id: self.dm_id.clone(),
conversation_type: self.conversation_type,
created_at_ns: self.created_at_ns,
context: self.context.clone(),
mutex: self.mutex.clone(),
Expand Down Expand Up @@ -247,9 +249,16 @@ where
context: Context,
group_id: Vec<u8>,
dm_id: Option<String>,
conversation_type: ConversationType,
created_at_ns: i64,
) -> Self {
Self::new_from_arc(context.clone(), group_id, dm_id, created_at_ns)
Self::new_from_arc(
context.clone(),
group_id,
dm_id,
conversation_type,
created_at_ns,
)
}

/// Creates a new group instance from the database. Validate that the group exists in the DB before constructing
Expand All @@ -269,6 +278,7 @@ where
context,
group_id.to_vec(),
group.dm_id.clone(),
ConversationType::Group,
group.created_at_ns,
),
group,
Expand All @@ -283,12 +293,14 @@ where
context: Context,
group_id: Vec<u8>,
dm_id: Option<String>,
conversation_type: ConversationType,
created_at_ns: i64,
) -> Self {
let mut mutexes = context.mutexes().clone();
Self {
group_id: group_id.clone(),
dm_id,
conversation_type,
created_at_ns,
mutex: mutexes.get_mutex(group_id),
context: context.clone(),
Expand Down Expand Up @@ -359,6 +371,7 @@ where
pub(crate) fn create_and_insert(
context: Context,
membership_state: GroupMembershipState,
conversation_type: ConversationType,
permissions_policy_set: PolicySet,
opts: GroupMetadataOptions,
) -> Result<Self, GroupError> {
Expand All @@ -373,6 +386,7 @@ where
context.clone(),
stored_group.id,
stored_group.dm_id,
conversation_type,
stored_group.created_at_ns,
);

Expand Down Expand Up @@ -498,6 +512,7 @@ where
context.clone(),
group_id.clone(),
stored_group.dm_id,
ConversationType::Dm,
stored_group.created_at_ns,
);
// Consent state defaults to allowed when the user creates the group
Expand Down Expand Up @@ -535,7 +550,13 @@ where
.ok_or(GroupError::NotFound(NotFound::GroupByWelcome(
welcome.id as i64,
)))?;
let group = Self::new(context, group.id, group.dm_id, group.created_at_ns);
let group = Self::new(
context,
group.id,
group.dm_id,
group.conversation_type,
group.created_at_ns,
);

tracing::warn!("Skipping old welcome {}", welcome.id);
return Ok(group);
Expand Down Expand Up @@ -791,6 +812,7 @@ where
context.clone(),
stored_group.id,
stored_group.dm_id,
stored_group.conversation_type,
stored_group.created_at_ns,
);

Expand Down Expand Up @@ -846,7 +868,13 @@ where
GroupMembershipState::Allowed,
)?;

let group = Self::new_from_arc(context, stored_group.id, None, stored_group.created_at_ns);
let group = Self::new_from_arc(
context,
stored_group.id,
None,
ConversationType::Sync,
stored_group.created_at_ns,
);

Ok(group)
}
Expand Down Expand Up @@ -1454,8 +1482,8 @@ where

/// Retrieves the conversation type of the group from the group's metadata extension.
pub async fn conversation_type(&self) -> Result<ConversationType, GroupError> {
let metadata = self.metadata().await?;
Ok(metadata.conversation_type)
let conversation_type = self.context.db().get_conversation_type(&self.group_id)?;
Ok(conversation_type)
}

/// Updates the admin list of the group and syncs the changes to the network.
Expand Down Expand Up @@ -1666,7 +1694,15 @@ where

let mls_groups = duplicates
.into_iter()
.map(|g| MlsGroup::new(self.context.clone(), g.id, g.dm_id, g.created_at_ns))
.map(|g| {
MlsGroup::new(
self.context.clone(),
g.id,
g.dm_id,
g.conversation_type,
g.created_at_ns,
)
})
.collect();

Ok(mls_groups)
Expand Down Expand Up @@ -1734,6 +1770,7 @@ where
context,
group_id,
stored_group.dm_id.clone(),
ConversationType::Dm,
stored_group.created_at_ns,
))
}
Expand Down
1 change: 1 addition & 0 deletions xmtp_mls/src/groups/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,7 @@ async fn test_removed_members_cannot_send_message_to_others() {
bola.context.clone(),
amal_group.group_id.clone(),
amal_group.dm_id.clone(),
amal_group.conversation_type,
amal_group.created_at_ns,
);
bola_group
Expand Down
20 changes: 18 additions & 2 deletions xmtp_mls/src/groups/welcome_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,15 @@ where
let groups = db
.all_sync_groups()?
.into_iter()
.map(|g| MlsGroup::new(self.context.clone(), g.id, g.dm_id, g.created_at_ns))
.map(|g| {
MlsGroup::new(
self.context.clone(),
g.id,
g.dm_id,
g.conversation_type,
g.created_at_ns,
)
})
.collect();
let active_groups_count = self.sync_all_groups(groups).await?;

Expand Down Expand Up @@ -180,7 +188,15 @@ where

let groups: Vec<MlsGroup<Context>> = conversations
.into_iter()
.map(|c| MlsGroup::new(self.context.clone(), c.id, c.dm_id, c.created_at_ns))
.map(|c| {
MlsGroup::new(
self.context.clone(),
c.id,
c.dm_id,
c.conversation_type,
c.created_at_ns,
)
})
.collect();

let success_count = self.sync_groups_in_batches(groups, 10).await?;
Expand Down
Loading
Loading