Skip to content

Commit

Permalink
added new update metadata intent type, updated proto
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Mar 29, 2024
1 parent fd44c19 commit b06e152
Show file tree
Hide file tree
Showing 7 changed files with 755 additions and 315 deletions.
53 changes: 52 additions & 1 deletion xmtp_mls/src/groups/intents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ use xmtp_proto::xmtp::mls::database::{
SendWelcomes as SendWelcomesProto,
},
remove_members_data::{Version as RemoveMembersVersion, V1 as RemoveMembersV1},
update_metadata_data::{Version as UpdateMetadataVersion, V1 as UpdateMetadataV1},
send_message_data::{Version as SendMessageVersion, V1 as SendMessageV1},
AccountAddresses, AddMembersData,
AddressesOrInstallationIds as AddressesOrInstallationIdsProtoWrapper, InstallationIds,
PostCommitAction as PostCommitActionProto, RemoveMembersData, SendMessageData,
PostCommitAction as PostCommitActionProto, RemoveMembersData, SendMessageData, UpdateMetadataData,
};

use crate::{
Expand Down Expand Up @@ -220,6 +221,56 @@ impl From<RemoveMembersIntentData> for Vec<u8> {
}
}

#[derive(Debug, Clone)]
pub struct UpdateMetadataIntentData {
pub group_name: String,
pub allow_list_account_addresses: AccountAddresses,
}

impl UpdateMetadataIntentData {
pub fn new(group_name: String, allow_list_account_addresses: AccountAddresses) -> Self {
Self { group_name, allow_list_account_addresses }
}

pub(crate) fn to_bytes(&self) -> Vec<u8> {
let mut buf = Vec::new();

UpdateMetadataData {
version: Some(UpdateMetadataVersion::V1(UpdateMetadataV1 {
group_name: self.group_name.clone(),
allow_list_account_addresses: Some(self.allow_list_account_addresses.clone().into()),

Check warning on line 241 in xmtp_mls/src/groups/intents.rs

View workflow job for this annotation

GitHub Actions / workspace

useless conversion to the same type: `xmtp_proto::xmtp::mls::database::AccountAddresses`

warning: useless conversion to the same type: `xmtp_proto::xmtp::mls::database::AccountAddresses` --> xmtp_mls/src/groups/intents.rs:241:52 | 241 | allow_list_account_addresses: Some(self.allow_list_account_addresses.clone().into()), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `self.allow_list_account_addresses.clone()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion = note: `#[warn(clippy::useless_conversion)]` on by default
})),
}
.encode(&mut buf)
.expect("encode error");

buf
}

pub(crate) fn from_bytes(data: &[u8]) -> Result<Self, IntentError> {

Check warning on line 250 in xmtp_mls/src/groups/intents.rs

View workflow job for this annotation

GitHub Actions / Test

associated function `from_bytes` is never used

Check warning on line 250 in xmtp_mls/src/groups/intents.rs

View workflow job for this annotation

GitHub Actions / Test

associated function `from_bytes` is never used

Check warning on line 250 in xmtp_mls/src/groups/intents.rs

View workflow job for this annotation

GitHub Actions / workspace

associated function `from_bytes` is never used

warning: associated function `from_bytes` is never used --> xmtp_mls/src/groups/intents.rs:250:19 | 230 | impl UpdateMetadataIntentData { | ----------------------------- associated function in this implementation ... 250 | pub(crate) fn from_bytes(data: &[u8]) -> Result<Self, IntentError> { | ^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
let msg = UpdateMetadataData::decode(data)?;
let group_name = match msg.version {
Some(UpdateMetadataVersion::V1(ref v1)) => v1
.group_name.clone(),
None => return Err(IntentError::Generic("missing payload".to_string())),
};
let allow_list_account_addresses = match msg.version {
Some(UpdateMetadataVersion::V1(v1)) => v1
.allow_list_account_addresses
.ok_or(IntentError::Generic("missing payload".to_string()))?,
None => return Err(IntentError::Generic("missing payload".to_string())),
};

Ok(Self::new(group_name, allow_list_account_addresses))
}
}

impl From<UpdateMetadataIntentData> for Vec<u8> {
fn from(intent: UpdateMetadataIntentData) -> Self {
intent.to_bytes()
}
}

#[derive(Debug, Clone)]
pub enum PostCommitAction {
SendWelcomes(SendWelcomesAction),
Expand Down
7 changes: 6 additions & 1 deletion xmtp_mls/src/groups/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ where

let conn = provider.conn();
match intent.kind {
IntentKind::AddMembers | IntentKind::RemoveMembers | IntentKind::KeyUpdate => {
IntentKind::AddMembers | IntentKind::RemoveMembers | IntentKind::KeyUpdate | IntentKind::MetadataUpdate => {
if !allow_epoch_increment {
return Err(MessageProcessingError::EpochIncrementNotAllowed);
}
Expand Down Expand Up @@ -648,6 +648,11 @@ where

Ok((commit.tls_serialize_detached()?, None))
}
IntentKind::MetadataUpdate => {
// TODO: Not implemented

Ok((vec![], None))
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions xmtp_mls/src/storage/encrypted_store/group_intent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub enum IntentKind {
AddMembers = 2,
RemoveMembers = 3,
KeyUpdate = 4,
MetadataUpdate = 5,
}

#[repr(i32)]
Expand Down Expand Up @@ -261,6 +262,7 @@ where
2 => Ok(IntentKind::AddMembers),
3 => Ok(IntentKind::RemoveMembers),
4 => Ok(IntentKind::KeyUpdate),
5 => Ok(IntentKind::MetadataUpdate),
x => Err(format!("Unrecognized variant {}", x).into()),
}
}
Expand Down
Loading

0 comments on commit b06e152

Please sign in to comment.