2026-05-10 23:08:18 -07:00
|
|
|
mod group_v1;
|
2026-05-11 09:33:01 -07:00
|
|
|
mod group_v2;
|
2026-05-10 23:08:18 -07:00
|
|
|
|
|
|
|
|
use crate::{AccountId, ContentData, DeliveryService, RegistrationService};
|
|
|
|
|
use chat_proto::logoschat::encryption::EncryptedPayload;
|
|
|
|
|
use libchat::IdentityProvider;
|
|
|
|
|
|
|
|
|
|
use std::fmt::Debug;
|
|
|
|
|
|
|
|
|
|
pub use crate::ChatError;
|
|
|
|
|
pub use group_v1::GroupV1Convo;
|
|
|
|
|
|
|
|
|
|
pub type ConversationIdRef<'a> = &'a str;
|
|
|
|
|
pub type ConversationId = String;
|
|
|
|
|
|
2026-05-12 17:30:22 -07:00
|
|
|
/// 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct ServiceContext<S: ExternalServices> {
|
|
|
|
|
pub(crate) identity_provider: S::IP,
|
|
|
|
|
pub(crate) ds: S::DS,
|
|
|
|
|
pub(crate) rs: S::RS,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<S: ExternalServices> ServiceContext<S> {
|
|
|
|
|
pub fn new(identity_provider: S::IP, ds: S::DS, rs: S::RS) -> Self {
|
|
|
|
|
ServiceContext {
|
|
|
|
|
identity_provider,
|
|
|
|
|
ds,
|
|
|
|
|
rs,
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-10 23:08:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait Id: Debug {
|
|
|
|
|
fn id(&self) -> ConversationIdRef<'_>;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 17:30:22 -07:00
|
|
|
pub trait BaseConvo<S: ExternalServices>: Id + Debug {
|
|
|
|
|
fn init(&self, service_ctx: &mut ServiceContext<S>) -> Result<(), ChatError>;
|
2026-05-10 23:08:18 -07:00
|
|
|
|
|
|
|
|
fn send_content(
|
|
|
|
|
&mut self,
|
2026-05-12 17:30:22 -07:00
|
|
|
service_ctx: &mut ServiceContext<S>,
|
2026-05-10 23:08:18 -07:00
|
|
|
content: &[u8],
|
|
|
|
|
) -> Result<(), ChatError>;
|
|
|
|
|
|
|
|
|
|
fn handle_frame(
|
|
|
|
|
&mut self,
|
2026-05-12 17:30:22 -07:00
|
|
|
service_ctx: &mut ServiceContext<S>,
|
2026-05-10 23:08:18 -07:00
|
|
|
enc_payload: EncryptedPayload,
|
|
|
|
|
) -> Result<Option<ContentData>, ChatError>;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 17:30:22 -07:00
|
|
|
pub trait BaseGroupConvo<S: ExternalServices>: BaseConvo<S> {
|
2026-05-10 23:08:18 -07:00
|
|
|
fn add_member(
|
|
|
|
|
&mut self,
|
2026-05-12 17:30:22 -07:00
|
|
|
service_ctx: &mut ServiceContext<S>,
|
2026-05-10 23:08:18 -07:00
|
|
|
members: &[&AccountId],
|
|
|
|
|
) -> Result<(), ChatError>;
|
|
|
|
|
}
|