mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
7e4071c117
**Does not yet work!** Currently, state resolution does not correctly resolve conflicting states. Everything else appears to work as expected, so stateres will be fixed soon, then we should be clear for takeoff. Also: a lot of things currently accept a nullable room ID that really just don't need to. This will need tidying up before merge. Some authentication checks have also been disabled temporarily but nothing important. A lot of things are tagged with `TODO(hydra)`, those need resolving before merge. External contributors should PR to the `hydra/public` branch, *not* ` main`. --- This PR should be squash merged. Reviewed-on: https://forgejo.ellis.link/continuwuation/continuwuity/pulls/943 Co-authored-by: nexy7574 <git@nexy7574.co.uk> Co-committed-by: nexy7574 <git@nexy7574.co.uk>
194 lines
4.2 KiB
Rust
194 lines
4.2 KiB
Rust
mod content;
|
|
mod filter;
|
|
mod format;
|
|
mod id;
|
|
mod redact;
|
|
mod relation;
|
|
mod type_ext;
|
|
mod unsigned;
|
|
|
|
use std::fmt::Debug;
|
|
|
|
use ruma::{
|
|
CanonicalJsonObject, EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, RoomId,
|
|
RoomVersionId, UserId, events::TimelineEventType,
|
|
};
|
|
use serde::Deserialize;
|
|
use serde_json::{Value as JsonValue, value::RawValue as RawJsonValue};
|
|
|
|
pub use self::{filter::Matches, id::*, relation::RelationTypeEqual, type_ext::TypeExt};
|
|
use super::{pdu::Pdu, state_key::StateKey};
|
|
use crate::{Result, utils};
|
|
|
|
/// Abstraction of a PDU so users can have their own PDU types.
|
|
pub trait Event: Clone + Debug {
|
|
/// Serialize into a Ruma JSON format, consuming.
|
|
#[inline]
|
|
fn into_format<T>(self) -> T
|
|
where
|
|
T: From<format::Owned<Self>>,
|
|
Self: Sized,
|
|
{
|
|
format::Owned(self).into()
|
|
}
|
|
|
|
/// Serialize into a Ruma JSON format
|
|
#[inline]
|
|
fn to_format<'a, T>(&'a self) -> T
|
|
where
|
|
T: From<format::Ref<'a, Self>>,
|
|
Self: Sized + 'a,
|
|
{
|
|
format::Ref(self).into()
|
|
}
|
|
|
|
#[inline]
|
|
fn contains_unsigned_property<T>(&self, property: &str, is_type: T) -> bool
|
|
where
|
|
T: FnOnce(&JsonValue) -> bool,
|
|
Self: Sized,
|
|
{
|
|
unsigned::contains_unsigned_property::<T, _>(self, property, is_type)
|
|
}
|
|
|
|
#[inline]
|
|
fn get_unsigned_property<T>(&self, property: &str) -> Result<T>
|
|
where
|
|
T: for<'de> Deserialize<'de>,
|
|
Self: Sized,
|
|
{
|
|
unsigned::get_unsigned_property::<T, _>(self, property)
|
|
}
|
|
|
|
#[inline]
|
|
fn get_unsigned_as_value(&self) -> JsonValue
|
|
where
|
|
Self: Sized,
|
|
{
|
|
unsigned::get_unsigned_as_value(self)
|
|
}
|
|
|
|
#[inline]
|
|
fn get_unsigned<T>(&self) -> Result<T>
|
|
where
|
|
T: for<'de> Deserialize<'de>,
|
|
Self: Sized,
|
|
{
|
|
unsigned::get_unsigned::<T, _>(self)
|
|
}
|
|
|
|
#[inline]
|
|
fn get_content_as_value(&self) -> JsonValue
|
|
where
|
|
Self: Sized,
|
|
{
|
|
content::as_value(self)
|
|
}
|
|
|
|
#[inline]
|
|
fn get_content<T>(&self) -> Result<T>
|
|
where
|
|
for<'de> T: Deserialize<'de>,
|
|
Self: Sized,
|
|
{
|
|
content::get::<T, _>(self)
|
|
}
|
|
|
|
#[inline]
|
|
fn redacts_id(&self, room_version: &RoomVersionId) -> Option<OwnedEventId>
|
|
where
|
|
Self: Sized,
|
|
{
|
|
redact::redacts_id(self, room_version)
|
|
}
|
|
|
|
#[inline]
|
|
fn is_redacted(&self) -> bool
|
|
where
|
|
Self: Sized,
|
|
{
|
|
redact::is_redacted(self)
|
|
}
|
|
|
|
#[inline]
|
|
fn into_canonical_object(self) -> CanonicalJsonObject
|
|
where
|
|
Self: Sized,
|
|
{
|
|
utils::to_canonical_object(self.into_pdu()).expect("failed to create Value::Object")
|
|
}
|
|
|
|
#[inline]
|
|
fn to_canonical_object(&self) -> CanonicalJsonObject {
|
|
utils::to_canonical_object(self.as_pdu()).expect("failed to create Value::Object")
|
|
}
|
|
|
|
#[inline]
|
|
fn into_value(self) -> JsonValue
|
|
where
|
|
Self: Sized,
|
|
{
|
|
serde_json::to_value(self.into_pdu()).expect("failed to create JSON Value")
|
|
}
|
|
|
|
#[inline]
|
|
fn to_value(&self) -> JsonValue {
|
|
serde_json::to_value(self.as_pdu()).expect("failed to create JSON Value")
|
|
}
|
|
|
|
#[inline]
|
|
fn as_mut_pdu(&mut self) -> &mut Pdu { unimplemented!("not a mutable Pdu") }
|
|
|
|
fn as_pdu(&self) -> &Pdu;
|
|
|
|
fn into_pdu(self) -> Pdu;
|
|
|
|
fn is_owned(&self) -> bool;
|
|
|
|
//
|
|
// Canonical properties
|
|
//
|
|
|
|
/// All the authenticating events for this event.
|
|
fn auth_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_;
|
|
|
|
/// The event's content.
|
|
fn content(&self) -> &RawJsonValue;
|
|
|
|
/// The `EventId` of this event.
|
|
fn event_id(&self) -> &EventId;
|
|
|
|
/// The time of creation on the originating server.
|
|
fn origin_server_ts(&self) -> MilliSecondsSinceUnixEpoch;
|
|
|
|
/// The events before this event.
|
|
fn prev_events(&self) -> impl DoubleEndedIterator<Item = &EventId> + Clone + Send + '_;
|
|
|
|
/// If this event is a redaction event this is the event it redacts.
|
|
fn redacts(&self) -> Option<&EventId>;
|
|
|
|
/// The `RoomId` of this event.
|
|
fn room_id(&self) -> Option<&RoomId>;
|
|
|
|
/// The `RoomId` or hash of this event.
|
|
/// This should only be preferred over room_id() if the event is a v12
|
|
/// create event.
|
|
fn room_id_or_hash(&self) -> OwnedRoomId;
|
|
|
|
/// The `UserId` of this event.
|
|
fn sender(&self) -> &UserId;
|
|
|
|
/// The state key for this event.
|
|
fn state_key(&self) -> Option<&str>;
|
|
|
|
/// The event type.
|
|
fn kind(&self) -> &TimelineEventType;
|
|
|
|
/// Metadata container; peer-trusted only.
|
|
fn unsigned(&self) -> Option<&RawJsonValue>;
|
|
|
|
//#[deprecated]
|
|
#[inline]
|
|
fn event_type(&self) -> &TimelineEventType { self.kind() }
|
|
}
|