Skip to content

Commit

Permalink
message save, there and back
Browse files Browse the repository at this point in the history
  • Loading branch information
codabrink committed Jan 8, 2025
1 parent 81b94af commit 4b86529
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 2 deletions.
1 change: 1 addition & 0 deletions xmtp_mls/src/groups/device_sync/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};

mod consent_save;
mod group_save;
mod message_save;

#[derive(Serialize, Deserialize)]
pub enum BackupElement {
Expand Down
3 changes: 1 addition & 2 deletions xmtp_mls/src/groups/device_sync/backup/consent_save.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::storage::consent_record::{ConsentState, ConsentType, StoredConsentRecord};
use xmtp_proto::xmtp::device_sync::consent_backup::{
ConsentRecordSave, ConsentStateSave, ConsentTypeSave,
};

use crate::storage::consent_record::{ConsentState, ConsentType, StoredConsentRecord};

impl From<ConsentRecordSave> for StoredConsentRecord {
fn from(value: ConsentRecordSave) -> Self {
let entity_type = value.entity_type().into();
Expand Down
119 changes: 119 additions & 0 deletions xmtp_mls/src/groups/device_sync/backup/message_save.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
use xmtp_proto::xmtp::device_sync::message_backup::{
ContentTypeSave, DeliveryStatusSave, GroupMessageKindSave, GroupMessageSave,
};

use crate::storage::group_message::{
ContentType, DeliveryStatus, GroupMessageKind, StoredGroupMessage,
};

impl From<GroupMessageSave> for StoredGroupMessage {
fn from(value: GroupMessageSave) -> Self {
let kind = value.kind().into();
let delivery_status = value.delivery_status().into();
let content_type = value.content_type().into();

Self {
id: value.id,
group_id: value.group_id,
decrypted_message_bytes: value.decrypted_message_bytes,
sent_at_ns: value.sent_at_ns,
kind,
sender_installation_id: value.sender_installation_id,
sender_inbox_id: value.sender_inbox_id,
delivery_status,
content_type,
version_major: value.version_major,
version_minor: value.version_minor,
authority_id: value.authority_id,
}
}
}
impl From<GroupMessageKindSave> for GroupMessageKind {
fn from(value: GroupMessageKindSave) -> Self {
match value {
GroupMessageKindSave::Application => Self::Application,
GroupMessageKindSave::MembershipChange => Self::MembershipChange,
}
}
}
impl From<DeliveryStatusSave> for DeliveryStatus {
fn from(value: DeliveryStatusSave) -> Self {
match value {
DeliveryStatusSave::Failed => Self::Failed,
DeliveryStatusSave::Published => Self::Published,
DeliveryStatusSave::Unpublished => Self::Unpublished,
}
}
}
impl From<ContentTypeSave> for ContentType {
fn from(value: ContentTypeSave) -> Self {
match value {
ContentTypeSave::Attachment => Self::Attachment,
ContentTypeSave::GroupMembershipChange => Self::GroupMembershipChange,
ContentTypeSave::GroupUpdated => Self::GroupUpdated,
ContentTypeSave::Reaction => Self::Reaction,
ContentTypeSave::ReadReceipt => Self::ReadReceipt,
ContentTypeSave::RemoteAttachment => Self::RemoteAttachment,
ContentTypeSave::Reply => Self::Reply,
ContentTypeSave::Text => Self::Text,
ContentTypeSave::TransactionReference => Self::TransactionReference,
ContentTypeSave::Unknown => Self::Unknown,
}
}
}

impl From<StoredGroupMessage> for GroupMessageSave {
fn from(value: StoredGroupMessage) -> Self {
let kind: GroupMessageKindSave = value.kind.into();
let delivery_status: DeliveryStatusSave = value.delivery_status.into();
let content_type: ContentTypeSave = value.content_type.into();

Self {
id: value.id,
group_id: value.group_id,
decrypted_message_bytes: value.decrypted_message_bytes,
sent_at_ns: value.sent_at_ns,
kind: kind as i32,
sender_installation_id: value.sender_installation_id,
sender_inbox_id: value.sender_inbox_id,
delivery_status: delivery_status as i32,
content_type: content_type as i32,
version_major: value.version_major,
version_minor: value.version_minor,
authority_id: value.authority_id,
}
}
}
impl From<GroupMessageKind> for GroupMessageKindSave {
fn from(value: GroupMessageKind) -> Self {
match value {
GroupMessageKind::Application => Self::Application,
GroupMessageKind::MembershipChange => Self::MembershipChange,
}
}
}
impl From<DeliveryStatus> for DeliveryStatusSave {
fn from(value: DeliveryStatus) -> Self {
match value {
DeliveryStatus::Failed => Self::Failed,
DeliveryStatus::Published => Self::Published,
DeliveryStatus::Unpublished => Self::Unpublished,
}
}
}
impl From<ContentType> for ContentTypeSave {
fn from(value: ContentType) -> Self {
match value {
ContentType::Attachment => Self::Attachment,
ContentType::GroupMembershipChange => Self::GroupMembershipChange,
ContentType::GroupUpdated => Self::GroupUpdated,
ContentType::Reaction => Self::Reaction,
ContentType::ReadReceipt => Self::ReadReceipt,
ContentType::RemoteAttachment => Self::RemoteAttachment,
ContentType::Reply => Self::Reply,
ContentType::Text => Self::Text,
ContentType::TransactionReference => Self::TransactionReference,
ContentType::Unknown => Self::Unknown,
}
}
}

0 comments on commit 4b86529

Please sign in to comment.