Merge pull request #12 from morguldir/accountdata

accountdata: add an enum to allow returning both global and room accountdata
This commit is contained in:
June 🍓🦴 2024-08-30 07:41:44 -04:00 committed by GitHub
commit d7ddcd036f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,6 +10,8 @@ use ruma_macros::Event;
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize}; use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize};
use serde_json::value::RawValue as RawJsonValue; use serde_json::value::RawValue as RawJsonValue;
use crate::{AnyGlobalAccountDataEvent, AnyRoomAccountDataEvent};
use super::{ use super::{
AnyInitialStateEvent, EmptyStateKey, EphemeralRoomEventContent, EventContent, AnyInitialStateEvent, EmptyStateKey, EphemeralRoomEventContent, EventContent,
EventContentFromType, GlobalAccountDataEventContent, MessageLikeEventContent, EventContentFromType, GlobalAccountDataEventContent, MessageLikeEventContent,
@ -19,6 +21,26 @@ use super::{
ToDeviceEventContent, ToDeviceEventContent,
}; };
/// Enum allowing to use the same structures for global and room account data
#[derive(Debug)]
#[allow(clippy::exhaustive_enums)]
pub enum AnyAccountDataEvent {
/// An event for a specific room
Room(AnyRoomAccountDataEvent),
/// An event for the whole account
Global(AnyGlobalAccountDataEvent),
}
/// Enum allowing to use the same structures for global and room account data
#[derive(Debug)]
#[allow(clippy::exhaustive_enums)]
pub enum AnyRawAccountDataEvent {
/// An event for a specific room
Room(Raw<AnyRoomAccountDataEvent>),
/// An event for the whole account
Global(Raw<AnyGlobalAccountDataEvent>),
}
/// A global account data event. /// A global account data event.
#[derive(Clone, Debug, Event)] #[derive(Clone, Debug, Event)]
pub struct GlobalAccountDataEvent<C: GlobalAccountDataEventContent> { pub struct GlobalAccountDataEvent<C: GlobalAccountDataEventContent> {