mod group_v1; mod group_v2; use crate::{AccountId, ContentData, DeliveryService, RegistrationService}; use chat_proto::logoschat::encryption::EncryptedPayload; use libchat::{IdentityProvider, WakeupService}; use std::fmt::Debug; pub use crate::ChatError; pub use group_v1::GroupV1Convo; pub use group_v2::GroupV2Convo; pub type ConversationIdRef<'a> = &'a str; pub type ConversationId = String; /// A trait which bundles all the external service traits into a single scope. /// This allows for a single bound to be used internally, and cuts down on /// the clutter pub trait ExternalServices: Debug { type IP: IdentityProvider; type DS: DeliveryService; type RS: RegistrationService; type WS: WakeupService; } #[derive(Debug)] pub struct ServiceContext { pub(crate) identity_provider: S::IP, pub(crate) ds: S::DS, pub(crate) rs: S::RS, pub(crate) wakeup_service: S::WS, } impl ServiceContext { pub fn new(identity_provider: S::IP, ds: S::DS, rs: S::RS, wakeup_service: S::WS) -> Self { ServiceContext { identity_provider, ds, rs, wakeup_service, } } } pub trait Id: Debug { fn id(&self) -> ConversationIdRef<'_>; } pub trait BaseConvo: Id + Debug { fn init(&self, service_ctx: &mut ServiceContext) -> Result<(), ChatError>; fn send_content( &mut self, service_ctx: &mut ServiceContext, content: &[u8], ) -> Result<(), ChatError>; fn handle_frame( &mut self, service_ctx: &mut ServiceContext, enc_payload: EncryptedPayload, ) -> Result, ChatError>; fn wakeup(&mut self, service_ctx: &mut ServiceContext) -> Result<(), ChatError>; } pub trait BaseGroupConvo: BaseConvo { fn add_member( &mut self, service_ctx: &mut ServiceContext, members: &[&AccountId], ) -> Result<(), ChatError>; }