mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-06-28 20:19:26 +00:00
parent
e163980715
commit
c5b264c827
@ -15,7 +15,7 @@ pub type ConversationId = String;
|
|||||||
pub type ConversationIdRef<'a> = &'a str;
|
pub type ConversationIdRef<'a> = &'a str;
|
||||||
|
|
||||||
/// Behaviour shared by every conversation kind.
|
/// Behaviour shared by every conversation kind.
|
||||||
pub(crate) trait Convo<S: ExternalServices> {
|
pub(crate) trait Convo<S: ExternalServices>: Identified {
|
||||||
fn send_content(&mut self, cx: &mut ServiceContext<S>, content: &[u8])
|
fn send_content(&mut self, cx: &mut ServiceContext<S>, content: &[u8])
|
||||||
-> Result<(), ChatError>;
|
-> Result<(), ChatError>;
|
||||||
|
|
||||||
@ -40,6 +40,8 @@ pub(crate) trait GroupConvo<S: ExternalServices>: Convo<S> + std::fmt::Debug + S
|
|||||||
cx: &mut ServiceContext<S>,
|
cx: &mut ServiceContext<S>,
|
||||||
members: &[IdentIdRef],
|
members: &[IdentIdRef],
|
||||||
) -> Result<(), ChatError>;
|
) -> Result<(), ChatError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) trait Identified {
|
||||||
fn id(&self) -> ConversationIdRef<'_>;
|
fn id(&self) -> ConversationIdRef<'_>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,12 +11,13 @@ use prost::Message as _;
|
|||||||
use shared_traits::IdentIdRef;
|
use shared_traits::IdentIdRef;
|
||||||
|
|
||||||
use crate::account_directory::{AccountDirectory, resolve_device_ids};
|
use crate::account_directory::{AccountDirectory, resolve_device_ids};
|
||||||
|
use crate::conversation::ConversationIdRef;
|
||||||
use crate::inbox_v2::MlsProvider;
|
use crate::inbox_v2::MlsProvider;
|
||||||
use crate::service_context::{ExternalServices, ServiceContext};
|
use crate::service_context::{ExternalServices, ServiceContext};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
DeliveryService, IdentityProvider,
|
DeliveryService, IdentityProvider,
|
||||||
conversation::{ChatError, Convo, GroupConvo},
|
conversation::{ChatError, Convo, GroupConvo, Identified},
|
||||||
outcomes::{Content, ConvoOutcome},
|
outcomes::{Content, ConvoOutcome},
|
||||||
service_traits::KeyPackageProvider,
|
service_traits::KeyPackageProvider,
|
||||||
types::AddressedEncryptedPayload,
|
types::AddressedEncryptedPayload,
|
||||||
@ -174,10 +175,6 @@ impl GroupV1Convo {
|
|||||||
Ok(keypackages)
|
Ok(keypackages)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn id(&self) -> &str {
|
|
||||||
&self.convo_id
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send_message<S: ExternalServices>(
|
fn send_message<S: ExternalServices>(
|
||||||
&mut self,
|
&mut self,
|
||||||
content: &[u8],
|
content: &[u8],
|
||||||
@ -205,6 +202,12 @@ impl GroupV1Convo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Identified for GroupV1Convo {
|
||||||
|
fn id(&self) -> ConversationIdRef<'_> {
|
||||||
|
&self.convo_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<S: ExternalServices> Convo<S> for GroupV1Convo {
|
impl<S: ExternalServices> Convo<S> for GroupV1Convo {
|
||||||
fn send_content(
|
fn send_content(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -344,8 +347,4 @@ impl<S: ExternalServices> GroupConvo<S> for GroupV1Convo {
|
|||||||
.publish(env)
|
.publish(env)
|
||||||
.map_err(|e| ChatError::Generic(format!("Publish: {e}")))
|
.map_err(|e| ChatError::Generic(format!("Publish: {e}")))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(&self) -> super::ConversationIdRef<'_> {
|
|
||||||
&self.convo_id
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ use crate::IdentityProvider;
|
|||||||
use crate::conversation::{ConversationIdRef, ExternalServices, ServiceContext};
|
use crate::conversation::{ConversationIdRef, ExternalServices, ServiceContext};
|
||||||
use crate::{
|
use crate::{
|
||||||
ConvoOutcome, DeliveryService, RegistrationService,
|
ConvoOutcome, DeliveryService, RegistrationService,
|
||||||
conversation::{ChatError, Convo, GroupConvo},
|
conversation::{ChatError, Convo, GroupConvo, Identified},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Namespace used for de-mls (GroupV2) keypackages, so they don't collide
|
/// Namespace used for de-mls (GroupV2) keypackages, so they don't collide
|
||||||
@ -272,6 +272,12 @@ impl GroupV2Convo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Identified for GroupV2Convo {
|
||||||
|
fn id(&self) -> ConversationIdRef<'_> {
|
||||||
|
&self.convo_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<S> Convo<S> for GroupV2Convo
|
impl<S> Convo<S> for GroupV2Convo
|
||||||
where
|
where
|
||||||
S: ExternalServices,
|
S: ExternalServices,
|
||||||
@ -347,9 +353,6 @@ impl<S> GroupConvo<S> for GroupV2Convo
|
|||||||
where
|
where
|
||||||
S: ExternalServices,
|
S: ExternalServices,
|
||||||
{
|
{
|
||||||
fn id(&self) -> ConversationIdRef<'_> {
|
|
||||||
&self.convo_id
|
|
||||||
}
|
|
||||||
#[instrument(name = "groupv2.add_member", skip_all, fields(user_id = %service_ctx.mls_identity.display_name()))]
|
#[instrument(name = "groupv2.add_member", skip_all, fields(user_id = %service_ctx.mls_identity.display_name()))]
|
||||||
fn add_member(
|
fn add_member(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|||||||
@ -14,7 +14,7 @@ use storage::{ConversationKind, ConversationMeta, ConversationStore};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
DeliveryService,
|
DeliveryService,
|
||||||
conversation::{ChatError, ConversationId, Convo},
|
conversation::{ChatError, ConversationId, ConversationIdRef, Convo, Identified},
|
||||||
errors::EncryptionError,
|
errors::EncryptionError,
|
||||||
inbox::PRIVATE_V1_INBOX_ADDRESS,
|
inbox::PRIVATE_V1_INBOX_ADDRESS,
|
||||||
outcomes::{Content, ConvoOutcome},
|
outcomes::{Content, ConvoOutcome},
|
||||||
@ -200,10 +200,6 @@ impl PrivateV1Convo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn id(&self) -> &str {
|
|
||||||
&self.local_convo_id
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn encrypt_content<S: RatchetStore>(
|
pub fn encrypt_content<S: RatchetStore>(
|
||||||
&mut self,
|
&mut self,
|
||||||
content: &[u8],
|
content: &[u8],
|
||||||
@ -235,6 +231,12 @@ impl PrivateV1Convo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Identified for PrivateV1Convo {
|
||||||
|
fn id(&self) -> ConversationIdRef<'_> {
|
||||||
|
&self.local_convo_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<S: ExternalServices> Convo<S> for PrivateV1Convo {
|
impl<S: ExternalServices> Convo<S> for PrivateV1Convo {
|
||||||
fn send_content(
|
fn send_content(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
use crate::causal_history::{CausalHistoryStore, MissingMessage};
|
use crate::causal_history::{CausalHistoryStore, MissingMessage};
|
||||||
use crate::conversation::{ConversationIdRef, GroupV1Convo, GroupV2Convo, PrivateV1Convo};
|
use crate::conversation::{
|
||||||
|
ConversationIdRef, GroupV1Convo, GroupV2Convo, Identified, PrivateV1Convo,
|
||||||
|
};
|
||||||
use crate::service_context::{ExternalServices, ServiceContext};
|
use crate::service_context::{ExternalServices, ServiceContext};
|
||||||
use crate::{DeliveryService, IdentityProvider, RegistrationService, WakeupService};
|
use crate::{DeliveryService, IdentityProvider, RegistrationService, WakeupService};
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -470,8 +472,8 @@ enum ConvoTypeOwned<S: ExternalServices> {
|
|||||||
Group(Box<dyn GroupConvo<S>>),
|
Group(Box<dyn GroupConvo<S>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, S: ExternalServices> ConvoTypeOwned<S> {
|
impl<S: ExternalServices> Identified for ConvoTypeOwned<S> {
|
||||||
pub fn id(&'a self) -> ConversationIdRef<'a> {
|
fn id(&self) -> ConversationIdRef<'_> {
|
||||||
match self {
|
match self {
|
||||||
ConvoTypeOwned::Group(group_convo) => group_convo.id(),
|
ConvoTypeOwned::Group(group_convo) => group_convo.id(),
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ use crate::RegistrationService;
|
|||||||
use crate::conversation::GroupConvo;
|
use crate::conversation::GroupConvo;
|
||||||
use crate::conversation::GroupV1Convo;
|
use crate::conversation::GroupV1Convo;
|
||||||
use crate::conversation::GroupV2Convo;
|
use crate::conversation::GroupV2Convo;
|
||||||
|
use crate::conversation::Identified as _;
|
||||||
use crate::service_context::{ExternalServices, ServiceContext};
|
use crate::service_context::{ExternalServices, ServiceContext};
|
||||||
use crate::utils::{blake2b_hex, hash_size};
|
use crate::utils::{blake2b_hex, hash_size};
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user