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 Apr 3, 2024
1 parent 954614c commit a99d38b
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 @@ -13,10 +13,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 @@ -222,6 +223,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()),
})),
}
.encode(&mut buf)
.expect("encode error");

buf
}

pub(crate) fn from_bytes(data: &[u8]) -> Result<Self, IntentError> {
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 @@ -174,7 +174,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 @@ -654,6 +654,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 a99d38b

Please sign in to comment.