mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-04-01 09:04:03 +00:00
chore: refactor to use generics and enum
This commit is contained in:
parent
d64d618a8d
commit
e5e10c6cb0
@ -6,7 +6,7 @@ use double_ratchets::{RatchetState, restore_ratchet_state};
|
||||
use storage::{ChatStore, ConversationKind, ConversationMeta};
|
||||
|
||||
use crate::{
|
||||
conversation::{ConversationId, Convo, Id, PrivateV1Convo},
|
||||
conversation::{Conversation, ConversationId, Convo, Id, PrivateV1Convo},
|
||||
errors::ChatError,
|
||||
inbox::Inbox,
|
||||
proto::{EncryptedPayload, EnvelopeV1, Message},
|
||||
@ -148,7 +148,10 @@ impl<T: ChatStore> Context<T> {
|
||||
|
||||
let (convo, content) = self.inbox.handle_frame(&ephemeral_key, enc_payload)?;
|
||||
|
||||
self.persist_convo(&convo)?;
|
||||
match convo {
|
||||
Conversation::Private(convo) => self.persist_convo(&convo)?,
|
||||
};
|
||||
|
||||
self.store.remove_ephemeral_key(&key_hex)?;
|
||||
Ok(content)
|
||||
}
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
mod privatev1;
|
||||
|
||||
use crate::types::{AddressedEncryptedPayload, ContentData};
|
||||
use chat_proto::logoschat::encryption::EncryptedPayload;
|
||||
use std::fmt::Debug;
|
||||
use std::sync::Arc;
|
||||
use storage::ConversationKind;
|
||||
|
||||
pub use crate::errors::ChatError;
|
||||
use crate::types::{AddressedEncryptedPayload, ContentData};
|
||||
pub use privatev1::PrivateV1Convo;
|
||||
|
||||
pub type ConversationId<'a> = &'a str;
|
||||
pub type ConversationIdOwned = Arc<str>;
|
||||
@ -31,8 +36,6 @@ pub trait Convo: Id + Debug {
|
||||
fn convo_type(&self) -> ConversationKind;
|
||||
}
|
||||
|
||||
mod privatev1;
|
||||
|
||||
use chat_proto::logoschat::encryption::EncryptedPayload;
|
||||
pub use privatev1::PrivateV1Convo;
|
||||
use storage::ConversationKind;
|
||||
pub enum Conversation {
|
||||
Private(PrivateV1Convo),
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ impl PrivateV1Convo {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn save_ratchet_state(&self, storage: &mut dyn RatchetStore) -> Result<(), ChatError> {
|
||||
pub fn save_ratchet_state<T: RatchetStore>(&self, storage: &mut T) -> Result<(), ChatError> {
|
||||
let record = to_ratchet_record(&self.dr_state);
|
||||
let skipped_keys = to_skipped_key_records(&self.dr_state.skipped_keys());
|
||||
storage.save_ratchet_state(&self.local_convo_id, &record, &skipped_keys)?;
|
||||
|
||||
@ -8,7 +8,7 @@ use std::rc::Rc;
|
||||
use crypto::{PrekeyBundle, SymmetricKey32};
|
||||
|
||||
use crate::context::Introduction;
|
||||
use crate::conversation::{ChatError, ConversationId, Convo, Id, PrivateV1Convo};
|
||||
use crate::conversation::{ChatError, Conversation, ConversationId, Convo, Id, PrivateV1Convo};
|
||||
use crate::crypto::{CopyBytes, PrivateKey, PublicKey};
|
||||
use crate::inbox::handshake::InboxHandshake;
|
||||
use crate::proto;
|
||||
@ -115,7 +115,7 @@ impl Inbox {
|
||||
&self,
|
||||
ephemeral_key: &PrivateKey,
|
||||
enc_payload: EncryptedPayload,
|
||||
) -> Result<(PrivateV1Convo, Option<ContentData>), ChatError> {
|
||||
) -> Result<(Conversation, Option<ContentData>), ChatError> {
|
||||
let handshake = Self::extract_payload(enc_payload)?;
|
||||
|
||||
let header = handshake
|
||||
@ -142,7 +142,7 @@ impl Inbox {
|
||||
None => return Err(ChatError::Protocol("expected contentData".into())),
|
||||
};
|
||||
|
||||
Ok((convo, Some(content)))
|
||||
Ok((Conversation::Private(convo), Some(content)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user