Make Event trait Send+Sync.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -256,7 +256,7 @@ pub(crate) async fn is_ignored_pdu<Pdu>(
|
|||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
) -> bool
|
) -> bool
|
||||||
where
|
where
|
||||||
Pdu: Event + Send + Sync,
|
Pdu: Event,
|
||||||
{
|
{
|
||||||
// exclude Synapse's dummy events from bloating up response bodies. clients
|
// exclude Synapse's dummy events from bloating up response bodies. clients
|
||||||
// don't need to see this.
|
// don't need to see this.
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use super::{pdu::Pdu, state_key::StateKey};
|
|||||||
use crate::{Result, utils};
|
use crate::{Result, utils};
|
||||||
|
|
||||||
/// Abstraction of a PDU so users can have their own PDU types.
|
/// Abstraction of a PDU so users can have their own PDU types.
|
||||||
pub trait Event: Clone + Debug {
|
pub trait Event: Clone + Debug + Send + Sync {
|
||||||
/// Serialize into a Ruma JSON format, consuming.
|
/// Serialize into a Ruma JSON format, consuming.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_format<T>(self) -> T
|
fn into_format<T>(self) -> T
|
||||||
|
|||||||
@@ -84,7 +84,10 @@ impl Pdu {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Event for Pdu {
|
impl Event for Pdu
|
||||||
|
where
|
||||||
|
Self: Send + Sync + 'static,
|
||||||
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn auth_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_ {
|
fn auth_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_ {
|
||||||
self.auth_events.iter().map(AsRef::as_ref)
|
self.auth_events.iter().map(AsRef::as_ref)
|
||||||
@@ -137,7 +140,10 @@ impl Event for Pdu {
|
|||||||
fn is_owned(&self) -> bool { true }
|
fn is_owned(&self) -> bool { true }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Event for &Pdu {
|
impl Event for &Pdu
|
||||||
|
where
|
||||||
|
Self: Send,
|
||||||
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn auth_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_ {
|
fn auth_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_ {
|
||||||
self.auth_events.iter().map(AsRef::as_ref)
|
self.auth_events.iter().map(AsRef::as_ref)
|
||||||
|
|||||||
@@ -349,9 +349,9 @@ impl Service {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_admin_command<E>(&self, event: &E, body: &str) -> bool
|
pub async fn is_admin_command<Pdu>(&self, event: &Pdu, body: &str) -> bool
|
||||||
where
|
where
|
||||||
E: Event + Send + Sync,
|
Pdu: Event,
|
||||||
{
|
{
|
||||||
// Server-side command-escape with public echo
|
// Server-side command-escape with public echo
|
||||||
let is_escape = body.starts_with('\\');
|
let is_escape = body.starts_with('\\');
|
||||||
|
|||||||
@@ -296,8 +296,7 @@ impl Service {
|
|||||||
event: &E,
|
event: &E,
|
||||||
) -> Result
|
) -> Result
|
||||||
where
|
where
|
||||||
E: Event + Send + Sync,
|
E: Event,
|
||||||
for<'a> &'a E: Event + Send,
|
|
||||||
{
|
{
|
||||||
let mut notify = None;
|
let mut notify = None;
|
||||||
let mut tweaks = Vec::new();
|
let mut tweaks = Vec::new();
|
||||||
@@ -385,15 +384,13 @@ impl Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self, unread, pusher, tweaks, event))]
|
#[tracing::instrument(skip(self, unread, pusher, tweaks, event))]
|
||||||
async fn send_notice<E>(
|
async fn send_notice<Pdu: Event>(
|
||||||
&self,
|
&self,
|
||||||
unread: UInt,
|
unread: UInt,
|
||||||
pusher: &Pusher,
|
pusher: &Pusher,
|
||||||
tweaks: Vec<Tweak>,
|
tweaks: Vec<Tweak>,
|
||||||
event: &E,
|
event: &Pdu,
|
||||||
) -> Result
|
) -> Result
|
||||||
where
|
|
||||||
E: Event + Send + Sync,
|
|
||||||
{
|
{
|
||||||
// TODO: email
|
// TODO: email
|
||||||
match &pusher.kind {
|
match &pusher.kind {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ pub(super) async fn fetch_and_handle_outliers<'a, Pdu, Events>(
|
|||||||
room_id: &'a RoomId,
|
room_id: &'a RoomId,
|
||||||
) -> Vec<(PduEvent, Option<BTreeMap<String, CanonicalJsonValue>>)>
|
) -> Vec<(PduEvent, Option<BTreeMap<String, CanonicalJsonValue>>)>
|
||||||
where
|
where
|
||||||
Pdu: Event + Send + Sync,
|
Pdu: Event,
|
||||||
Events: Iterator<Item = &'a EventId> + Clone + Send,
|
Events: Iterator<Item = &'a EventId> + Clone + Send,
|
||||||
{
|
{
|
||||||
let back_off = |id| match self
|
let back_off = |id| match self
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub(super) async fn fetch_prev<'a, Pdu, Events>(
|
|||||||
HashMap<OwnedEventId, (PduEvent, BTreeMap<String, CanonicalJsonValue>)>,
|
HashMap<OwnedEventId, (PduEvent, BTreeMap<String, CanonicalJsonValue>)>,
|
||||||
)>
|
)>
|
||||||
where
|
where
|
||||||
Pdu: Event + Send + Sync,
|
Pdu: Event,
|
||||||
Events: Iterator<Item = &'a EventId> + Clone + Send,
|
Events: Iterator<Item = &'a EventId> + Clone + Send,
|
||||||
{
|
{
|
||||||
let num_ids = initial_set.clone().count();
|
let num_ids = initial_set.clone().count();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ pub(super) async fn fetch_state<Pdu>(
|
|||||||
event_id: &EventId,
|
event_id: &EventId,
|
||||||
) -> Result<Option<HashMap<u64, OwnedEventId>>>
|
) -> Result<Option<HashMap<u64, OwnedEventId>>>
|
||||||
where
|
where
|
||||||
Pdu: Event + Send + Sync,
|
Pdu: Event,
|
||||||
{
|
{
|
||||||
let res = self
|
let res = self
|
||||||
.services
|
.services
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub(super) async fn handle_outlier_pdu<'a, Pdu>(
|
|||||||
auth_events_known: bool,
|
auth_events_known: bool,
|
||||||
) -> Result<(PduEvent, BTreeMap<String, CanonicalJsonValue>)>
|
) -> Result<(PduEvent, BTreeMap<String, CanonicalJsonValue>)>
|
||||||
where
|
where
|
||||||
Pdu: Event + Send + Sync,
|
Pdu: Event,
|
||||||
{
|
{
|
||||||
// 1. Remove unsigned field
|
// 1. Remove unsigned field
|
||||||
value.remove("unsigned");
|
value.remove("unsigned");
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ pub(super) async fn handle_prev_pdu<'a, Pdu>(
|
|||||||
prev_id: &'a EventId,
|
prev_id: &'a EventId,
|
||||||
) -> Result
|
) -> Result
|
||||||
where
|
where
|
||||||
Pdu: Event + Send + Sync,
|
Pdu: Event,
|
||||||
{
|
{
|
||||||
// Check for disabled again because it might have changed
|
// Check for disabled again because it might have changed
|
||||||
if self.services.metadata.is_disabled(room_id).await {
|
if self.services.metadata.is_disabled(room_id).await {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub(super) async fn state_at_incoming_degree_one<Pdu>(
|
|||||||
incoming_pdu: &Pdu,
|
incoming_pdu: &Pdu,
|
||||||
) -> Result<Option<HashMap<u64, OwnedEventId>>>
|
) -> Result<Option<HashMap<u64, OwnedEventId>>>
|
||||||
where
|
where
|
||||||
Pdu: Event + Send + Sync,
|
Pdu: Event,
|
||||||
{
|
{
|
||||||
let prev_event = incoming_pdu
|
let prev_event = incoming_pdu
|
||||||
.prev_events()
|
.prev_events()
|
||||||
@@ -80,7 +80,7 @@ pub(super) async fn state_at_incoming_resolved<Pdu>(
|
|||||||
room_version_id: &RoomVersionId,
|
room_version_id: &RoomVersionId,
|
||||||
) -> Result<Option<HashMap<u64, OwnedEventId>>>
|
) -> Result<Option<HashMap<u64, OwnedEventId>>>
|
||||||
where
|
where
|
||||||
Pdu: Event + Send + Sync,
|
Pdu: Event,
|
||||||
{
|
{
|
||||||
trace!("Calculating extremity statehashes...");
|
trace!("Calculating extremity statehashes...");
|
||||||
let Ok(extremity_sstatehashes) = incoming_pdu
|
let Ok(extremity_sstatehashes) = incoming_pdu
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ pub(super) async fn upgrade_outlier_to_timeline_pdu<Pdu>(
|
|||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
) -> Result<Option<RawPduId>>
|
) -> Result<Option<RawPduId>>
|
||||||
where
|
where
|
||||||
Pdu: Event + Send + Sync,
|
Pdu: Event,
|
||||||
{
|
{
|
||||||
// Skip the PDU if we already have it as a timeline event
|
// Skip the PDU if we already have it as a timeline event
|
||||||
if let Ok(pduid) = self
|
if let Ok(pduid) = self
|
||||||
|
|||||||
@@ -332,10 +332,9 @@ impl Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all, level = "debug")]
|
#[tracing::instrument(skip_all, level = "debug")]
|
||||||
pub async fn summary_stripped<'a, E>(&self, event: &'a E) -> Vec<Raw<AnyStrippedStateEvent>>
|
pub async fn summary_stripped<Pdu>(&self, event: &Pdu) -> Vec<Raw<AnyStrippedStateEvent>>
|
||||||
where
|
where
|
||||||
E: Event + Send + Sync,
|
Pdu: Event,
|
||||||
&'a E: Event + Send,
|
|
||||||
{
|
{
|
||||||
let cells = [
|
let cells = [
|
||||||
(&StateEventType::RoomCreate, ""),
|
(&StateEventType::RoomCreate, ""),
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ impl crate::Service for Service {
|
|||||||
impl Service {
|
impl Service {
|
||||||
pub async fn add_to_thread<E>(&self, root_event_id: &EventId, event: &E) -> Result
|
pub async fn add_to_thread<E>(&self, root_event_id: &EventId, event: &E) -> Result
|
||||||
where
|
where
|
||||||
E: Event + Send + Sync,
|
E: Event,
|
||||||
{
|
{
|
||||||
let root_id = self
|
let root_id = self
|
||||||
.services
|
.services
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ pub async fn build_and_append_pdu(
|
|||||||
#[tracing::instrument(skip_all, level = "debug")]
|
#[tracing::instrument(skip_all, level = "debug")]
|
||||||
async fn check_pdu_for_admin_room<Pdu>(&self, pdu: &Pdu, sender: &UserId) -> Result
|
async fn check_pdu_for_admin_room<Pdu>(&self, pdu: &Pdu, sender: &UserId) -> Result
|
||||||
where
|
where
|
||||||
Pdu: Event + Send + Sync,
|
Pdu: Event,
|
||||||
{
|
{
|
||||||
match pdu.kind() {
|
match pdu.kind() {
|
||||||
| TimelineEventType::RoomEncryption => {
|
| TimelineEventType::RoomEncryption => {
|
||||||
|
|||||||
Reference in New Issue
Block a user