Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add groups storage #88

Merged
merged 13 commits into from
Jan 29, 2023
Merged

Add groups storage #88

merged 13 commits into from
Jan 29, 2023

Conversation

nanu-c
Copy link
Contributor

@nanu-c nanu-c commented Jan 6, 2023

This implements a group store and saves the groups as protobuf messages in the store.

@gferon
Copy link
Collaborator

gferon commented Jan 6, 2023

Awesome addition, it was on my todo list forever 😄

examples/cli.rs Outdated Show resolved Hide resolved
examples/cli.rs Outdated Show resolved Hide resolved
examples/cli.rs Outdated Show resolved Hide resolved
examples/cli.rs Outdated Show resolved Hide resolved
examples/cli.rs Outdated
println!("{:?} {:?}",key, title);
}
Err(e) => {
println!("Error: {:?}", e);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use the error! macro here instead? And avoid using the Debug representation of the error as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually i would love to use log::Error and log::Info or error! but they don't print anything to my console, so I ended up with println! statements. Regarding the {:?}, I still have to read some basics about the representations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the macro error! isn't defined and i changed it to an error representation.

examples/cli.rs Outdated
let manager = Manager::load_registered(config_store)?;
let group = manager.get_group_v2(group_master_key).await?;
let group = manager.get_group_v2(master_key).await?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super sure why you'd have to do it like this? Is it because you want to use the master key as a string key in the storage backend?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proto::group has no field for the master_key, so how should we store the masterkey? Either by adding a new field or using it as key in the tree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure, it was just a shot in the dark. First i looked into the groups_v2::Group but this doesn't serialize into json or a protobuf, so I tried it this way.

examples/cli.rs Outdated
println!("{:#?}", DebugGroup(&group));
for member in &group.members {
let profile_key = base64::encode(&member.profile_key.bytes);
println!("{member:#?} => profile_key = {profile_key}",);
}
manager.save_group(group, key.as_bytes().to_vec())?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure you can get the bytes representation from the GroupMasterKey object directly as well, also without allocating a new Vec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

503 | manager.save_group(group, master_key.into())?;
| ^^^^ the trait From<GroupMasterKey> is not implemented for Vec<u8>

src/manager.rs Outdated
@@ -811,6 +817,26 @@ impl<C: Store> Manager<C, Registered> {
Ok(group_changes)
}

pub fn save_group(&self, group:Group, key:Vec<u8>) -> Result<(), Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn save_group(&self, group:Group, key:Vec<u8>) -> Result<(), Error> {
pub fn save_group(&self, key: impl AsRef<[u8]>, group: Group) -> Result<(), Error> {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we have to rethink, it a little. I set the public_key: key which needs an vector. I misuse that field to pass the group id to self.config_store.save_group(proto_group)?; We have to either make a struct à la {key, group} or we need to pass the key as second argument.

src/proto.rs Outdated
@@ -110,3 +111,26 @@ impl TryInto<Content> for ContentProto {
Content::from_proto(self.content, self.metadata.into()).map_err(Error::from)
}
}

#[derive(Clone, PartialEq, ::prost::Message)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm confused but I feel like we don't need this wrapper to serialize the group?

@Schmiddiii
Copy link
Contributor

Some minor comments from my side:

  • Should presage also have a request_groups_sync similar to request_contacts_sync (if that is even possible)?
  • And probably the client using presage should not have to call save_group themselves, but I would expect that to be called inside presage (either when syncing groups like previously mentioned or deconstructing Message to search for new groups inside receive_messages).

Otherwise this GroupsStore-trait seems good for usage in Flare (once I update to use the presage-store).

@nanu-c
Copy link
Contributor Author

nanu-c commented Jan 11, 2023

Actually should we add the group sync here or in another pr?

@gferon gferon changed the title add groups storage Add groups storage Jan 29, 2023
@gferon
Copy link
Collaborator

gferon commented Jan 29, 2023

Actually should we add the group sync here or in another pr?

I would take care of this separately, this is already working fine fetching groups when you receive messages.

@gferon gferon self-requested a review January 29, 2023 21:02
@gferon gferon merged commit 57e2aa5 into whisperfish:main Jan 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants