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

Move content types to new crate #1401

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"bindings_ffi",
"xtask",
"xmtp_debug",
"xmtp_content_types",
]

# Make the feature resolver explicit.
Expand Down Expand Up @@ -102,6 +103,7 @@ xmtp_cryptography = { path = "xmtp_cryptography" }
xmtp_id = { path = "xmtp_id" }
xmtp_mls = { path = "xmtp_mls" }
xmtp_proto = { path = "xmtp_proto" }
xmtp_content_types = { path = "xmtp_content_types" }

[profile.dev]
# Disabling debug info speeds up builds a bunch,
Expand Down
1 change: 1 addition & 0 deletions examples/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ valuable = { version = "0.1", features = ["derive"] }
valuable-serde = "0.1"
xmtp_api_grpc = { path = "../../xmtp_api_grpc" }
xmtp_cryptography = { path = "../../xmtp_cryptography" }
xmtp_content_types = { path = "../../xmtp_content_types" }
xmtp_id = { path = "../../xmtp_id" }
xmtp_mls = { path = "../../xmtp_mls" }
xmtp_proto = { path = "../../xmtp_proto", features = ["proto_full"] }
2 changes: 1 addition & 1 deletion examples/cli/cli-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use tracing_subscriber::{
use valuable::Valuable;
use xmtp_api_grpc::grpc_api_helper::Client as ClientV3;
use xmtp_api_grpc::replication_client::ClientV4;
use xmtp_content_types::{text::TextCodec, ContentCodec};
use xmtp_cryptography::{
signature::{RecoverableSignature, SignatureError},
utils::rng,
Expand All @@ -47,7 +48,6 @@ use xmtp_mls::XmtpApi;
use xmtp_mls::{
builder::ClientBuilderError,
client::ClientError,
codecs::{text::TextCodec, ContentCodec},
groups::{device_sync::MessageHistoryUrls, GroupMetadataOptions},
identity::IdentityStrategy,
storage::{
Expand Down
8 changes: 2 additions & 6 deletions examples/cli/serializable.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
use prost::Message;
use serde::Serialize;
use valuable::Valuable;
use xmtp_mls::{
codecs::{text::TextCodec, ContentCodec},
groups::MlsGroup,
storage::group_message::StoredGroupMessage,
XmtpApi,
};
use xmtp_content_types::{text::TextCodec, ContentCodec};
use xmtp_mls::{groups::MlsGroup, storage::group_message::StoredGroupMessage, XmtpApi};
use xmtp_proto::xmtp::mls::message_contents::EncodedContent;

#[derive(Serialize, Debug, Valuable)]
Expand Down
16 changes: 16 additions & 0 deletions xmtp_content_types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
edition = "2021"
name = "xmtp_content_types"
version.workspace = true
license.workspace = true

[dependencies]
thiserror = { workspace = true }
prost = { workspace = true, features = ["prost-derive"] }
rand = { workspace = true }

# XMTP/Local
xmtp_proto = { workspace = true, features = ["convert"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tonic = { version = "0.12", features = ["transport"] }
Copy link
Contributor

@insipx insipx Dec 11, 2024

Choose a reason for hiding this comment

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

where do we/will we use tonic in this crate?

Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub(crate) mod tests {

use xmtp_proto::xmtp::mls::message_contents::{group_updated::Inbox, GroupUpdated};

use crate::utils::test::rand_string;
use crate::test_utils::rand_string;

use super::*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
pub mod group_updated;
pub mod membership_change;
#[cfg(test)]
mod test_utils;
pub mod text;

use thiserror::Error;

use xmtp_proto::xmtp::mls::message_contents::{ContentTypeId, EncodedContent};

pub enum ContentType {
GroupMembershipChange,
GroupUpdated,
Text,
}

#[derive(Debug, Error)]
pub enum CodecError {
#[error("encode error {0}")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) mod tests {

use xmtp_proto::xmtp::mls::message_contents::MembershipChange;

use crate::utils::test::{rand_string, rand_vec};
use crate::test_utils::{rand_string, rand_vec};

use super::*;

Expand Down
15 changes: 15 additions & 0 deletions xmtp_content_types/src/test_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#[cfg(test)]
use rand::{
distributions::{Alphanumeric, DistString},
Rng,
};

#[cfg(test)]
pub(crate) fn rand_string() -> String {
Alphanumeric.sample_string(&mut rand::thread_rng(), 24)
}

#[cfg(test)]
pub(crate) fn rand_vec() -> Vec<u8> {
rand::thread_rng().gen::<[u8; 24]>().to_vec()
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) mod tests {
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_dedicated_worker);

use crate::codecs::{text::TextCodec, ContentCodec};
use crate::{text::TextCodec, ContentCodec};

#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
#[cfg_attr(not(target_arch = "wasm32"), test)]
Expand Down
1 change: 1 addition & 0 deletions xmtp_mls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ web-time.workspace = true
zeroize.workspace = true

# XMTP/Local
xmtp_content_types = { path = "../xmtp_content_types" }
xmtp_cryptography = { workspace = true }
xmtp_id = { path = "../xmtp_id" }
xmtp_proto = { workspace = true, features = ["convert"] }
Expand Down
4 changes: 2 additions & 2 deletions xmtp_mls/src/groups/mls_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use super::{
GroupError, HmacKey, IntentError, MlsGroup, ScopedGroupClient,
};
use crate::{
codecs::{group_updated::GroupUpdatedCodec, ContentCodec},
configuration::{
GRPC_DATA_LIMIT, HMAC_SALT, MAX_GROUP_SIZE, MAX_INTENT_PUBLISH_ATTEMPTS, MAX_PAST_EPOCHS,
SYNC_UPDATE_INSTALLATIONS_INTERVAL_NS,
Expand Down Expand Up @@ -64,6 +63,7 @@ use std::{
ops::RangeInclusive,
};
use thiserror::Error;
use xmtp_content_types::{group_updated::GroupUpdatedCodec, CodecError, ContentCodec};
use xmtp_id::{InboxId, InboxIdRef};
use xmtp_proto::xmtp::mls::{
api::v1::{
Expand Down Expand Up @@ -122,7 +122,7 @@ pub enum GroupMessageProcessingError {
#[error(transparent)]
Intent(#[from] IntentError),
#[error(transparent)]
Codec(#[from] crate::codecs::CodecError),
Codec(#[from] CodecError),
#[error("wrong credential type")]
WrongCredentialType(#[from] BasicCredentialError),
#[error(transparent)]
Expand Down
2 changes: 1 addition & 1 deletion xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1609,14 +1609,14 @@ pub(crate) mod tests {
use openmls::prelude::Member;
use prost::Message;
use std::sync::Arc;
use xmtp_content_types::{group_updated::GroupUpdatedCodec, ContentCodec};
use xmtp_cryptography::utils::generate_local_wallet;
use xmtp_proto::xmtp::mls::api::v1::group_message::Version;
use xmtp_proto::xmtp::mls::message_contents::EncodedContent;

use crate::{
assert_err,
builder::ClientBuilder,
codecs::{group_updated::GroupUpdatedCodec, ContentCodec},
groups::{
build_dm_protected_metadata_extension, build_mutable_metadata_extension_default,
build_protected_metadata_extension,
Expand Down
1 change: 0 additions & 1 deletion xmtp_mls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
pub mod api;
pub mod builder;
pub mod client;
pub mod codecs;
pub mod configuration;
pub mod groups;
mod hpke;
Expand Down
Loading