|
|
|
@ -5,16 +5,16 @@ use rocket::{get, options, post, put, State}; |
|
|
|
use ruma_client_api::{ |
|
|
|
use ruma_client_api::{ |
|
|
|
error::{Error, ErrorKind}, |
|
|
|
error::{Error, ErrorKind}, |
|
|
|
r0::{ |
|
|
|
r0::{ |
|
|
|
account::{ |
|
|
|
account::register, |
|
|
|
register, AuthenticationFlow, UserInteractiveAuthenticationInfo, |
|
|
|
|
|
|
|
UserInteractiveAuthenticationResponse, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
alias::get_alias, |
|
|
|
alias::get_alias, |
|
|
|
|
|
|
|
capabilities::get_capabilities, |
|
|
|
config::{get_global_account_data, set_global_account_data}, |
|
|
|
config::{get_global_account_data, set_global_account_data}, |
|
|
|
directory::{self, get_public_rooms_filtered}, |
|
|
|
directory::{self, get_public_rooms_filtered}, |
|
|
|
filter::{self, create_filter, get_filter}, |
|
|
|
filter::{self, create_filter, get_filter}, |
|
|
|
keys::{get_keys, upload_keys}, |
|
|
|
keys::{get_keys, upload_keys}, |
|
|
|
membership::{invite_user, join_room_by_id, join_room_by_id_or_alias}, |
|
|
|
membership::{ |
|
|
|
|
|
|
|
get_member_events, invite_user, join_room_by_id, join_room_by_id_or_alias, leave_room, |
|
|
|
|
|
|
|
}, |
|
|
|
message::create_message_event, |
|
|
|
message::create_message_event, |
|
|
|
presence::set_presence, |
|
|
|
presence::set_presence, |
|
|
|
profile::{ |
|
|
|
profile::{ |
|
|
|
@ -28,15 +28,20 @@ use ruma_client_api::{ |
|
|
|
sync::sync_events, |
|
|
|
sync::sync_events, |
|
|
|
thirdparty::get_protocols, |
|
|
|
thirdparty::get_protocols, |
|
|
|
typing::create_typing_event, |
|
|
|
typing::create_typing_event, |
|
|
|
|
|
|
|
uiaa::{AuthFlow, UiaaInfo, UiaaResponse}, |
|
|
|
user_directory::search_users, |
|
|
|
user_directory::search_users, |
|
|
|
}, |
|
|
|
}, |
|
|
|
unversioned::get_supported_versions, |
|
|
|
unversioned::get_supported_versions, |
|
|
|
}; |
|
|
|
}; |
|
|
|
use ruma_events::{collections::only::Event as EduEvent, EventType}; |
|
|
|
use ruma_events::{collections::only::Event as EduEvent, EventType}; |
|
|
|
use ruma_identifiers::{RoomId, RoomIdOrAliasId, UserId}; |
|
|
|
use ruma_identifiers::{RoomId, UserId}; |
|
|
|
use serde_json::json; |
|
|
|
use serde_json::json; |
|
|
|
use std::{collections::HashMap, convert::TryInto, path::PathBuf, time::Duration}; |
|
|
|
use std::{ |
|
|
|
use argon2::{Config, Variant}; |
|
|
|
collections::{BTreeMap, HashMap}, |
|
|
|
|
|
|
|
convert::{TryFrom, TryInto}, |
|
|
|
|
|
|
|
path::PathBuf, |
|
|
|
|
|
|
|
time::{Duration, SystemTime}, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const GUEST_NAME_LENGTH: usize = 10; |
|
|
|
const GUEST_NAME_LENGTH: usize = 10; |
|
|
|
const DEVICE_ID_LENGTH: usize = 10; |
|
|
|
const DEVICE_ID_LENGTH: usize = 10; |
|
|
|
@ -46,8 +51,8 @@ const TOKEN_LENGTH: usize = 256; |
|
|
|
#[get("/_matrix/client/versions")] |
|
|
|
#[get("/_matrix/client/versions")] |
|
|
|
pub fn get_supported_versions_route() -> MatrixResult<get_supported_versions::Response> { |
|
|
|
pub fn get_supported_versions_route() -> MatrixResult<get_supported_versions::Response> { |
|
|
|
MatrixResult(Ok(get_supported_versions::Response { |
|
|
|
MatrixResult(Ok(get_supported_versions::Response { |
|
|
|
versions: vec!["r0.6.0".to_owned()], |
|
|
|
versions: vec!["r0.5.0".to_owned(), "r0.6.0".to_owned()], |
|
|
|
unstable_features: HashMap::new(), |
|
|
|
unstable_features: BTreeMap::new(), |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -55,18 +60,17 @@ pub fn get_supported_versions_route() -> MatrixResult<get_supported_versions::Re |
|
|
|
pub fn register_route( |
|
|
|
pub fn register_route( |
|
|
|
data: State<Data>, |
|
|
|
data: State<Data>, |
|
|
|
body: Ruma<register::Request>, |
|
|
|
body: Ruma<register::Request>, |
|
|
|
) -> MatrixResult<register::Response, UserInteractiveAuthenticationResponse> { |
|
|
|
) -> MatrixResult<register::Response, UiaaResponse> { |
|
|
|
if body.auth.is_none() { |
|
|
|
if body.auth.is_none() { |
|
|
|
return MatrixResult(Err(UserInteractiveAuthenticationResponse::AuthResponse( |
|
|
|
return MatrixResult(Err(UiaaResponse::AuthResponse(UiaaInfo { |
|
|
|
UserInteractiveAuthenticationInfo { |
|
|
|
flows: vec![AuthFlow { |
|
|
|
flows: vec![AuthenticationFlow { |
|
|
|
stages: vec!["m.login.dummy".to_owned()], |
|
|
|
stages: vec!["m.login.dummy".to_owned()], |
|
|
|
}], |
|
|
|
}], |
|
|
|
completed: vec![], |
|
|
|
completed: vec![], |
|
|
|
params: json!({}), |
|
|
|
params: json!({}), |
|
|
|
session: Some(utils::random_string(SESSION_ID_LENGTH)), |
|
|
|
session: Some(utils::random_string(SESSION_ID_LENGTH)), |
|
|
|
auth_error: None, |
|
|
|
}, |
|
|
|
}))); |
|
|
|
))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Validate user id
|
|
|
|
// Validate user id
|
|
|
|
@ -81,13 +85,11 @@ pub fn register_route( |
|
|
|
{ |
|
|
|
{ |
|
|
|
Err(_) => { |
|
|
|
Err(_) => { |
|
|
|
debug!("Username invalid"); |
|
|
|
debug!("Username invalid"); |
|
|
|
return MatrixResult(Err(UserInteractiveAuthenticationResponse::MatrixError( |
|
|
|
return MatrixResult(Err(UiaaResponse::MatrixError(Error { |
|
|
|
Error { |
|
|
|
kind: ErrorKind::InvalidUsername, |
|
|
|
kind: ErrorKind::InvalidUsername, |
|
|
|
message: "Username was invalid.".to_owned(), |
|
|
|
message: "Username was invalid.".to_owned(), |
|
|
|
status_code: http::StatusCode::BAD_REQUEST, |
|
|
|
status_code: http::StatusCode::BAD_REQUEST, |
|
|
|
}))); |
|
|
|
}, |
|
|
|
|
|
|
|
))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Ok(user_id) => user_id, |
|
|
|
Ok(user_id) => user_id, |
|
|
|
}; |
|
|
|
}; |
|
|
|
@ -95,13 +97,11 @@ pub fn register_route( |
|
|
|
// Check if username is creative enough
|
|
|
|
// Check if username is creative enough
|
|
|
|
if data.user_exists(&user_id) { |
|
|
|
if data.user_exists(&user_id) { |
|
|
|
debug!("ID already taken"); |
|
|
|
debug!("ID already taken"); |
|
|
|
return MatrixResult(Err(UserInteractiveAuthenticationResponse::MatrixError( |
|
|
|
return MatrixResult(Err(UiaaResponse::MatrixError(Error { |
|
|
|
Error { |
|
|
|
kind: ErrorKind::UserInUse, |
|
|
|
kind: ErrorKind::UserInUse, |
|
|
|
message: "Desired user ID is already taken.".to_owned(), |
|
|
|
message: "Desired user ID is already taken.".to_owned(), |
|
|
|
status_code: http::StatusCode::BAD_REQUEST, |
|
|
|
status_code: http::StatusCode::BAD_REQUEST, |
|
|
|
}))); |
|
|
|
}, |
|
|
|
|
|
|
|
))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let password = body.password.clone().unwrap_or_default(); |
|
|
|
let password = body.password.clone().unwrap_or_default(); |
|
|
|
@ -110,13 +110,11 @@ pub fn register_route( |
|
|
|
// Create user
|
|
|
|
// Create user
|
|
|
|
data.user_add(&user_id, &hash); |
|
|
|
data.user_add(&user_id, &hash); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return MatrixResult(Err(UserInteractiveAuthenticationResponse::MatrixError( |
|
|
|
return MatrixResult(Err(UiaaResponse::MatrixError(Error { |
|
|
|
Error { |
|
|
|
kind: ErrorKind::InvalidParam, |
|
|
|
kind: ErrorKind::InvalidParam, |
|
|
|
message: "Password did not met requirements".to_owned(), |
|
|
|
message: "Password did not meet requirements".to_owned(), |
|
|
|
status_code: http::StatusCode::BAD_REQUEST, |
|
|
|
status_code: http::StatusCode::BAD_REQUEST, |
|
|
|
}))); |
|
|
|
}, |
|
|
|
|
|
|
|
))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Generate new device id if the user didn't specify one
|
|
|
|
// Generate new device id if the user didn't specify one
|
|
|
|
@ -158,8 +156,8 @@ pub fn login_route(data: State<Data>, body: Ruma<login::Request>) -> MatrixResul |
|
|
|
} |
|
|
|
} |
|
|
|
if let Ok(user_id) = (*username).try_into() { |
|
|
|
if let Ok(user_id) = (*username).try_into() { |
|
|
|
if let Some(hash) = data.password_hash_get(&user_id) { |
|
|
|
if let Some(hash) = data.password_hash_get(&user_id) { |
|
|
|
let hash_matches = argon2::verify_encoded(&hash, password.as_bytes()) |
|
|
|
let hash_matches = |
|
|
|
.unwrap_or(false); |
|
|
|
argon2::verify_encoded(&hash, password.as_bytes()).unwrap_or(false); |
|
|
|
|
|
|
|
|
|
|
|
if hash_matches { |
|
|
|
if hash_matches { |
|
|
|
// Success!
|
|
|
|
// Success!
|
|
|
|
@ -219,11 +217,25 @@ pub fn login_route(data: State<Data>, body: Ruma<login::Request>) -> MatrixResul |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[get("/_matrix/client/r0/capabilities", data = "<body>")] |
|
|
|
|
|
|
|
pub fn get_capabilities_route( |
|
|
|
|
|
|
|
body: Ruma<get_capabilities::Request>, |
|
|
|
|
|
|
|
) -> MatrixResult<get_capabilities::Response> { |
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
MatrixResult(Ok(get_capabilities::Response { |
|
|
|
|
|
|
|
capabilities: get_capabilities::Capabilities { |
|
|
|
|
|
|
|
change_password: None, |
|
|
|
|
|
|
|
room_versions: None, |
|
|
|
|
|
|
|
custom_capabilities: BTreeMap::new(), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
})) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[get("/_matrix/client/r0/pushrules")] |
|
|
|
#[get("/_matrix/client/r0/pushrules")] |
|
|
|
pub fn get_pushrules_all_route() -> MatrixResult<get_pushrules_all::Response> { |
|
|
|
pub fn get_pushrules_all_route() -> MatrixResult<get_pushrules_all::Response> { |
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
MatrixResult(Ok(get_pushrules_all::Response { |
|
|
|
MatrixResult(Ok(get_pushrules_all::Response { |
|
|
|
global: HashMap::new(), |
|
|
|
global: BTreeMap::new(), |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -447,8 +459,8 @@ pub fn set_presence_route( |
|
|
|
pub fn get_keys_route(body: Ruma<get_keys::Request>) -> MatrixResult<get_keys::Response> { |
|
|
|
pub fn get_keys_route(body: Ruma<get_keys::Request>) -> MatrixResult<get_keys::Response> { |
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
MatrixResult(Ok(get_keys::Response { |
|
|
|
MatrixResult(Ok(get_keys::Response { |
|
|
|
failures: HashMap::new(), |
|
|
|
failures: BTreeMap::new(), |
|
|
|
device_keys: HashMap::new(), |
|
|
|
device_keys: BTreeMap::new(), |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -459,7 +471,7 @@ pub fn upload_keys_route( |
|
|
|
) -> MatrixResult<upload_keys::Response> { |
|
|
|
) -> MatrixResult<upload_keys::Response> { |
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
MatrixResult(Ok(upload_keys::Response { |
|
|
|
MatrixResult(Ok(upload_keys::Response { |
|
|
|
one_time_key_counts: HashMap::new(), |
|
|
|
one_time_key_counts: BTreeMap::new(), |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -472,14 +484,14 @@ pub fn set_read_marker_route( |
|
|
|
let user_id = body.user_id.clone().expect("user is authenticated"); |
|
|
|
let user_id = body.user_id.clone().expect("user is authenticated"); |
|
|
|
// TODO: Fully read
|
|
|
|
// TODO: Fully read
|
|
|
|
if let Some(event) = &body.read_receipt { |
|
|
|
if let Some(event) = &body.read_receipt { |
|
|
|
let mut user_receipts = HashMap::new(); |
|
|
|
let mut user_receipts = BTreeMap::new(); |
|
|
|
user_receipts.insert( |
|
|
|
user_receipts.insert( |
|
|
|
user_id.clone(), |
|
|
|
user_id.clone(), |
|
|
|
ruma_events::receipt::Receipt { |
|
|
|
ruma_events::receipt::Receipt { |
|
|
|
ts: Some(utils::millis_since_unix_epoch().try_into().unwrap()), |
|
|
|
ts: Some(SystemTime::now()), |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
let mut receipt_content = HashMap::new(); |
|
|
|
let mut receipt_content = BTreeMap::new(); |
|
|
|
receipt_content.insert( |
|
|
|
receipt_content.insert( |
|
|
|
event.clone(), |
|
|
|
event.clone(), |
|
|
|
ruma_events::receipt::Receipts { |
|
|
|
ruma_events::receipt::Receipts { |
|
|
|
@ -537,7 +549,7 @@ pub fn create_room_route( |
|
|
|
body: Ruma<create_room::Request>, |
|
|
|
body: Ruma<create_room::Request>, |
|
|
|
) -> MatrixResult<create_room::Response> { |
|
|
|
) -> MatrixResult<create_room::Response> { |
|
|
|
// TODO: check if room is unique
|
|
|
|
// TODO: check if room is unique
|
|
|
|
let room_id = RoomId::new(data.hostname()).expect("host is valid"); |
|
|
|
let room_id = RoomId::try_from(data.hostname()).expect("host is valid"); |
|
|
|
let user_id = body.user_id.clone().expect("user is authenticated"); |
|
|
|
let user_id = body.user_id.clone().expect("user is authenticated"); |
|
|
|
|
|
|
|
|
|
|
|
data.pdu_append( |
|
|
|
data.pdu_append( |
|
|
|
@ -589,8 +601,6 @@ pub fn create_room_route( |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
dbg!(&*body); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.room_join(&room_id, &user_id); |
|
|
|
data.room_join(&room_id, &user_id); |
|
|
|
|
|
|
|
|
|
|
|
for user in &body.invite { |
|
|
|
for user in &body.invite { |
|
|
|
@ -651,8 +661,8 @@ pub fn join_room_by_id_or_alias_route( |
|
|
|
body: Ruma<join_room_by_id_or_alias::Request>, |
|
|
|
body: Ruma<join_room_by_id_or_alias::Request>, |
|
|
|
_room_id_or_alias: String, |
|
|
|
_room_id_or_alias: String, |
|
|
|
) -> MatrixResult<join_room_by_id_or_alias::Response> { |
|
|
|
) -> MatrixResult<join_room_by_id_or_alias::Response> { |
|
|
|
let room_id = match &body.room_id_or_alias { |
|
|
|
let room_id = if body.room_id_or_alias.is_room_alias_id() { |
|
|
|
RoomIdOrAliasId::RoomAliasId(alias) => match alias.alias() { |
|
|
|
match body.room_id_or_alias.as_ref() { |
|
|
|
"#room:localhost" => "!xclkjvdlfj:localhost".try_into().unwrap(), |
|
|
|
"#room:localhost" => "!xclkjvdlfj:localhost".try_into().unwrap(), |
|
|
|
_ => { |
|
|
|
_ => { |
|
|
|
debug!("Room not found."); |
|
|
|
debug!("Room not found."); |
|
|
|
@ -662,9 +672,9 @@ pub fn join_room_by_id_or_alias_route( |
|
|
|
status_code: http::StatusCode::NOT_FOUND, |
|
|
|
status_code: http::StatusCode::NOT_FOUND, |
|
|
|
})); |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
RoomIdOrAliasId::RoomId(id) => id.clone(), |
|
|
|
body.room_id_or_alias.try_into().unwrap() |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
if data.room_join( |
|
|
|
if data.room_join( |
|
|
|
@ -681,6 +691,17 @@ pub fn join_room_by_id_or_alias_route( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[post("/_matrix/client/r0/rooms/<_room_id>/leave", data = "<body>")] |
|
|
|
|
|
|
|
pub fn leave_room_route( |
|
|
|
|
|
|
|
data: State<Data>, |
|
|
|
|
|
|
|
body: Ruma<leave_room::Request>, |
|
|
|
|
|
|
|
_room_id: String, |
|
|
|
|
|
|
|
) -> MatrixResult<leave_room::Response> { |
|
|
|
|
|
|
|
let user_id = body.user_id.clone().expect("user is authenticated"); |
|
|
|
|
|
|
|
data.room_leave(&user_id, &body.room_id, &user_id); |
|
|
|
|
|
|
|
MatrixResult(Ok(leave_room::Response)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[post("/_matrix/client/r0/rooms/<_room_id>/invite", data = "<body>")] |
|
|
|
#[post("/_matrix/client/r0/rooms/<_room_id>/invite", data = "<body>")] |
|
|
|
pub fn invite_user_route( |
|
|
|
pub fn invite_user_route( |
|
|
|
data: State<Data>, |
|
|
|
data: State<Data>, |
|
|
|
@ -714,7 +735,7 @@ pub fn get_public_rooms_filtered_route( |
|
|
|
.map(|room_id| { |
|
|
|
.map(|room_id| { |
|
|
|
let state = data.room_state(&room_id); |
|
|
|
let state = data.room_state(&room_id); |
|
|
|
directory::PublicRoomsChunk { |
|
|
|
directory::PublicRoomsChunk { |
|
|
|
aliases: None, |
|
|
|
aliases: Vec::new(), |
|
|
|
canonical_alias: None, |
|
|
|
canonical_alias: None, |
|
|
|
name: state |
|
|
|
name: state |
|
|
|
.get(&(EventType::RoomName, "".to_owned())) |
|
|
|
.get(&(EventType::RoomName, "".to_owned())) |
|
|
|
@ -763,13 +784,22 @@ pub fn search_users_route( |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[get("/_matrix/client/r0/rooms/<_room_id>/members", data = "<body>")] |
|
|
|
|
|
|
|
pub fn get_member_events_route( |
|
|
|
|
|
|
|
body: Ruma<get_member_events::Request>, |
|
|
|
|
|
|
|
_room_id: String, |
|
|
|
|
|
|
|
) -> MatrixResult<get_member_events::Response> { |
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
MatrixResult(Ok(get_member_events::Response { chunk: Vec::new() })) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[get("/_matrix/client/r0/thirdparty/protocols", data = "<body>")] |
|
|
|
#[get("/_matrix/client/r0/thirdparty/protocols", data = "<body>")] |
|
|
|
pub fn get_protocols_route( |
|
|
|
pub fn get_protocols_route( |
|
|
|
body: Ruma<get_protocols::Request>, |
|
|
|
body: Ruma<get_protocols::Request>, |
|
|
|
) -> MatrixResult<get_protocols::Response> { |
|
|
|
) -> MatrixResult<get_protocols::Response> { |
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
MatrixResult(Ok(get_protocols::Response { |
|
|
|
MatrixResult(Ok(get_protocols::Response { |
|
|
|
protocols: HashMap::new(), |
|
|
|
protocols: BTreeMap::new(), |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -851,7 +881,7 @@ pub fn sync_route( |
|
|
|
std::thread::sleep(Duration::from_millis(200)); |
|
|
|
std::thread::sleep(Duration::from_millis(200)); |
|
|
|
let next_batch = data.last_pdu_index().to_string(); |
|
|
|
let next_batch = data.last_pdu_index().to_string(); |
|
|
|
|
|
|
|
|
|
|
|
let mut joined_rooms = HashMap::new(); |
|
|
|
let mut joined_rooms = BTreeMap::new(); |
|
|
|
let joined_roomids = data.rooms_joined(body.user_id.as_ref().expect("user is authenticated")); |
|
|
|
let joined_roomids = data.rooms_joined(body.user_id.as_ref().expect("user is authenticated")); |
|
|
|
let since = body |
|
|
|
let since = body |
|
|
|
.since |
|
|
|
.since |
|
|
|
@ -860,7 +890,11 @@ pub fn sync_route( |
|
|
|
.unwrap_or(0); |
|
|
|
.unwrap_or(0); |
|
|
|
for room_id in joined_roomids { |
|
|
|
for room_id in joined_roomids { |
|
|
|
let pdus = data.pdus_since(&room_id, since); |
|
|
|
let pdus = data.pdus_since(&room_id, since); |
|
|
|
let room_events = pdus.into_iter().map(|pdu| pdu.to_room_event()).collect(); |
|
|
|
let room_events = pdus |
|
|
|
|
|
|
|
.into_iter() |
|
|
|
|
|
|
|
.map(|pdu| pdu.to_room_event()) |
|
|
|
|
|
|
|
.filter_map(|e| e) |
|
|
|
|
|
|
|
.collect(); |
|
|
|
let mut edus = data.roomlatests_since(&room_id, since); |
|
|
|
let mut edus = data.roomlatests_since(&room_id, since); |
|
|
|
edus.extend_from_slice(&data.roomactives_in(&room_id)); |
|
|
|
edus.extend_from_slice(&data.roomactives_in(&room_id)); |
|
|
|
|
|
|
|
|
|
|
|
@ -888,7 +922,33 @@ pub fn sync_route( |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let mut invited_rooms = HashMap::new(); |
|
|
|
let mut left_rooms = BTreeMap::new(); |
|
|
|
|
|
|
|
let left_roomids = data.rooms_left(body.user_id.as_ref().expect("user is authenticated")); |
|
|
|
|
|
|
|
for room_id in left_roomids { |
|
|
|
|
|
|
|
let pdus = data.pdus_since(&room_id, since); |
|
|
|
|
|
|
|
let room_events = pdus |
|
|
|
|
|
|
|
.into_iter() |
|
|
|
|
|
|
|
.map(|pdu| pdu.to_room_event()) |
|
|
|
|
|
|
|
.filter_map(|e| e) |
|
|
|
|
|
|
|
.collect(); |
|
|
|
|
|
|
|
let mut edus = data.roomlatests_since(&room_id, since); |
|
|
|
|
|
|
|
edus.extend_from_slice(&data.roomactives_in(&room_id)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
left_rooms.insert( |
|
|
|
|
|
|
|
room_id.clone().try_into().unwrap(), |
|
|
|
|
|
|
|
sync_events::LeftRoom { |
|
|
|
|
|
|
|
account_data: sync_events::AccountData { events: Vec::new() }, |
|
|
|
|
|
|
|
timeline: sync_events::Timeline { |
|
|
|
|
|
|
|
limited: Some(false), |
|
|
|
|
|
|
|
prev_batch: Some("".to_owned()), |
|
|
|
|
|
|
|
events: room_events, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
state: sync_events::State { events: Vec::new() }, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut invited_rooms = BTreeMap::new(); |
|
|
|
for room_id in data.rooms_invited(body.user_id.as_ref().expect("user is authenticated")) { |
|
|
|
for room_id in data.rooms_invited(body.user_id.as_ref().expect("user is authenticated")) { |
|
|
|
let events = data |
|
|
|
let events = data |
|
|
|
.pdus_since(&room_id, since) |
|
|
|
.pdus_since(&room_id, since) |
|
|
|
@ -907,7 +967,7 @@ pub fn sync_route( |
|
|
|
MatrixResult(Ok(sync_events::Response { |
|
|
|
MatrixResult(Ok(sync_events::Response { |
|
|
|
next_batch, |
|
|
|
next_batch, |
|
|
|
rooms: sync_events::Rooms { |
|
|
|
rooms: sync_events::Rooms { |
|
|
|
leave: Default::default(), |
|
|
|
leave: left_rooms, |
|
|
|
join: joined_rooms, |
|
|
|
join: joined_rooms, |
|
|
|
invite: invited_rooms, |
|
|
|
invite: invited_rooms, |
|
|
|
}, |
|
|
|
}, |
|
|
|
|