Skip to content

Commit

Permalink
adds existing content type identifiers for saving to db
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Dec 19, 2024
1 parent fbed7ce commit ca5c57a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 4 deletions.
6 changes: 6 additions & 0 deletions xmtp_content_types/src/attachment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub struct AttachmentCodec {}

//. Legacy content type id at https://github.com/xmtp/xmtp-js/blob/main/content-types/content-type-remote-attachment/src/Attachment.ts
impl AttachmentCodec {
pub const TYPE_ID: &'static str = "attachment";
}
1 change: 1 addition & 0 deletions xmtp_content_types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod attachment;
pub mod group_updated;
pub mod membership_change;
pub mod reaction;
Expand Down
1 change: 1 addition & 0 deletions xmtp_content_types/src/reaction.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub struct ReactionCodec {}

/// Legacy content type id at https://github.com/xmtp/xmtp-js/blob/main/content-types/content-type-reaction/src/Reaction.ts
impl ReactionCodec {
pub const TYPE_ID: &'static str = "reaction";
}
3 changes: 2 additions & 1 deletion xmtp_content_types/src/read_receipt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub struct ReadReceiptCodec {}

/// Legacy content type id at https://github.com/xmtp/xmtp-js/blob/main/content-types/content-type-read-receipt/src/ReadReceipt.ts
impl ReadReceiptCodec {
pub const TYPE_ID: &'static str = "read_receipt";
pub const TYPE_ID: &'static str = "readReceipt";
}
3 changes: 2 additions & 1 deletion xmtp_content_types/src/remote_attachment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub struct RemoteAttachmentCodec {}

//. Legacy content type id at https://github.com/xmtp/xmtp-js/blob/main/content-types/content-type-remote-attachment/src/RemoteAttachment.ts
impl RemoteAttachmentCodec {
pub const TYPE_ID: &'static str = "remote_attachment";
pub const TYPE_ID: &'static str = "remoteStaticAttachment";
}
1 change: 1 addition & 0 deletions xmtp_content_types/src/reply.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub struct ReplyCodec {}

/// Legacy content type id at https://github.com/xmtp/xmtp-js/blob/main/content-types/content-type-reply/src/Reply.ts
impl ReplyCodec {
pub const TYPE_ID: &'static str = "reply";
}
3 changes: 2 additions & 1 deletion xmtp_content_types/src/transaction_reference.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub struct TransactionReferenceCodec {}

/// Legacy content type id at https://github.com/xmtp/xmtp-js/blob/main/content-types/content-type-transaction-reference/src/TransactionReference.ts
impl TransactionReferenceCodec {
pub const TYPE_ID: &'static str = "transaction_reference";
pub const TYPE_ID: &'static str = "transactionReference";
}
30 changes: 29 additions & 1 deletion xmtp_mls/src/storage/encrypted_store/group_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use diesel::{
sql_types::Integer,
};
use serde::{Deserialize, Serialize};
use xmtp_content_types::{group_updated, membership_change, text};
use xmtp_content_types::{
attachment, group_updated, membership_change, reaction, read_receipt, remote_attachment, reply,
text, transaction_reference,
};

use super::{
db_connection::DbConnection,
Expand Down Expand Up @@ -86,6 +89,7 @@ where
}
}

//Legacy content types found at https://github.com/xmtp/xmtp-js/tree/main/content-types
#[repr(i32)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, FromSqlRow, AsExpression)]
#[diesel(sql_type = diesel::sql_types::Integer)]
Expand All @@ -94,6 +98,12 @@ pub enum ContentType {
Text = 1,
GroupMembershipChange = 2,
GroupUpdated = 3,
Reaction = 4,
ReadReceipt = 5,
Reply = 6,
Attachment = 7,
RemoteAttachment = 8,
TransactionReference = 9,
}

impl std::fmt::Display for ContentType {
Expand All @@ -103,6 +113,12 @@ impl std::fmt::Display for ContentType {
Self::Text => text::TextCodec::TYPE_ID,
Self::GroupMembershipChange => membership_change::GroupMembershipChangeCodec::TYPE_ID,
Self::GroupUpdated => group_updated::GroupUpdatedCodec::TYPE_ID,
Self::Reaction => reaction::ReactionCodec::TYPE_ID,
Self::ReadReceipt => read_receipt::ReadReceiptCodec::TYPE_ID,
Self::Attachment => attachment::AttachmentCodec::TYPE_ID,
Self::RemoteAttachment => remote_attachment::RemoteAttachmentCodec::TYPE_ID,
Self::Reply => reply::ReplyCodec::TYPE_ID,
Self::TransactionReference => transaction_reference::TransactionReferenceCodec::TYPE_ID,
};

write!(f, "{}", as_string)
Expand All @@ -115,6 +131,12 @@ impl From<String> for ContentType {
text::TextCodec::TYPE_ID => Self::Text,
membership_change::GroupMembershipChangeCodec::TYPE_ID => Self::GroupMembershipChange,
group_updated::GroupUpdatedCodec::TYPE_ID => Self::GroupUpdated,
reaction::ReactionCodec::TYPE_ID => Self::Reaction,
read_receipt::ReadReceiptCodec::TYPE_ID => Self::ReadReceipt,
reply::ReplyCodec::TYPE_ID => Self::Reply,
attachment::AttachmentCodec::TYPE_ID => Self::Attachment,
remote_attachment::RemoteAttachmentCodec::TYPE_ID => Self::RemoteAttachment,
transaction_reference::TransactionReferenceCodec::TYPE_ID => Self::TransactionReference,
_ => Self::Unknown,
}
}
Expand All @@ -140,6 +162,12 @@ where
1 => Ok(ContentType::Text),
2 => Ok(ContentType::GroupMembershipChange),
3 => Ok(ContentType::GroupUpdated),
4 => Ok(ContentType::Reaction),
5 => Ok(ContentType::ReadReceipt),
6 => Ok(ContentType::Reply),
7 => Ok(ContentType::Attachment),
8 => Ok(ContentType::RemoteAttachment),
9 => Ok(ContentType::TransactionReference),
x => Err(format!("Unrecognized variant {}", x).into()),
}
}
Expand Down

0 comments on commit ca5c57a

Please sign in to comment.