pub mod v3 {
use ruma_common::{
OwnedRoomId,
api::{auth_scheme::AccessToken, request, response},
metadata,
serde::Raw,
};
use ruma_events::{
AnyRoomAccountDataEvent, AnyStateEvent, AnyTimelineEvent, room::member::MembershipState,
};
use serde::{Deserialize, Serialize};
use crate::room::Visibility;
metadata! {
method: GET,
rate_limited: false,
authentication: AccessToken,
history: {
1.0 => "/_matrix/client/r0/rooms/{room_id}/initialSync",
1.1 => "/_matrix/client/v3/rooms/{room_id}/initialSync",
}
}
#[request(error = crate::Error)]
pub struct Request {
#[ruma_api(path)]
pub room_id: OwnedRoomId,
}
impl Request {
pub fn new(room_id: OwnedRoomId) -> Self {
Self { room_id }
}
}
#[response(error = crate::Error)]
pub struct Response {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub account_data: Vec<Raw<AnyRoomAccountDataEvent>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub membership: Option<MembershipState>,
#[serde(skip_serializing_if = "Option::is_none")]
pub messages: Option<PaginationChunk>,
pub room_id: OwnedRoomId,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub state: Vec<Raw<AnyStateEvent>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub visibility: Option<Visibility>,
}
impl Response {
pub fn new(room_id: OwnedRoomId) -> Self {
Self {
room_id,
account_data: Vec::new(),
membership: None,
messages: None,
state: Vec::new(),
visibility: None,
}
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
#[cfg_attr(not(ruma_unstable_exhaustive_types), non_exhaustive)]
pub struct PaginationChunk {
pub chunk: Vec<Raw<AnyTimelineEvent>>,
pub end: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub start: Option<String>,
}
impl PaginationChunk {
pub fn new(chunk: Vec<Raw<AnyTimelineEvent>>, end: String) -> Self {
Self { chunk, end, start: None }
}
}
}