mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-02-05 21:22:25 -05:00
refactor: Add IsPrefix = False bound on StaticEventContent bounds
Since those APIs only support a full event type, not an event type prefix. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
committed by
Damir Jelić
parent
d8b6966c0a
commit
0a7ac18d9f
@@ -578,7 +578,9 @@ impl StateChanges {
|
||||
state_key: &K,
|
||||
) -> Option<&Raw<SyncStateEvent<C>>>
|
||||
where
|
||||
C: StaticEventContent + StaticStateEventContent + RedactContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False>
|
||||
+ StaticStateEventContent
|
||||
+ RedactContent,
|
||||
C::Redacted: RedactedStateEventContent,
|
||||
C::StateKey: Borrow<K>,
|
||||
K: AsRef<str> + ?Sized,
|
||||
@@ -599,7 +601,7 @@ impl StateChanges {
|
||||
state_key: &K,
|
||||
) -> Option<&Raw<StrippedStateEvent<C::PossiblyRedacted>>>
|
||||
where
|
||||
C: StaticEventContent + StaticStateEventContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False> + StaticStateEventContent,
|
||||
C::StateKey: Borrow<K>,
|
||||
K: AsRef<str> + ?Sized,
|
||||
{
|
||||
@@ -620,7 +622,9 @@ impl StateChanges {
|
||||
state_key: &K,
|
||||
) -> Option<StrippedStateEvent<C::PossiblyRedacted>>
|
||||
where
|
||||
C: StaticEventContent + StaticStateEventContent + RedactContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False>
|
||||
+ StaticStateEventContent
|
||||
+ RedactContent,
|
||||
C::Redacted: RedactedStateEventContent,
|
||||
C::PossiblyRedacted: StaticEventContent + DeserializeOwned,
|
||||
C::StateKey: Borrow<K>,
|
||||
|
||||
@@ -788,7 +788,9 @@ pub trait StateStoreExt: StateStore {
|
||||
room_id: &RoomId,
|
||||
) -> Result<Option<RawSyncOrStrippedState<C>>, Self::Error>
|
||||
where
|
||||
C: StaticEventContent + StaticStateEventContent<StateKey = EmptyStateKey> + RedactContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False>
|
||||
+ StaticStateEventContent<StateKey = EmptyStateKey>
|
||||
+ RedactContent,
|
||||
C::Redacted: RedactedStateEventContent,
|
||||
{
|
||||
Ok(self.get_state_event(room_id, C::TYPE.into(), "").await?.map(|raw| raw.cast()))
|
||||
@@ -805,7 +807,9 @@ pub trait StateStoreExt: StateStore {
|
||||
state_key: &K,
|
||||
) -> Result<Option<RawSyncOrStrippedState<C>>, Self::Error>
|
||||
where
|
||||
C: StaticEventContent + StaticStateEventContent + RedactContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False>
|
||||
+ StaticStateEventContent
|
||||
+ RedactContent,
|
||||
C::StateKey: Borrow<K>,
|
||||
C::Redacted: RedactedStateEventContent,
|
||||
K: AsRef<str> + ?Sized + Sync,
|
||||
@@ -826,7 +830,9 @@ pub trait StateStoreExt: StateStore {
|
||||
room_id: &RoomId,
|
||||
) -> Result<Vec<RawSyncOrStrippedState<C>>, Self::Error>
|
||||
where
|
||||
C: StaticEventContent + StaticStateEventContent + RedactContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False>
|
||||
+ StaticStateEventContent
|
||||
+ RedactContent,
|
||||
C::Redacted: RedactedStateEventContent,
|
||||
{
|
||||
// FIXME: Could be more efficient, if we had streaming store accessor functions
|
||||
@@ -852,7 +858,9 @@ pub trait StateStoreExt: StateStore {
|
||||
state_keys: I,
|
||||
) -> Result<Vec<RawSyncOrStrippedState<C>>, Self::Error>
|
||||
where
|
||||
C: StaticEventContent + StaticStateEventContent + RedactContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False>
|
||||
+ StaticStateEventContent
|
||||
+ RedactContent,
|
||||
C::StateKey: Borrow<K>,
|
||||
C::Redacted: RedactedStateEventContent,
|
||||
K: AsRef<str> + Sized + Sync + 'a,
|
||||
@@ -876,7 +884,7 @@ pub trait StateStoreExt: StateStore {
|
||||
&self,
|
||||
) -> Result<Option<Raw<GlobalAccountDataEvent<C>>>, Self::Error>
|
||||
where
|
||||
C: StaticEventContent + GlobalAccountDataEventContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False> + GlobalAccountDataEventContent,
|
||||
{
|
||||
Ok(self.get_account_data_event(C::TYPE.into()).await?.map(Raw::cast_unchecked))
|
||||
}
|
||||
@@ -893,7 +901,7 @@ pub trait StateStoreExt: StateStore {
|
||||
room_id: &RoomId,
|
||||
) -> Result<Option<Raw<RoomAccountDataEvent<C>>>, Self::Error>
|
||||
where
|
||||
C: StaticEventContent + RoomAccountDataEventContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False> + RoomAccountDataEventContent,
|
||||
{
|
||||
Ok(self
|
||||
.get_room_account_data_event(room_id, C::TYPE.into())
|
||||
|
||||
@@ -722,7 +722,7 @@ impl Account {
|
||||
/// ```
|
||||
pub async fn account_data<C>(&self) -> Result<Option<Raw<C>>>
|
||||
where
|
||||
C: GlobalAccountDataEventContent + StaticEventContent,
|
||||
C: GlobalAccountDataEventContent + StaticEventContent<IsPrefix = ruma::events::False>,
|
||||
{
|
||||
get_raw_content(self.client.state_store().get_account_data_event_static::<C>().await?)
|
||||
}
|
||||
@@ -785,7 +785,7 @@ impl Account {
|
||||
/// Fetch an account data event of statically-known type from the server.
|
||||
pub async fn fetch_account_data_static<C>(&self) -> Result<Option<Raw<C>>>
|
||||
where
|
||||
C: GlobalAccountDataEventContent + StaticEventContent,
|
||||
C: GlobalAccountDataEventContent + StaticEventContent<IsPrefix = ruma::events::False>,
|
||||
{
|
||||
Ok(self.fetch_account_data(C::TYPE.into()).await?.map(Raw::cast_unchecked))
|
||||
}
|
||||
|
||||
@@ -1017,7 +1017,9 @@ impl Room {
|
||||
/// ```
|
||||
pub async fn get_state_events_static<C>(&self) -> Result<Vec<RawSyncOrStrippedState<C>>>
|
||||
where
|
||||
C: StaticEventContent + StaticStateEventContent + RedactContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False>
|
||||
+ StaticStateEventContent
|
||||
+ RedactContent,
|
||||
C::Redacted: RedactedStateEventContent,
|
||||
{
|
||||
Ok(self.client.state_store().get_state_events_static(self.room_id()).await?)
|
||||
@@ -1061,7 +1063,9 @@ impl Room {
|
||||
state_keys: I,
|
||||
) -> Result<Vec<RawSyncOrStrippedState<C>>>
|
||||
where
|
||||
C: StaticEventContent + StaticStateEventContent + RedactContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False>
|
||||
+ StaticStateEventContent
|
||||
+ RedactContent,
|
||||
C::StateKey: Borrow<K>,
|
||||
C::Redacted: RedactedStateEventContent,
|
||||
K: AsRef<str> + Sized + Sync + 'a,
|
||||
@@ -1108,7 +1112,9 @@ impl Room {
|
||||
/// ```
|
||||
pub async fn get_state_event_static<C>(&self) -> Result<Option<RawSyncOrStrippedState<C>>>
|
||||
where
|
||||
C: StaticEventContent + StaticStateEventContent<StateKey = EmptyStateKey> + RedactContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False>
|
||||
+ StaticStateEventContent<StateKey = EmptyStateKey>
|
||||
+ RedactContent,
|
||||
C::Redacted: RedactedStateEventContent,
|
||||
{
|
||||
self.get_state_event_static_for_key(&EmptyStateKey).await
|
||||
@@ -1138,7 +1144,9 @@ impl Room {
|
||||
state_key: &K,
|
||||
) -> Result<Option<RawSyncOrStrippedState<C>>>
|
||||
where
|
||||
C: StaticEventContent + StaticStateEventContent + RedactContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False>
|
||||
+ StaticStateEventContent
|
||||
+ RedactContent,
|
||||
C::StateKey: Borrow<K>,
|
||||
C::Redacted: RedactedStateEventContent,
|
||||
K: AsRef<str> + ?Sized + Sync,
|
||||
@@ -1257,7 +1265,7 @@ impl Room {
|
||||
/// ```
|
||||
pub async fn account_data_static<C>(&self) -> Result<Option<Raw<RoomAccountDataEvent<C>>>>
|
||||
where
|
||||
C: StaticEventContent + RoomAccountDataEventContent,
|
||||
C: StaticEventContent<IsPrefix = ruma::events::False> + RoomAccountDataEventContent,
|
||||
{
|
||||
Ok(self.account_data(C::TYPE.into()).await?.map(Raw::cast_unchecked))
|
||||
}
|
||||
|
||||
@@ -29,8 +29,9 @@ use ruma::{
|
||||
TransactionId, UInt, UserId, VoipVersionId,
|
||||
events::{
|
||||
AnyStateEvent, AnySyncMessageLikeEvent, AnySyncStateEvent, AnySyncTimelineEvent,
|
||||
AnyTimelineEvent, BundledMessageLikeRelations, Mentions, RedactedMessageLikeEventContent,
|
||||
RedactedStateEventContent, StateEventContent, StaticEventContent,
|
||||
AnyTimelineEvent, BundledMessageLikeRelations, False, Mentions,
|
||||
RedactedMessageLikeEventContent, RedactedStateEventContent, StateEventContent,
|
||||
StaticEventContent,
|
||||
beacon::BeaconEventContent,
|
||||
call::{
|
||||
SessionDescription,
|
||||
@@ -143,7 +144,7 @@ impl<C: StaticEventContent> Default for Unsigned<C> {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EventBuilder<C: StaticEventContent> {
|
||||
pub struct EventBuilder<C: StaticEventContent<IsPrefix = False>> {
|
||||
sender: Option<OwnedUserId>,
|
||||
/// Whether the event is an ephemeral one. As such, it doesn't require a
|
||||
/// room id or a sender.
|
||||
@@ -159,7 +160,7 @@ pub struct EventBuilder<C: StaticEventContent> {
|
||||
state_key: Option<String>,
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent> EventBuilder<E> {
|
||||
impl<E: StaticEventContent<IsPrefix = False>> EventBuilder<E> {
|
||||
pub fn room(mut self, room_id: &RoomId) -> Self {
|
||||
self.room = Some(room_id.to_owned());
|
||||
self
|
||||
@@ -243,7 +244,7 @@ impl<E: StaticEventContent> EventBuilder<E> {
|
||||
|
||||
impl<E> EventBuilder<E>
|
||||
where
|
||||
E: StaticEventContent + Serialize,
|
||||
E: StaticEventContent<IsPrefix = False> + Serialize,
|
||||
{
|
||||
#[inline(always)]
|
||||
fn construct_json(self, requires_room: bool) -> serde_json::Value {
|
||||
@@ -460,7 +461,7 @@ impl EventBuilder<StickerEventContent> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent> From<EventBuilder<E>> for Raw<AnySyncTimelineEvent>
|
||||
impl<E: StaticEventContent<IsPrefix = False>> From<EventBuilder<E>> for Raw<AnySyncTimelineEvent>
|
||||
where
|
||||
E: Serialize,
|
||||
{
|
||||
@@ -469,7 +470,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent> From<EventBuilder<E>> for Raw<AnyTimelineEvent>
|
||||
impl<E: StaticEventContent<IsPrefix = False>> From<EventBuilder<E>> for Raw<AnyTimelineEvent>
|
||||
where
|
||||
E: Serialize,
|
||||
{
|
||||
@@ -478,7 +479,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent> From<EventBuilder<E>> for TimelineEvent
|
||||
impl<E: StaticEventContent<IsPrefix = False>> From<EventBuilder<E>> for TimelineEvent
|
||||
where
|
||||
E: Serialize,
|
||||
{
|
||||
@@ -487,13 +488,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent + StateEventContent> From<EventBuilder<E>> for Raw<AnySyncStateEvent> {
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for Raw<AnySyncStateEvent>
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::new(&val.construct_json(false)).unwrap().cast_unchecked()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: StaticEventContent + StateEventContent> From<EventBuilder<E>> for Raw<AnyStateEvent> {
|
||||
impl<E: StaticEventContent<IsPrefix = False> + StateEventContent> From<EventBuilder<E>>
|
||||
for Raw<AnyStateEvent>
|
||||
{
|
||||
fn from(val: EventBuilder<E>) -> Self {
|
||||
Raw::new(&val.construct_json(true)).unwrap().cast_unchecked()
|
||||
}
|
||||
@@ -531,7 +536,7 @@ impl EventFactory {
|
||||
}
|
||||
|
||||
/// Create an event from any event content.
|
||||
pub fn event<E: StaticEventContent>(&self, content: E) -> EventBuilder<E> {
|
||||
pub fn event<E: StaticEventContent<IsPrefix = False>>(&self, content: E) -> EventBuilder<E> {
|
||||
EventBuilder {
|
||||
sender: self.sender.clone(),
|
||||
is_ephemeral: false,
|
||||
@@ -701,7 +706,7 @@ impl EventFactory {
|
||||
|
||||
/// Create a redacted event, with extra information in the unsigned section
|
||||
/// about the redaction itself.
|
||||
pub fn redacted<T: StaticEventContent + RedactedMessageLikeEventContent>(
|
||||
pub fn redacted<T: StaticEventContent<IsPrefix = False> + RedactedMessageLikeEventContent>(
|
||||
&self,
|
||||
redacter: &UserId,
|
||||
content: T,
|
||||
@@ -722,7 +727,7 @@ impl EventFactory {
|
||||
|
||||
/// Create a redacted state event, with extra information in the unsigned
|
||||
/// section about the redaction itself.
|
||||
pub fn redacted_state<T: StaticEventContent + RedactedStateEventContent>(
|
||||
pub fn redacted_state<T: StaticEventContent<IsPrefix = False> + RedactedStateEventContent>(
|
||||
&self,
|
||||
redacter: &UserId,
|
||||
state_key: impl Into<String>,
|
||||
|
||||
Reference in New Issue
Block a user