Skip to content

Commit

Permalink
fix group membership enum
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Nov 2, 2023
1 parent 7c960f4 commit a6145ee
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 26 deletions.
99 changes: 98 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions xmtp_mls/src/storage/encrypted_store/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::schema::groups;
use crate::impl_fetch_and_store;
use diesel::prelude::*;
use diesel::{backend::Backend, sqlite::Sqlite, serialize::{self, Output, ToSql, IsNull}, deserialize::{self, FromSql}, sql_types::Integer, expression::AsExpression};
use diesel::{backend::Backend, sqlite::Sqlite, serialize::{self, Output, ToSql, IsNull}, deserialize::{self, FromSql, FromSqlRow}, sql_types::Integer, expression::AsExpression};

/// The Group ID type.
pub type ID = Vec<u8>;
Expand All @@ -18,21 +18,21 @@ pub struct StoredGroup {
/// based on timestamp of this welcome message
pub created_at_ns: i64,
/// enum, [`GroupMembershipState`] representing access to the group.
pub membership_state: i32,
pub membership_state: GroupMembershipState,
}

impl_fetch_and_store!(StoredGroup, groups, Vec<u8>);

impl StoredGroup {
pub fn new(id: ID, created_at_ns: i64, membership_state: GroupMembershipState) -> Self {
Self {
id, created_at_ns, membership_state: membership_state as i32
id, created_at_ns, membership_state: membership_state

Check warning on line 29 in xmtp_mls/src/storage/encrypted_store/group.rs

View workflow job for this annotation

GitHub Actions / workspace

redundant field names in struct initialization

warning: redundant field names in struct initialization --> xmtp_mls/src/storage/encrypted_store/group.rs:29:32 | 29 | id, created_at_ns, membership_state: membership_state | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `membership_state` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names = note: `#[warn(clippy::redundant_field_names)]` on by default
}
}
}

#[repr(i32)]
#[derive(Debug, Clone, Copy, AsExpression)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, AsExpression, FromSqlRow)]
#[diesel(sql_type = Integer)]
/// Status of membership in a group, once a user sends a request to join
pub enum GroupMembershipState {
Expand Down Expand Up @@ -113,7 +113,7 @@ mod tests {

test_group.store(&mut conn).unwrap();
let updated_group = store.update_group_membership(&mut conn, id, GroupMembershipState::Rejected).unwrap();
assert_eq!(updated_group, StoredGroup { membership_state: GroupMembershipState::Rejected as i32, ..test_group });
assert_eq!(updated_group, StoredGroup { membership_state: GroupMembershipState::Rejected, ..test_group });
})
}
}
5 changes: 3 additions & 2 deletions xmtp_mls/src/storage/encrypted_store/group_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use diesel::prelude::*;
pub struct StoredGroupIntent {
pub id: i32,
pub kind: i32,
pub state: i32,
pub group_id: Vec<u8>,
pub data: Vec<u8>,
pub state: i32,
pub payload_hash: Option<Vec<u8>>,
pub post_commit_data: Option<Vec<u8>>,
}
Expand All @@ -18,7 +18,8 @@ pub struct StoredGroupIntent {
#[diesel(table_name = group_intents)]
pub struct NewGroupIntent {
pub kind: i32,
pub state: i32,
pub group_id: Vec<u8>,
pub data: Vec<u8>,
pub state: i32,
}

2 changes: 2 additions & 0 deletions xmtp_mls/src/storage/encrypted_store/group_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub struct StoredGroupMessage {
pub decrypted_message_bytes: Vec<u8>,
/// Time in nanoseconds the message was sent.
pub sent_at_ns: i64,
/// Group Message Kind Enum
pub kind: i32,
/// The ID of the App Installation this message was sent from.
pub sender_installation_id: Vec<u8>,
/// Network wallet address of the Sender
Expand Down
21 changes: 3 additions & 18 deletions xmtp_mls/src/storage/encrypted_store/key_store_entry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::DbConnection;
use super::{schema::openmls_key_store, StorageError};
use crate::{Delete, Fetch, Store};
use crate::impl_fetch_and_store;
use crate::Delete;
use diesel::prelude::*;

#[derive(Insertable, Queryable, Debug, Clone)]
Expand All @@ -11,23 +12,7 @@ pub struct StoredKeyStoreEntry {
pub value_bytes: Vec<u8>,
}

impl Store<DbConnection> for StoredKeyStoreEntry {
fn store(&self, into: &mut DbConnection) -> Result<(), StorageError> {
diesel::insert_into(openmls_key_store::table)
.values(self)
.execute(into)?;

Ok(())
}
}

impl Fetch<StoredKeyStoreEntry> for DbConnection {
type Key = Vec<u8>;
fn fetch(&mut self, key: Vec<u8>) -> Result<Option<StoredKeyStoreEntry>, StorageError> where {
use super::schema::openmls_key_store::dsl::*;
Ok(openmls_key_store.find(key).first(self).optional()?)
}
}
impl_fetch_and_store!(StoredKeyStoreEntry, openmls_key_store, Vec<u8>);

impl Delete<StoredKeyStoreEntry> for DbConnection {
type Key = Vec<u8>;
Expand Down

0 comments on commit a6145ee

Please sign in to comment.