Make room_id optional
This field can be absent in some contextes, notably in the responses to the /sync endpoint, where the events are summarised in the initial sync of a client. Fixes #19
This commit is contained in:
parent
6240c25160
commit
e9fc9b03fd
@ -214,7 +214,10 @@ pub trait RoomEvent: Event {
|
|||||||
fn origin_server_ts(&self) -> u64;
|
fn origin_server_ts(&self) -> u64;
|
||||||
|
|
||||||
/// The unique identifier for the room associated with this event.
|
/// The unique identifier for the room associated with this event.
|
||||||
fn room_id(&self) -> &RoomId;
|
///
|
||||||
|
/// This can be `None` if the event came from a context where there is
|
||||||
|
/// no ambiguity which room it belongs to, like a `/sync` response for example.
|
||||||
|
fn room_id(&self) -> Option<&RoomId>;
|
||||||
|
|
||||||
/// The unique identifier for the user who sent this event.
|
/// The unique identifier for the user who sent this event.
|
||||||
fn sender(&self) -> &UserId;
|
fn sender(&self) -> &UserId;
|
||||||
|
@ -94,7 +94,8 @@ macro_rules! room_event {
|
|||||||
pub origin_server_ts: u64,
|
pub origin_server_ts: u64,
|
||||||
|
|
||||||
/// The unique identifier for the room associated with this event.
|
/// The unique identifier for the room associated with this event.
|
||||||
pub room_id: ::ruma_identifiers::RoomId,
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
|
pub room_id: Option<::ruma_identifiers::RoomId>,
|
||||||
|
|
||||||
/// Additional key-value pairs not signed by the homeserver.
|
/// Additional key-value pairs not signed by the homeserver.
|
||||||
#[serde(skip_serializing_if="Option::is_none")]
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
@ -126,8 +127,8 @@ macro_rules! impl_room_event {
|
|||||||
self.origin_server_ts
|
self.origin_server_ts
|
||||||
}
|
}
|
||||||
|
|
||||||
fn room_id(&self) -> &::ruma_identifiers::RoomId {
|
fn room_id(&self) -> Option<&::ruma_identifiers::RoomId> {
|
||||||
&self.room_id
|
self.room_id.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unsigned(&self) -> Option<&::serde_json::Value> {
|
fn unsigned(&self) -> Option<&::serde_json::Value> {
|
||||||
@ -172,7 +173,8 @@ macro_rules! state_event {
|
|||||||
pub prev_content: Option<$content_type>,
|
pub prev_content: Option<$content_type>,
|
||||||
|
|
||||||
/// The unique identifier for the room associated with this event.
|
/// The unique identifier for the room associated with this event.
|
||||||
pub room_id: ::ruma_identifiers::RoomId,
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
|
pub room_id: Option<::ruma_identifiers::RoomId>,
|
||||||
|
|
||||||
/// A key that determines which piece of room state the event represents.
|
/// A key that determines which piece of room state the event represents.
|
||||||
pub state_key: String,
|
pub state_key: String,
|
||||||
|
@ -8,7 +8,11 @@ event! {
|
|||||||
/// Informs the client of new receipts.
|
/// Informs the client of new receipts.
|
||||||
pub struct ReceiptEvent(ReceiptEventContent) {
|
pub struct ReceiptEvent(ReceiptEventContent) {
|
||||||
/// The unique identifier for the room associated with this event.
|
/// The unique identifier for the room associated with this event.
|
||||||
pub room_id: RoomId
|
///
|
||||||
|
/// This can be `None` if the event came from a context where there is
|
||||||
|
/// no ambiguity which room it belongs to, like a `/sync` response for example.
|
||||||
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
|
pub room_id: Option<RoomId>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ mod tests {
|
|||||||
event_type: EventType::RoomPinnedEvents,
|
event_type: EventType::RoomPinnedEvents,
|
||||||
origin_server_ts: 1432804485886,
|
origin_server_ts: 1432804485886,
|
||||||
prev_content: None,
|
prev_content: None,
|
||||||
room_id: RoomId::new("example.com").unwrap(),
|
room_id: Some(RoomId::new("example.com").unwrap()),
|
||||||
sender: UserId::new("example.com").unwrap(),
|
sender: UserId::new("example.com").unwrap(),
|
||||||
state_key: "".to_string(),
|
state_key: "".to_string(),
|
||||||
unsigned: None,
|
unsigned: None,
|
||||||
|
@ -6,7 +6,11 @@ event! {
|
|||||||
/// Informs the client of the list of users currently typing.
|
/// Informs the client of the list of users currently typing.
|
||||||
pub struct TypingEvent(TypingEventContent) {
|
pub struct TypingEvent(TypingEventContent) {
|
||||||
/// The unique identifier for the room associated with this event.
|
/// The unique identifier for the room associated with this event.
|
||||||
pub room_id: RoomId
|
///
|
||||||
|
/// This can be `None` if the event came from a context where there is
|
||||||
|
/// no ambiguity which room it belongs to, like a `/sync` response for example.
|
||||||
|
#[serde(skip_serializing_if="Option::is_none")]
|
||||||
|
pub room_id: Option<RoomId>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user