diff --git a/core/conversations/src/context.rs b/core/conversations/src/context.rs index 49b9a3a..dfb5443 100644 --- a/core/conversations/src/context.rs +++ b/core/conversations/src/context.rs @@ -192,7 +192,7 @@ impl Context { let dr_state: RatchetState = self.ratchet_storage.load(&record.local_convo_id)?; - Ok(PrivateV1Convo::from_stored( + Ok(PrivateV1Convo::new( record.local_convo_id, record.remote_convo_id, dr_state, diff --git a/core/conversations/src/conversation.rs b/core/conversations/src/conversation.rs index 4e15373..31ef831 100644 --- a/core/conversations/src/conversation.rs +++ b/core/conversations/src/conversation.rs @@ -29,15 +29,14 @@ pub trait Convo: Id + Debug { fn remote_id(&self) -> String; /// Returns the conversation type identifier for storage. - fn convo_type(&self) -> &str; + fn convo_type(&self) -> ConversationKind; /// Persists ratchet state to storage. Default is no-op. - fn save_ratchet_state(&self, _storage: &mut RatchetStorage) -> Result<(), ChatError> { - Ok(()) - } + fn save_ratchet_state(&self, _storage: &mut RatchetStorage) -> Result<(), ChatError>; } mod privatev1; use chat_proto::logoschat::encryption::EncryptedPayload; pub use privatev1::PrivateV1Convo; +use storage::ConversationKind; diff --git a/core/conversations/src/conversation/privatev1.rs b/core/conversations/src/conversation/privatev1.rs index 3cd506d..3ab9116 100644 --- a/core/conversations/src/conversation/privatev1.rs +++ b/core/conversations/src/conversation/privatev1.rs @@ -10,6 +10,7 @@ use crypto::{PrivateKey, PublicKey, SymmetricKey32}; use double_ratchets::{Header, InstallationKeyPair, RatchetState}; use prost::{Message, bytes::Bytes}; use std::fmt::Debug; +use storage::ConversationKind; use crate::{ conversation::{ChatError, ConversationId, Convo, Id}, @@ -60,6 +61,15 @@ pub struct PrivateV1Convo { } impl PrivateV1Convo { + /// Reconstructs a PrivateV1Convo from persisted metadata and ratchet state. + pub fn new(local_convo_id: String, remote_convo_id: String, dr_state: RatchetState) -> Self { + Self { + local_convo_id, + remote_convo_id, + dr_state, + } + } + pub fn new_initiator(seed_key: SymmetricKey32, remote: PublicKey) -> Self { let base_convo_id = BaseConvoId::new(&seed_key); let local_convo_id = base_convo_id.id_for_participant(Role::Initiator); @@ -78,19 +88,6 @@ impl PrivateV1Convo { } } - /// Reconstructs a PrivateV1Convo from persisted metadata and ratchet state. - pub fn from_stored( - local_convo_id: String, - remote_convo_id: String, - dr_state: RatchetState, - ) -> Self { - Self { - local_convo_id, - remote_convo_id, - dr_state, - } - } - pub fn new_responder(seed_key: SymmetricKey32, dh_self: &PrivateKey) -> Self { let base_convo_id = BaseConvoId::new(&seed_key); let local_convo_id = base_convo_id.id_for_participant(Role::Responder); @@ -224,8 +221,8 @@ impl Convo for PrivateV1Convo { self.remote_convo_id.clone() } - fn convo_type(&self) -> &str { - "private_v1" + fn convo_type(&self) -> ConversationKind { + ConversationKind::PrivateV1 } fn save_ratchet_state(&self, storage: &mut RatchetStorage) -> Result<(), ChatError> {