mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-04-01 17:13:13 +00:00
chore: more refactor
This commit is contained in:
parent
927be286e8
commit
a342a508b3
@ -192,7 +192,7 @@ impl<T: ChatStore> Context<T> {
|
||||
|
||||
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,
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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> {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user