Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Nov 3, 2023
1 parent d2ae87d commit de42f3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
26 changes: 14 additions & 12 deletions xmtp_mls/src/storage/encrypted_store/group_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ pub struct StoredGroupMessage {
pub enum GroupMessageKind {
Application = 1,
MemberAdded = 2,
MemberRemoved = 3
MemberRemoved = 3,
}

impl ToSql<Integer, Sqlite> for GroupMessageKind
impl ToSql<Integer, Sqlite> for GroupMessageKind
where
i32: ToSql<Integer, Sqlite>,
{
Expand All @@ -51,7 +51,7 @@ where
}
}

impl FromSql<Integer, Sqlite> for GroupMessageKind
impl FromSql<Integer, Sqlite> for GroupMessageKind
where
i32: FromSql<Integer, Sqlite>,
{
Expand All @@ -68,9 +68,7 @@ where
impl_fetch!(StoredGroupMessage, group_messages, Vec<u8>);
impl_store!(StoredGroupMessage, group_messages);


impl EncryptedMessageStore {

/// Query for group messages
pub fn get_group_messages(
&self,
Expand All @@ -81,7 +79,7 @@ impl EncryptedMessageStore {
kind: Option<i32>,
) -> Result<Vec<StoredGroupMessage>, StorageError> {
use super::schema::group_messages::dsl;

let mut query = dsl::group_messages
.filter(dsl::group_id.eq(group_id))
.into_boxed();
Expand All @@ -99,30 +97,34 @@ impl EncryptedMessageStore {
}
Ok(query.load::<StoredGroupMessage>(conn)?)
}

/// Get a particular group message
pub fn get_group_message(
&self,
id: &[u8],
conn: &mut DbConnection,
) -> Result<Option<StoredGroupMessage>, StorageError> {
use super::schema::group_messages::dsl;
Ok(dsl::group_messages.filter(dsl::id.eq(id)).first(conn).optional()?)
Ok(dsl::group_messages
.filter(dsl::id.eq(id))
.first(conn)
.optional()?)
}
}

#[cfg(test)]
mod tests {
use super::*;
use rand::Rng;

use super::*;
use crate::{
storage::encrypted_store::{schema::groups::dsl::groups, tests::with_store},
Fetch, Store,
};

fn rand_bytes(length: usize) -> Vec<u8> {
(0..length).map(|_| { rand::random::<u8>() }).collect()
}
(0..length).map(|_| rand::random::<u8>()).collect()
}

fn generate_message(kind: Option<GroupMessageKind>) -> StoredGroupMessage {
let mut rng = rand::thread_rng();
Expand All @@ -148,7 +150,7 @@ mod tests {
assert!(matches!(store.get_group_message(&id, &mut conn), Ok(_)));
})
}

#[test]
fn it_gets_messages() {
with_store(|store, conn| {
Expand Down
1 change: 0 additions & 1 deletion xmtp_mls/src/storage/encrypted_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ macro_rules! impl_store {
};
}


#[cfg(test)]
mod tests {
use std::{boxed::Box, fs};
Expand Down

0 comments on commit de42f3a

Please sign in to comment.