Skip to content

Commit

Permalink
Some refactoring and more tests (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkohbrok authored Jul 18, 2023
1 parent c63227e commit bda086c
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 222 deletions.
19 changes: 0 additions & 19 deletions backend/src/ds/self_remove_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,6 @@ impl DsGroupState {
Duration::days(USER_EXPIRATION_DAYS),
);

// ... then we update the client profiles and the user profile.
let user_profile = self
.user_profiles
.get_mut(&params.sender)
// This should have been caught by message validation.
.ok_or(ClientSelfRemovalError::LibraryError)?;

// If it's not the user's last client, we just remove the client.
if let Some(position) = user_profile
.clients
.iter()
.position(|&leaf_index| leaf_index == sender_index)
{
user_profile.clients.remove(position);
} else {
// The removed client does not seem to belong to this user...
return Err(ClientSelfRemovalError::InvalidMessage);
}

// We remove the user and client profile only when the proposal is committed.

// Finally, we create the message for distribution.
Expand Down
2 changes: 1 addition & 1 deletion coreclient/src/conversations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use uuid::Uuid;

pub(crate) fn new_conversation_message(message: Message) -> ConversationMessage {
ConversationMessage {
id: UuidBytes::from_uuid(&Uuid::new_v4()),
id: UuidBytes::from_uuid(Uuid::new_v4()),
timestamp: Timestamp::now().as_u64(),
message,
}
Expand Down
19 changes: 9 additions & 10 deletions coreclient/src/conversations/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,26 @@ impl ConversationStore {
conversations
}

pub(crate) fn conversation(&self, conversation_id: &Uuid) -> Option<&Conversation> {
self.conversations.get(conversation_id)
pub(crate) fn conversation(&self, conversation_id: Uuid) -> Option<&Conversation> {
self.conversations.get(&conversation_id)
}

pub(crate) fn set_inactive(&mut self, conversation_id: &Uuid, past_members: &[String]) {
self.conversations
.get_mut(conversation_id)
.map(|conversation| {
conversation.status = ConversationStatus::Inactive(InactiveConversation {
past_members: past_members.to_vec(),
past_members: past_members.iter().map(|m| m.to_owned()).collect(),
})
});
}

pub(crate) fn messages(
&self,
conversation_id: &Uuid,
conversation_id: Uuid,
last_n: usize,
) -> Vec<ConversationMessage> {
match self.messages.get(conversation_id) {
match self.messages.get(&conversation_id) {
Some(messages) => {
let mut messages: Vec<ConversationMessage> = messages
.iter()
Expand All @@ -125,21 +125,20 @@ impl ConversationStore {

pub(crate) fn store_message(
&mut self,
conversation_id: &Uuid,
conversation_id: Uuid,
message: ConversationMessage,
) -> Result<(), ConversationStoreError> {
let message_id = message.id.clone();
match self.conversations.get(conversation_id) {
match self.conversations.get(&conversation_id) {
Some(_conversation_data) => {
match self.messages.get_mut(conversation_id) {
match self.messages.get_mut(&conversation_id) {
Some(conversation_messages) => {
conversation_messages.insert(message_id.as_uuid(), message);
}
None => {
let mut conversation_messages = HashMap::new();
conversation_messages.insert(message_id.as_uuid(), message);
self.messages
.insert(*conversation_id, conversation_messages);
self.messages.insert(conversation_id, conversation_messages);
}
}
Ok(())
Expand Down
6 changes: 6 additions & 0 deletions coreclient/src/groups/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,10 @@ impl GroupDiff {
.insert(self.new_number_of_leaves, Some(new_client_information));
self.new_number_of_leaves += 1;
}

pub(crate) fn apply_pending_removes(&mut self, staged_commit: &StagedCommit) {
for pending_remove in staged_commit.remove_proposals() {
self.remove_client_credential(pending_remove.remove_proposal().removed())
}
}
}
Loading

0 comments on commit bda086c

Please sign in to comment.