libchat/core/conversations/src/conversation.rs

44 lines
1.2 KiB
Rust
Raw Normal View History

2025-12-22 09:40:46 -08:00
use std::fmt::Debug;
use std::sync::Arc;
pub use crate::errors::ChatError;
use crate::types::{AddressedEncryptedPayload, ContentData};
use double_ratchets::RatchetStorage;
2025-12-22 09:40:46 -08:00
pub type ConversationId<'a> = &'a str;
pub type ConversationIdOwned = Arc<str>;
pub trait Id: Debug {
2026-02-10 18:34:33 +01:00
fn id(&self) -> ConversationId<'_>;
2025-12-22 09:40:46 -08:00
}
pub trait Convo: Id + Debug {
fn send_message(&mut self, content: &[u8])
-> Result<Vec<AddressedEncryptedPayload>, ChatError>;
/// Decrypts and processes an incoming encrypted frame.
///
/// Returns `Ok(Some(ContentData))` if the frame contains user content,
/// `Ok(None)` for protocol frames (e.g., placeholders), or an error if
/// decryption or frame parsing fails.
fn handle_frame(
&mut self,
enc_payload: EncryptedPayload,
) -> Result<Option<ContentData>, ChatError>;
fn remote_id(&self) -> String;
2026-03-13 10:15:06 +08:00
/// Returns the conversation type identifier for storage.
fn convo_type(&self) -> &str;
/// Persists ratchet state to storage. Default is no-op.
fn save_ratchet_state(&self, _storage: &mut RatchetStorage) -> Result<(), ChatError> {
Ok(())
}
}
2025-12-22 09:40:46 -08:00
mod privatev1;
use chat_proto::logoschat::encryption::EncryptedPayload;
2025-12-22 09:40:46 -08:00
pub use privatev1::PrivateV1Convo;