federation-api: Use fine-grained event type enums
This commit is contained in:
parent
ce785064a9
commit
7e05351f58
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
api::ruma_api,
|
api::ruma_api,
|
||||||
events::{room::member::RoomMemberEventContent, AnyStrippedStateEvent, EventType},
|
events::{room::member::RoomMemberEventContent, AnyStrippedStateEvent, StateEventType},
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, UserId,
|
EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, UserId,
|
||||||
};
|
};
|
||||||
@ -42,7 +42,7 @@ ruma_api! {
|
|||||||
|
|
||||||
/// The value `m.room.member`.
|
/// The value `m.room.member`.
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub kind: EventType,
|
pub kind: StateEventType,
|
||||||
|
|
||||||
/// The user ID of the invited member.
|
/// The user ID of the invited member.
|
||||||
pub state_key: &'a UserId,
|
pub state_key: &'a UserId,
|
||||||
@ -124,7 +124,7 @@ impl<'a> From<RequestInit<'a>> for Request<'a> {
|
|||||||
sender: init.sender,
|
sender: init.sender,
|
||||||
origin: init.origin,
|
origin: init.origin,
|
||||||
origin_server_ts: init.origin_server_ts,
|
origin_server_ts: init.origin_server_ts,
|
||||||
kind: EventType::RoomMember,
|
kind: StateEventType::RoomMember,
|
||||||
state_key: init.state_key,
|
state_key: init.state_key,
|
||||||
content: init.content,
|
content: init.content,
|
||||||
unsigned: init.unsigned,
|
unsigned: init.unsigned,
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
api::ruma_api,
|
api::ruma_api,
|
||||||
events::{room::member::RoomMemberEventContent, EventType},
|
events::{room::member::RoomMemberEventContent, StateEventType},
|
||||||
serde::Raw,
|
serde::Raw,
|
||||||
EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, UserId,
|
EventId, MilliSecondsSinceUnixEpoch, RoomId, ServerName, UserId,
|
||||||
};
|
};
|
||||||
@ -46,7 +46,7 @@ ruma_api! {
|
|||||||
/// The value `m.room.member`.
|
/// The value `m.room.member`.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub event_type: EventType,
|
pub event_type: StateEventType,
|
||||||
|
|
||||||
/// The user ID of the leaving member.
|
/// The user ID of the leaving member.
|
||||||
#[ruma_api(query)]
|
#[ruma_api(query)]
|
||||||
@ -95,7 +95,7 @@ pub struct RequestInit<'a> {
|
|||||||
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
pub origin_server_ts: MilliSecondsSinceUnixEpoch,
|
||||||
|
|
||||||
/// The value `m.room.member`.
|
/// The value `m.room.member`.
|
||||||
pub event_type: EventType,
|
pub event_type: StateEventType,
|
||||||
|
|
||||||
/// The user ID of the leaving member.
|
/// The user ID of the leaving member.
|
||||||
pub state_key: &'a str,
|
pub state_key: &'a str,
|
||||||
|
@ -13,7 +13,7 @@ pub mod v1 {
|
|||||||
|
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
api::ruma_api,
|
api::ruma_api,
|
||||||
events::{room::member::ThirdPartyInvite, EventType},
|
events::{room::member::ThirdPartyInvite, StateEventType},
|
||||||
RoomId, UserId,
|
RoomId, UserId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -35,9 +35,9 @@ pub mod v1 {
|
|||||||
|
|
||||||
/// The event type.
|
/// The event type.
|
||||||
///
|
///
|
||||||
/// Must be `EventType::RoomMember`.
|
/// Must be `StateEventType::RoomMember`.
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub kind: EventType,
|
pub kind: StateEventType,
|
||||||
|
|
||||||
/// The user ID of the user who sent the original invite event.
|
/// The user ID of the user who sent the original invite event.
|
||||||
pub sender: &'a UserId,
|
pub sender: &'a UserId,
|
||||||
@ -61,7 +61,7 @@ pub mod v1 {
|
|||||||
state_key: &'a UserId,
|
state_key: &'a UserId,
|
||||||
content: &'a ThirdPartyInvite,
|
content: &'a ThirdPartyInvite,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self { room_id, kind: EventType::RoomMember, sender, state_key, content }
|
Self { room_id, kind: StateEventType::RoomMember, sender, state_key, content }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ use std::collections::BTreeMap;
|
|||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma_common::{
|
use ruma_common::{
|
||||||
encryption::{CrossSigningKey, DeviceKeys},
|
encryption::{CrossSigningKey, DeviceKeys},
|
||||||
events::{receipt::Receipt, AnyToDeviceEventContent, EventType},
|
events::{receipt::Receipt, AnyToDeviceEventContent, ToDeviceEventType},
|
||||||
presence::PresenceState,
|
presence::PresenceState,
|
||||||
serde::{from_raw_json_value, Raw},
|
serde::{from_raw_json_value, Raw},
|
||||||
to_device::DeviceIdOrAllDevices,
|
to_device::DeviceIdOrAllDevices,
|
||||||
@ -264,7 +264,7 @@ pub struct DirectDeviceContent {
|
|||||||
|
|
||||||
/// Event type for the message.
|
/// Event type for the message.
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub ev_type: EventType,
|
pub ev_type: ToDeviceEventType,
|
||||||
|
|
||||||
/// Unique utf8 string ID for the message, used for idempotency.
|
/// Unique utf8 string ID for the message, used for idempotency.
|
||||||
pub message_id: Box<TransactionId>,
|
pub message_id: Box<TransactionId>,
|
||||||
@ -278,7 +278,11 @@ pub struct DirectDeviceContent {
|
|||||||
|
|
||||||
impl DirectDeviceContent {
|
impl DirectDeviceContent {
|
||||||
/// Creates a new `DirectDeviceContent` with the given `sender, `ev_type` and `message_id`.
|
/// 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() }
|
Self { sender, ev_type, message_id, messages: DirectDeviceMessages::new() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -489,7 +493,7 @@ mod test {
|
|||||||
Edu::DirectToDevice(DirectDeviceContent {
|
Edu::DirectToDevice(DirectDeviceContent {
|
||||||
sender, ev_type, message_id, messages
|
sender, ev_type, message_id, messages
|
||||||
}) if sender == "@john:example.com"
|
}) if sender == "@john:example.com"
|
||||||
&& *ev_type == EventType::RoomKeyRequest
|
&& *ev_type == ToDeviceEventType::RoomKeyRequest
|
||||||
&& message_id == "hiezohf6Hoo7kaev"
|
&& message_id == "hiezohf6Hoo7kaev"
|
||||||
&& messages.get(user_id!("@alice:example.org")).is_some()
|
&& messages.get(user_id!("@alice:example.org")).is_some()
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user