Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
codabrink committed Dec 19, 2024
1 parent 1873e99 commit e4e2e87
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion xmtp_mls/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ where
target_inbox_id: String,
) -> Result<MlsGroup<Self>, ClientError> {
let conn = self.store().conn()?;
match conn.find_dm_group(DmMembers {
match conn.find_dm_group(&DmMembers {
member_one_inbox_id: self.inbox_id(),
member_two_inbox_id: &target_inbox_id,
})? {
Expand Down
25 changes: 22 additions & 3 deletions xmtp_mls/src/groups/group_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,23 +161,42 @@ where
}
}

impl<Id> From<DmMembers<Id>> for String
impl<Id> From<&DmMembers<Id>> for String
where
Id: AsRef<str>,
{
fn from(members: DmMembers<Id>) -> Self {
let inbox_ids = [
fn from(members: &DmMembers<Id>) -> Self {
let mut inbox_ids = [
members.member_one_inbox_id.as_ref(),
members.member_two_inbox_id.as_ref(),
]
.into_iter()
.map(str::to_lowercase)
.collect::<Vec<_>>();
inbox_ids.sort();

format!("dm:{}", inbox_ids.join(":"))
}
}

impl<Id> From<DmMembers<Id>> for String
where
Id: AsRef<str>,
{
fn from(members: DmMembers<Id>) -> Self {
String::from(&members)
}
}

impl<Id> ToString for DmMembers<Id>
where
Id: AsRef<str>,
{
fn to_string(&self) -> String {
String::from(self)
}
}

impl TryFrom<DmMembersProto> for DmMembers<InboxId> {
type Error = GroupMetadataError;

Expand Down
7 changes: 3 additions & 4 deletions xmtp_mls/src/storage/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use diesel::{
};
use serde::{Deserialize, Serialize};
use xmtp_common::time::now_ns;
use xmtp_id::InboxIdRef;

pub type ID = Vec<u8>;

Expand Down Expand Up @@ -346,9 +345,9 @@ impl DbConnection {

pub fn find_dm_group(
&self,
members: DmMembers<&str>,
members: &DmMembers<&str>,
) -> Result<Option<StoredGroup>, StorageError> {
let dm_id = String::from(members.clone());
let dm_id = String::from(members);

let query = dsl::groups
.order(dsl::created_at_ns.asc())
Expand Down Expand Up @@ -745,7 +744,7 @@ pub(crate) mod tests {
// test find_dm_group

let dm_result = conn
.find_dm_group(DmMembers {
.find_dm_group(&DmMembers {
member_one_inbox_id: "placeholder_inbox_id_1",
member_two_inbox_id: "placeholder_inbox_id_2",
})
Expand Down

0 comments on commit e4e2e87

Please sign in to comment.