|
|
|
@ -14,6 +14,7 @@ use ruma_client_api::{
|
|
|
|
|
alias::{create_alias, delete_alias, get_alias},
|
|
|
|
|
capabilities::get_capabilities,
|
|
|
|
|
config::{get_global_account_data, set_global_account_data},
|
|
|
|
|
context::get_context,
|
|
|
|
|
device::{self, delete_device, delete_devices, get_device, get_devices, update_device},
|
|
|
|
|
directory::{
|
|
|
|
|
self, get_public_rooms, get_public_rooms_filtered, get_room_visibility,
|
|
|
|
@ -200,7 +201,7 @@ pub fn register_route(
|
|
|
|
|
content: ruma_events::push_rules::PushRulesEventContent {
|
|
|
|
|
global: ruma_events::push_rules::Ruleset {
|
|
|
|
|
content: vec![],
|
|
|
|
|
override_rules: vec![ruma_events::push_rules::ConditionalPushRule {
|
|
|
|
|
override_: vec![ruma_events::push_rules::ConditionalPushRule {
|
|
|
|
|
actions: vec![ruma_events::push_rules::Action::DontNotify],
|
|
|
|
|
default: true,
|
|
|
|
|
enabled: false,
|
|
|
|
@ -219,12 +220,10 @@ pub fn register_route(
|
|
|
|
|
default: true,
|
|
|
|
|
enabled: true,
|
|
|
|
|
rule_id: ".m.rule.message".to_owned(),
|
|
|
|
|
conditions: vec![ruma_events::push_rules::PushCondition::EventMatch(
|
|
|
|
|
ruma_events::push_rules::EventMatchCondition {
|
|
|
|
|
conditions: vec![ruma_events::push_rules::PushCondition::EventMatch {
|
|
|
|
|
key: "type".to_owned(),
|
|
|
|
|
pattern: "m.room.message".to_owned(),
|
|
|
|
|
},
|
|
|
|
|
)],
|
|
|
|
|
}],
|
|
|
|
|
}],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
@ -348,11 +347,11 @@ pub fn logout_route(
|
|
|
|
|
pub fn get_capabilities_route() -> MatrixResult<get_capabilities::Response> {
|
|
|
|
|
let mut available = BTreeMap::new();
|
|
|
|
|
available.insert(
|
|
|
|
|
"5".to_owned(),
|
|
|
|
|
RoomVersionId::version_5(),
|
|
|
|
|
get_capabilities::RoomVersionStability::Stable,
|
|
|
|
|
);
|
|
|
|
|
available.insert(
|
|
|
|
|
"6".to_owned(),
|
|
|
|
|
RoomVersionId::version_6(),
|
|
|
|
|
get_capabilities::RoomVersionStability::Stable,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
@ -374,7 +373,6 @@ pub fn get_pushrules_all_route(
|
|
|
|
|
body: Ruma<get_pushrules_all::Request>,
|
|
|
|
|
) -> MatrixResult<get_pushrules_all::Response> {
|
|
|
|
|
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
|
|
|
|
warn!("TODO: get_pushrules_all_route");
|
|
|
|
|
|
|
|
|
|
if let Some(EduEvent::PushRules(pushrules)) = db
|
|
|
|
|
.account_data
|
|
|
|
@ -383,7 +381,7 @@ pub fn get_pushrules_all_route(
|
|
|
|
|
.map(|edu| edu.deserialize().expect("PushRules event in db is valid"))
|
|
|
|
|
{
|
|
|
|
|
MatrixResult(Ok(get_pushrules_all::Response {
|
|
|
|
|
global: BTreeMap::new(),
|
|
|
|
|
global: pushrules.content.global
|
|
|
|
|
}))
|
|
|
|
|
} else {
|
|
|
|
|
MatrixResult(Err(Error {
|
|
|
|
@ -2092,9 +2090,15 @@ pub fn sync_route(
|
|
|
|
|
.unwrap()
|
|
|
|
|
> since
|
|
|
|
|
{
|
|
|
|
|
edus.push(serde_json::from_str(&serde_json::to_string(
|
|
|
|
|
&EduEvent::Typing(db.rooms.edus.roomactives_all(&room_id).unwrap()),
|
|
|
|
|
).unwrap()).unwrap());
|
|
|
|
|
edus.push(
|
|
|
|
|
serde_json::from_str(
|
|
|
|
|
&serde_json::to_string(&EduEvent::Typing(
|
|
|
|
|
db.rooms.edus.roomactives_all(&room_id).unwrap(),
|
|
|
|
|
))
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
joined_rooms.insert(
|
|
|
|
@ -2170,9 +2174,15 @@ pub fn sync_route(
|
|
|
|
|
.unwrap()
|
|
|
|
|
> since
|
|
|
|
|
{
|
|
|
|
|
edus.push(serde_json::from_str(&serde_json::to_string(
|
|
|
|
|
&EduEvent::Typing(db.rooms.edus.roomactives_all(&room_id).unwrap()),
|
|
|
|
|
).unwrap()).unwrap());
|
|
|
|
|
edus.push(
|
|
|
|
|
serde_json::from_str(
|
|
|
|
|
&serde_json::to_string(&EduEvent::Typing(
|
|
|
|
|
db.rooms.edus.roomactives_all(&room_id).unwrap(),
|
|
|
|
|
))
|
|
|
|
|
.unwrap(),
|
|
|
|
|
)
|
|
|
|
|
.unwrap(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
left_rooms.insert(
|
|
|
|
@ -2271,6 +2281,93 @@ pub fn sync_route(
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[get(
|
|
|
|
|
"/_matrix/client/r0/rooms/<_room_id>/context/<_event_id>",
|
|
|
|
|
data = "<body>"
|
|
|
|
|
)]
|
|
|
|
|
pub fn get_context_route(
|
|
|
|
|
db: State<'_, Database>,
|
|
|
|
|
body: Ruma<get_context::Request>,
|
|
|
|
|
_room_id: String,
|
|
|
|
|
_event_id: String,
|
|
|
|
|
) -> MatrixResult<get_context::Response> {
|
|
|
|
|
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
|
|
|
|
|
|
|
|
|
if !db.rooms.is_joined(user_id, &body.room_id).unwrap() {
|
|
|
|
|
return MatrixResult(Err(Error {
|
|
|
|
|
kind: ErrorKind::Forbidden,
|
|
|
|
|
message: "You don't have permission to view this room.".to_owned(),
|
|
|
|
|
status_code: http::StatusCode::BAD_REQUEST,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let Some(base_event) = db.rooms.get_pdu(&body.event_id).unwrap() {
|
|
|
|
|
let base_event = base_event
|
|
|
|
|
.to_room_event();
|
|
|
|
|
|
|
|
|
|
let base_token = db
|
|
|
|
|
.rooms
|
|
|
|
|
.get_pdu_count(&body.event_id)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.expect("event exists, so count should exist too");
|
|
|
|
|
|
|
|
|
|
let events_before = db
|
|
|
|
|
.rooms
|
|
|
|
|
.pdus_until(&body.room_id, base_token)
|
|
|
|
|
.take(u32::try_from(body.limit).unwrap() as usize / 2)
|
|
|
|
|
.map(|r| r.unwrap())
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
let start_token = events_before
|
|
|
|
|
.last()
|
|
|
|
|
.and_then(|e| db.rooms.get_pdu_count(&e.event_id).unwrap())
|
|
|
|
|
.map(|c| c.to_string());
|
|
|
|
|
|
|
|
|
|
let events_before = events_before
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|pdu| pdu.to_room_event())
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
let events_after = db
|
|
|
|
|
.rooms
|
|
|
|
|
.pdus_after(&body.room_id, base_token)
|
|
|
|
|
.take(u32::try_from(body.limit).unwrap() as usize / 2)
|
|
|
|
|
.map(|r| r.unwrap())
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
let end_token = events_after
|
|
|
|
|
.last()
|
|
|
|
|
.and_then(|e| db.rooms.get_pdu_count(&e.event_id).unwrap())
|
|
|
|
|
.map(|c| c.to_string());
|
|
|
|
|
|
|
|
|
|
let events_after = events_after
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|pdu| pdu.to_room_event())
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
MatrixResult(Ok(get_context::Response {
|
|
|
|
|
start: start_token,
|
|
|
|
|
end: end_token,
|
|
|
|
|
events_before,
|
|
|
|
|
event: Some(base_event),
|
|
|
|
|
events_after,
|
|
|
|
|
state: db // TODO: State at event
|
|
|
|
|
.rooms
|
|
|
|
|
.room_state(&body.room_id)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.values()
|
|
|
|
|
.map(|pdu| pdu.to_state_event())
|
|
|
|
|
.collect(),
|
|
|
|
|
}))
|
|
|
|
|
} else {
|
|
|
|
|
MatrixResult(Err(Error {
|
|
|
|
|
kind: ErrorKind::Unknown,
|
|
|
|
|
message: "Invalid base event.".to_owned(),
|
|
|
|
|
status_code: http::StatusCode::BAD_REQUEST,
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[get("/_matrix/client/r0/rooms/<_room_id>/messages", data = "<body>")]
|
|
|
|
|
pub fn get_message_events_route(
|
|
|
|
|
db: State<'_, Database>,
|
|
|
|
@ -2287,30 +2384,63 @@ pub fn get_message_events_route(
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let get_message_events::Direction::Forward = body.dir {
|
|
|
|
|
todo!();
|
|
|
|
|
}
|
|
|
|
|
match body.dir {
|
|
|
|
|
get_message_events::Direction::Forward => {
|
|
|
|
|
if let Ok(from) = body.from.clone().parse() {
|
|
|
|
|
let events_after = db
|
|
|
|
|
.rooms
|
|
|
|
|
.pdus_after(&body.room_id, from)
|
|
|
|
|
.take(body.limit.map(|l| l.try_into().unwrap()).unwrap_or(10_u32) as usize)
|
|
|
|
|
.map(|r| r.unwrap())
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
let end_token = events_after
|
|
|
|
|
.last()
|
|
|
|
|
.and_then(|e| db.rooms.get_pdu_count(&e.event_id).unwrap())
|
|
|
|
|
.map(|c| c.to_string());
|
|
|
|
|
|
|
|
|
|
let events_after = events_after
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|pdu| pdu.to_room_event())
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
MatrixResult(Ok(get_message_events::Response {
|
|
|
|
|
start: Some(body.from.clone()),
|
|
|
|
|
end: end_token,
|
|
|
|
|
chunk: events_after,
|
|
|
|
|
state: Vec::new(),
|
|
|
|
|
}))
|
|
|
|
|
} else {
|
|
|
|
|
MatrixResult(Err(Error {
|
|
|
|
|
kind: ErrorKind::Unknown,
|
|
|
|
|
message: "Invalid from.".to_owned(),
|
|
|
|
|
status_code: http::StatusCode::BAD_REQUEST,
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
get_message_events::Direction::Backward => {
|
|
|
|
|
if let Ok(from) = body.from.clone().parse() {
|
|
|
|
|
let pdus = db
|
|
|
|
|
let events_before = db
|
|
|
|
|
.rooms
|
|
|
|
|
.pdus_until(&body.room_id, from)
|
|
|
|
|
.take(body.limit.map(|l| l.try_into().unwrap()).unwrap_or(10_u32) as usize)
|
|
|
|
|
.map(|r| r.unwrap())
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
let prev_batch = pdus
|
|
|
|
|
|
|
|
|
|
let start_token = events_before
|
|
|
|
|
.last()
|
|
|
|
|
.and_then(|e| db.rooms.get_pdu_count(&e.event_id).unwrap())
|
|
|
|
|
.map(|c| c.to_string());
|
|
|
|
|
let room_events = pdus
|
|
|
|
|
|
|
|
|
|
let events_before = events_before
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|pdu| pdu.to_room_event())
|
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
|
|
MatrixResult(Ok(get_message_events::Response {
|
|
|
|
|
start: Some(body.from.clone()),
|
|
|
|
|
end: prev_batch,
|
|
|
|
|
chunk: room_events,
|
|
|
|
|
end: start_token,
|
|
|
|
|
chunk: events_before,
|
|
|
|
|
state: Vec::new(),
|
|
|
|
|
}))
|
|
|
|
|
} else {
|
|
|
|
@ -2320,6 +2450,9 @@ pub fn get_message_events_route(
|
|
|
|
|
status_code: http::StatusCode::BAD_REQUEST,
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[get("/_matrix/client/r0/voip/turnServer")]
|
|
|
|
|