federation-api: Use fine-grained event type enums

This commit is contained in:
Jonas Platte 2022-03-15 16:46:20 +01:00
parent ce785064a9
commit 7e05351f58
No known key found for this signature in database
GPG Key ID: BBA95679259D342F
4 changed files with 18 additions and 14 deletions

View File

@ -4,7 +4,7 @@
use ruma_common::{
api::ruma_api,
events::{room::member::RoomMemberEventContent, AnyStrippedStateEvent, EventType},
events::{room::member::RoomMemberEventContent, AnyStrippedStateEvent, StateEventType},
serde::Raw,
EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, UserId,
};
@ -42,7 +42,7 @@ ruma_api! {
/// The value `m.room.member`.
#[serde(rename = "type")]
pub kind: EventType,
pub kind: StateEventType,
/// The user ID of the invited member.
pub state_key: &'a UserId,
@ -124,7 +124,7 @@ impl<'a> From<RequestInit<'a>> for Request<'a> {
sender: init.sender,
origin: init.origin,
origin_server_ts: init.origin_server_ts,
kind: EventType::RoomMember,
kind: StateEventType::RoomMember,
state_key: init.state_key,
content: init.content,
unsigned: init.unsigned,

View File

@ -5,7 +5,7 @@
use js_int::UInt;
use ruma_common::{
api::ruma_api,
events::{room::member::RoomMemberEventContent, EventType},
events::{room::member::RoomMemberEventContent, StateEventType},
serde::Raw,
EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, UserId,
};
@ -46,7 +46,7 @@ ruma_api! {
/// The value `m.room.member`.
#[ruma_api(query)]
#[serde(rename = "type")]
pub event_type: EventType,
pub event_type: StateEventType,
/// The user ID of the leaving member.
#[ruma_api(query)]
@ -95,7 +95,7 @@ pub struct RequestInit<'a> {
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
/// The value `m.room.member`.
pub event_type: EventType,
pub event_type: StateEventType,
/// The user ID of the leaving member.
pub state_key: &'a str,

View File

@ -13,7 +13,7 @@ pub mod v1 {
use ruma_common::{
api::ruma_api,
events::{room::member::ThirdPartyInvite, EventType},
events::{room::member::ThirdPartyInvite, StateEventType},
RoomId, UserId,
};
@ -35,9 +35,9 @@ pub mod v1 {
/// The event type.
///
/// Must be `EventType::RoomMember`.
/// Must be `StateEventType::RoomMember`.
#[serde(rename = "type")]
pub kind: EventType,
pub kind: StateEventType,
/// The user ID of the user who sent the original invite event.
pub sender: &'a UserId,
@ -61,7 +61,7 @@ pub mod v1 {
state_key: &'a UserId,
content: &'a ThirdPartyInvite,
) -> Self {
Self { room_id, kind: EventType::RoomMember, sender, state_key, content }
Self { room_id, kind: StateEventType::RoomMember, sender, state_key, content }
}
}

View File

@ -5,7 +5,7 @@ use std::collections::BTreeMap;
use js_int::UInt;
use ruma_common::{
encryption::{CrossSigningKey, DeviceKeys},
events::{receipt::Receipt, AnyToDeviceEventContent, EventType},
events::{receipt::Receipt, AnyToDeviceEventContent, ToDeviceEventType},
presence::PresenceState,
serde::{from_raw_json_value, Raw},
to_device::DeviceIdOrAllDevices,
@ -264,7 +264,7 @@ pub struct DirectDeviceContent {
/// Event type for the message.
#[serde(rename = "type")]
pub ev_type: EventType,
pub ev_type: ToDeviceEventType,
/// Unique utf8 string ID for the message, used for idempotency.
pub message_id: Box<TransactionId>,
@ -278,7 +278,11 @@ pub struct DirectDeviceContent {
impl DirectDeviceContent {
/// Creates a new `DirectDeviceContent` with the given `sender, `ev_type` and `message_id`.
pub fn new(sender: Box<UserId>, ev_type: EventType, message_id: Box<TransactionId>) -> Self {
pub fn new(
sender: Box<UserId>,
ev_type: ToDeviceEventType,
message_id: Box<TransactionId>,
) -> Self {
Self { sender, ev_type, message_id, messages: DirectDeviceMessages::new() }
}
}
@ -489,7 +493,7 @@ mod test {
Edu::DirectToDevice(DirectDeviceContent {
sender, ev_type, message_id, messages
}) if sender == "@john:example.com"
&& *ev_type == EventType::RoomKeyRequest
&& *ev_type == ToDeviceEventType::RoomKeyRequest
&& message_id == "hiezohf6Hoo7kaev"
&& messages.get(user_id!("@alice:example.org")).is_some()
);