|
|
|
@ -12,7 +12,6 @@ use ruma_client_api::{ |
|
|
|
account::{get_username_availability, register}, |
|
|
|
account::{get_username_availability, register}, |
|
|
|
alias::get_alias, |
|
|
|
alias::get_alias, |
|
|
|
capabilities::get_capabilities, |
|
|
|
capabilities::get_capabilities, |
|
|
|
to_device::send_event_to_device, |
|
|
|
|
|
|
|
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}, |
|
|
|
@ -34,13 +33,14 @@ use ruma_client_api::{ |
|
|
|
state::{create_state_event_for_empty_key, create_state_event_for_key}, |
|
|
|
state::{create_state_event_for_empty_key, create_state_event_for_key}, |
|
|
|
sync::sync_events, |
|
|
|
sync::sync_events, |
|
|
|
thirdparty::get_protocols, |
|
|
|
thirdparty::get_protocols, |
|
|
|
|
|
|
|
to_device::send_event_to_device, |
|
|
|
typing::create_typing_event, |
|
|
|
typing::create_typing_event, |
|
|
|
uiaa::{AuthFlow, UiaaInfo, UiaaResponse}, |
|
|
|
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, EventJson, EventType}; |
|
|
|
use ruma_identifiers::{RoomId, UserId}; |
|
|
|
use ruma_identifiers::{RoomId, UserId}; |
|
|
|
use serde_json::{json, value::RawValue}; |
|
|
|
use serde_json::{json, value::RawValue}; |
|
|
|
|
|
|
|
|
|
|
|
@ -165,13 +165,13 @@ pub fn register_route( |
|
|
|
let token = utils::random_string(TOKEN_LENGTH); |
|
|
|
let token = utils::random_string(TOKEN_LENGTH); |
|
|
|
|
|
|
|
|
|
|
|
// Add device
|
|
|
|
// Add device
|
|
|
|
db |
|
|
|
db.users |
|
|
|
.users |
|
|
|
|
|
|
|
.create_device(&user_id, &device_id, &token) |
|
|
|
.create_device(&user_id, &device_id, &token) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
// Initial data
|
|
|
|
// Initial data
|
|
|
|
db.account_data.update( |
|
|
|
db.account_data |
|
|
|
|
|
|
|
.update( |
|
|
|
None, |
|
|
|
None, |
|
|
|
&user_id, |
|
|
|
&user_id, |
|
|
|
EduEvent::PushRules(ruma_events::push_rules::PushRulesEvent { |
|
|
|
EduEvent::PushRules(ruma_events::push_rules::PushRulesEvent { |
|
|
|
@ -220,7 +220,10 @@ pub fn get_login_route() -> MatrixResult<get_login_types::Response> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[post("/_matrix/client/r0/login", data = "<body>")] |
|
|
|
#[post("/_matrix/client/r0/login", data = "<body>")] |
|
|
|
pub fn login_route(db: State<'_, Database>, body: Ruma<login::Request>) -> MatrixResult<login::Response> { |
|
|
|
pub fn login_route( |
|
|
|
|
|
|
|
db: State<'_, Database>, |
|
|
|
|
|
|
|
body: Ruma<login::Request>, |
|
|
|
|
|
|
|
) -> MatrixResult<login::Response> { |
|
|
|
// Validate login method
|
|
|
|
// Validate login method
|
|
|
|
let user_id = |
|
|
|
let user_id = |
|
|
|
if let (login::UserInfo::MatrixId(mut username), login::LoginInfo::Password { password }) = |
|
|
|
if let (login::UserInfo::MatrixId(mut username), login::LoginInfo::Password { password }) = |
|
|
|
@ -280,8 +283,7 @@ pub fn login_route(db: State<'_, Database>, body: Ruma<login::Request>) -> Matri |
|
|
|
let token = utils::random_string(TOKEN_LENGTH); |
|
|
|
let token = utils::random_string(TOKEN_LENGTH); |
|
|
|
|
|
|
|
|
|
|
|
// Add device
|
|
|
|
// Add device
|
|
|
|
db |
|
|
|
db.users |
|
|
|
.users |
|
|
|
|
|
|
|
.create_device(&user_id, &device_id, &token) |
|
|
|
.create_device(&user_id, &device_id, &token) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
@ -318,7 +320,7 @@ pub fn get_pushrules_all_route() -> MatrixResult<get_pushrules_all::Response> { |
|
|
|
vec![push::PushRule { |
|
|
|
vec![push::PushRule { |
|
|
|
actions: vec![ |
|
|
|
actions: vec![ |
|
|
|
push::Action::Notify, |
|
|
|
push::Action::Notify, |
|
|
|
push::Action::SetTweak(ruma_common::push::Tweak::Highlight(false)) |
|
|
|
push::Action::SetTweak(ruma_common::push::Tweak::Highlight(false)), |
|
|
|
], |
|
|
|
], |
|
|
|
default: true, |
|
|
|
default: true, |
|
|
|
enabled: true, |
|
|
|
enabled: true, |
|
|
|
@ -346,7 +348,8 @@ pub fn set_pushrule_route( |
|
|
|
) -> MatrixResult<set_pushrule::Response> { |
|
|
|
) -> MatrixResult<set_pushrule::Response> { |
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
let user_id = body.user_id.clone().expect("user is authenticated"); |
|
|
|
let user_id = body.user_id.clone().expect("user is authenticated"); |
|
|
|
db.account_data.update( |
|
|
|
db.account_data |
|
|
|
|
|
|
|
.update( |
|
|
|
None, |
|
|
|
None, |
|
|
|
&user_id, |
|
|
|
&user_id, |
|
|
|
EduEvent::PushRules(ruma_events::push_rules::PushRulesEvent { |
|
|
|
EduEvent::PushRules(ruma_events::push_rules::PushRulesEvent { |
|
|
|
@ -376,7 +379,7 @@ pub fn set_pushrule_route( |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}), |
|
|
|
}), |
|
|
|
&db.globals |
|
|
|
&db.globals, |
|
|
|
) |
|
|
|
) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
@ -393,9 +396,7 @@ pub fn set_pushrule_enabled_route( |
|
|
|
MatrixResult(Ok(set_pushrule_enabled::Response)) |
|
|
|
MatrixResult(Ok(set_pushrule_enabled::Response)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[get(
|
|
|
|
#[get("/_matrix/client/r0/user/<_user_id>/filter/<_filter_id>")] |
|
|
|
"/_matrix/client/r0/user/<_user_id>/filter/<_filter_id>", |
|
|
|
|
|
|
|
)] |
|
|
|
|
|
|
|
pub fn get_filter_route( |
|
|
|
pub fn get_filter_route( |
|
|
|
_user_id: String, |
|
|
|
_user_id: String, |
|
|
|
_filter_id: String, |
|
|
|
_filter_id: String, |
|
|
|
@ -413,18 +414,14 @@ pub fn get_filter_route( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[post("/_matrix/client/r0/user/<_user_id>/filter")] |
|
|
|
#[post("/_matrix/client/r0/user/<_user_id>/filter")] |
|
|
|
pub fn create_filter_route( |
|
|
|
pub fn create_filter_route(_user_id: String) -> MatrixResult<create_filter::Response> { |
|
|
|
_user_id: String, |
|
|
|
|
|
|
|
) -> MatrixResult<create_filter::Response> { |
|
|
|
|
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
MatrixResult(Ok(create_filter::Response { |
|
|
|
MatrixResult(Ok(create_filter::Response { |
|
|
|
filter_id: utils::random_string(10), |
|
|
|
filter_id: utils::random_string(10), |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[put(
|
|
|
|
#[put("/_matrix/client/r0/user/<_user_id>/account_data/<_type>")] |
|
|
|
"/_matrix/client/r0/user/<_user_id>/account_data/<_type>", |
|
|
|
|
|
|
|
)] |
|
|
|
|
|
|
|
pub fn set_global_account_data_route( |
|
|
|
pub fn set_global_account_data_route( |
|
|
|
_user_id: String, |
|
|
|
_user_id: String, |
|
|
|
_type: String, |
|
|
|
_type: String, |
|
|
|
@ -432,9 +429,7 @@ pub fn set_global_account_data_route( |
|
|
|
MatrixResult(Ok(set_global_account_data::Response)) |
|
|
|
MatrixResult(Ok(set_global_account_data::Response)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[get(
|
|
|
|
#[get("/_matrix/client/r0/user/<_user_id>/account_data/<_type>")] |
|
|
|
"/_matrix/client/r0/user/<_user_id>/account_data/<_type>", |
|
|
|
|
|
|
|
)] |
|
|
|
|
|
|
|
pub fn get_global_account_data_route( |
|
|
|
pub fn get_global_account_data_route( |
|
|
|
_user_id: String, |
|
|
|
_user_id: String, |
|
|
|
_type: String, |
|
|
|
_type: String, |
|
|
|
@ -460,25 +455,44 @@ pub fn set_displayname_route( |
|
|
|
if displayname == "" { |
|
|
|
if displayname == "" { |
|
|
|
db.users.set_displayname(&user_id, None).unwrap(); |
|
|
|
db.users.set_displayname(&user_id, None).unwrap(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
db |
|
|
|
db.users |
|
|
|
.users |
|
|
|
|
|
|
|
.set_displayname(&user_id, Some(displayname.clone())) |
|
|
|
.set_displayname(&user_id, Some(displayname.clone())) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Send a new membership event into all joined rooms
|
|
|
|
// Send a new membership event into all joined rooms
|
|
|
|
for room_id in db.rooms.rooms_joined(&user_id) { |
|
|
|
for room_id in db.rooms.rooms_joined(&user_id) { |
|
|
|
db.rooms.append_pdu( |
|
|
|
db.rooms |
|
|
|
|
|
|
|
.append_pdu( |
|
|
|
room_id.unwrap(), |
|
|
|
room_id.unwrap(), |
|
|
|
user_id.clone(), |
|
|
|
user_id.clone(), |
|
|
|
EventType::RoomMember, |
|
|
|
EventType::RoomMember, |
|
|
|
json!({"membership": "join", "displayname": displayname}), |
|
|
|
json!({"membership": "join", "displayname": displayname}), |
|
|
|
None, |
|
|
|
None, |
|
|
|
Some(user_id.to_string()), |
|
|
|
Some(user_id.to_string()), |
|
|
|
&db.globals |
|
|
|
&db.globals, |
|
|
|
).unwrap(); |
|
|
|
) |
|
|
|
|
|
|
|
.unwrap(); |
|
|
|
} |
|
|
|
} |
|
|
|
// TODO: send a new m.presence event
|
|
|
|
|
|
|
|
|
|
|
|
// Presence update
|
|
|
|
|
|
|
|
db.global_edus |
|
|
|
|
|
|
|
.update_globallatest( |
|
|
|
|
|
|
|
&user_id, |
|
|
|
|
|
|
|
EduEvent::Presence(ruma_events::presence::PresenceEvent { |
|
|
|
|
|
|
|
content: ruma_events::presence::PresenceEventContent { |
|
|
|
|
|
|
|
avatar_url: db.users.avatar_url(&user_id).unwrap(), |
|
|
|
|
|
|
|
currently_active: None, |
|
|
|
|
|
|
|
displayname: db.users.displayname(&user_id).unwrap(), |
|
|
|
|
|
|
|
last_active_ago: Some(utils::millis_since_unix_epoch().try_into().unwrap()), |
|
|
|
|
|
|
|
presence: ruma_events::presence::PresenceState::Online, |
|
|
|
|
|
|
|
status_msg: None, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
sender: user_id.clone(), |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
&db.globals, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.unwrap(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Send error on None
|
|
|
|
// Send error on None
|
|
|
|
// Synapse returns a parsing error but the spec doesn't require this
|
|
|
|
// Synapse returns a parsing error but the spec doesn't require this
|
|
|
|
@ -542,8 +556,7 @@ pub fn set_avatar_url_route( |
|
|
|
if body.avatar_url == "" { |
|
|
|
if body.avatar_url == "" { |
|
|
|
db.users.set_avatar_url(&user_id, None).unwrap(); |
|
|
|
db.users.set_avatar_url(&user_id, None).unwrap(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
db |
|
|
|
db.users |
|
|
|
.users |
|
|
|
|
|
|
|
.set_avatar_url(&user_id, Some(body.avatar_url.clone())) |
|
|
|
.set_avatar_url(&user_id, Some(body.avatar_url.clone())) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
// TODO send a new m.room.member join event with the updated avatar_url
|
|
|
|
// TODO send a new m.room.member join event with the updated avatar_url
|
|
|
|
@ -605,11 +618,32 @@ pub fn get_profile_route( |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[put("/_matrix/client/r0/presence/<_user_id>/status")] |
|
|
|
#[put("/_matrix/client/r0/presence/<_user_id>/status", data = "<body>")] |
|
|
|
pub fn set_presence_route( |
|
|
|
pub fn set_presence_route( |
|
|
|
|
|
|
|
db: State<'_, Database>, |
|
|
|
|
|
|
|
body: Ruma<set_presence::Request>, |
|
|
|
_user_id: String, |
|
|
|
_user_id: String, |
|
|
|
) -> MatrixResult<set_presence::Response> { |
|
|
|
) -> MatrixResult<set_presence::Response> { |
|
|
|
// TODO
|
|
|
|
let user_id = body.user_id.clone().expect("user is authenticated"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.global_edus |
|
|
|
|
|
|
|
.update_globallatest( |
|
|
|
|
|
|
|
&user_id, |
|
|
|
|
|
|
|
EduEvent::Presence(ruma_events::presence::PresenceEvent { |
|
|
|
|
|
|
|
content: ruma_events::presence::PresenceEventContent { |
|
|
|
|
|
|
|
avatar_url: db.users.avatar_url(&user_id).unwrap(), |
|
|
|
|
|
|
|
currently_active: None, |
|
|
|
|
|
|
|
displayname: db.users.displayname(&user_id).unwrap(), |
|
|
|
|
|
|
|
last_active_ago: Some(utils::millis_since_unix_epoch().try_into().unwrap()), |
|
|
|
|
|
|
|
presence: body.presence, |
|
|
|
|
|
|
|
status_msg: body.status_msg.clone(), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
sender: user_id.clone(), |
|
|
|
|
|
|
|
}), |
|
|
|
|
|
|
|
&db.globals, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
MatrixResult(Ok(set_presence::Response)) |
|
|
|
MatrixResult(Ok(set_presence::Response)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -637,7 +671,8 @@ pub fn set_read_marker_route( |
|
|
|
_room_id: String, |
|
|
|
_room_id: String, |
|
|
|
) -> MatrixResult<set_read_marker::Response> { |
|
|
|
) -> MatrixResult<set_read_marker::Response> { |
|
|
|
let user_id = body.user_id.clone().expect("user is authenticated"); |
|
|
|
let user_id = body.user_id.clone().expect("user is authenticated"); |
|
|
|
db.account_data.update( |
|
|
|
db.account_data |
|
|
|
|
|
|
|
.update( |
|
|
|
Some(&body.room_id), |
|
|
|
Some(&body.room_id), |
|
|
|
&user_id, |
|
|
|
&user_id, |
|
|
|
EduEvent::FullyRead(ruma_events::fully_read::FullyReadEvent { |
|
|
|
EduEvent::FullyRead(ruma_events::fully_read::FullyReadEvent { |
|
|
|
@ -646,19 +681,17 @@ pub fn set_read_marker_route( |
|
|
|
}, |
|
|
|
}, |
|
|
|
room_id: Some(body.room_id.clone()), |
|
|
|
room_id: Some(body.room_id.clone()), |
|
|
|
}), |
|
|
|
}), |
|
|
|
&db.globals |
|
|
|
&db.globals, |
|
|
|
) |
|
|
|
) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
if let Some(event) = &body.read_receipt { |
|
|
|
if let Some(event) = &body.read_receipt { |
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.edus |
|
|
|
.edus |
|
|
|
.room_read_set( |
|
|
|
.room_read_set( |
|
|
|
&body.room_id, |
|
|
|
&body.room_id, |
|
|
|
&user_id, |
|
|
|
&user_id, |
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.get_pdu_count(event) |
|
|
|
.get_pdu_count(event) |
|
|
|
.unwrap() |
|
|
|
.unwrap() |
|
|
|
.expect("TODO: what if a client specifies an invalid event"), |
|
|
|
.expect("TODO: what if a client specifies an invalid event"), |
|
|
|
@ -680,8 +713,7 @@ pub fn set_read_marker_route( |
|
|
|
}, |
|
|
|
}, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.edus |
|
|
|
.edus |
|
|
|
.roomlatest_update( |
|
|
|
.roomlatest_update( |
|
|
|
&user_id, |
|
|
|
&user_id, |
|
|
|
@ -716,8 +748,7 @@ pub fn create_typing_event_route( |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if body.typing { |
|
|
|
if body.typing { |
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.edus |
|
|
|
.edus |
|
|
|
.roomactive_add( |
|
|
|
.roomactive_add( |
|
|
|
edu, |
|
|
|
edu, |
|
|
|
@ -728,11 +759,7 @@ pub fn create_typing_event_route( |
|
|
|
) |
|
|
|
) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
db |
|
|
|
db.rooms.edus.roomactive_remove(edu, &body.room_id).unwrap(); |
|
|
|
.rooms |
|
|
|
|
|
|
|
.edus |
|
|
|
|
|
|
|
.roomactive_remove(edu, &body.room_id) |
|
|
|
|
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
MatrixResult(Ok(create_typing_event::Response)) |
|
|
|
MatrixResult(Ok(create_typing_event::Response)) |
|
|
|
@ -747,8 +774,7 @@ pub fn create_room_route( |
|
|
|
let room_id = RoomId::try_from(db.globals.hostname()).expect("host is valid"); |
|
|
|
let room_id = RoomId::try_from(db.globals.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"); |
|
|
|
|
|
|
|
|
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.append_pdu( |
|
|
|
.append_pdu( |
|
|
|
room_id.clone(), |
|
|
|
room_id.clone(), |
|
|
|
user_id.clone(), |
|
|
|
user_id.clone(), |
|
|
|
@ -760,8 +786,7 @@ pub fn create_room_route( |
|
|
|
) |
|
|
|
) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.join( |
|
|
|
.join( |
|
|
|
&room_id, |
|
|
|
&room_id, |
|
|
|
&user_id, |
|
|
|
&user_id, |
|
|
|
@ -770,8 +795,7 @@ pub fn create_room_route( |
|
|
|
) |
|
|
|
) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.append_pdu( |
|
|
|
.append_pdu( |
|
|
|
room_id.clone(), |
|
|
|
room_id.clone(), |
|
|
|
user_id.clone(), |
|
|
|
user_id.clone(), |
|
|
|
@ -793,8 +817,7 @@ pub fn create_room_route( |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
if let Some(name) = &body.name { |
|
|
|
if let Some(name) = &body.name { |
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.append_pdu( |
|
|
|
.append_pdu( |
|
|
|
room_id.clone(), |
|
|
|
room_id.clone(), |
|
|
|
user_id.clone(), |
|
|
|
user_id.clone(), |
|
|
|
@ -808,8 +831,7 @@ pub fn create_room_route( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if let Some(topic) = &body.topic { |
|
|
|
if let Some(topic) = &body.topic { |
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.append_pdu( |
|
|
|
.append_pdu( |
|
|
|
room_id.clone(), |
|
|
|
room_id.clone(), |
|
|
|
user_id.clone(), |
|
|
|
user_id.clone(), |
|
|
|
@ -823,8 +845,7 @@ pub fn create_room_route( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for user in &body.invite { |
|
|
|
for user in &body.invite { |
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.invite(&user_id, &room_id, user, &db.globals) |
|
|
|
.invite(&user_id, &room_id, user, &db.globals) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -945,8 +966,7 @@ pub fn leave_room_route( |
|
|
|
_room_id: String, |
|
|
|
_room_id: String, |
|
|
|
) -> MatrixResult<leave_room::Response> { |
|
|
|
) -> MatrixResult<leave_room::Response> { |
|
|
|
let user_id = body.user_id.clone().expect("user is authenticated"); |
|
|
|
let user_id = body.user_id.clone().expect("user is authenticated"); |
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.leave(&user_id, &body.room_id, &user_id, &db.globals) |
|
|
|
.leave(&user_id, &body.room_id, &user_id, &db.globals) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
MatrixResult(Ok(leave_room::Response)) |
|
|
|
MatrixResult(Ok(leave_room::Response)) |
|
|
|
@ -970,8 +990,7 @@ pub fn invite_user_route( |
|
|
|
_room_id: String, |
|
|
|
_room_id: String, |
|
|
|
) -> MatrixResult<invite_user::Response> { |
|
|
|
) -> MatrixResult<invite_user::Response> { |
|
|
|
if let invite_user::InvitationRecipient::UserId { user_id } = &body.recipient { |
|
|
|
if let invite_user::InvitationRecipient::UserId { user_id } = &body.recipient { |
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.invite( |
|
|
|
.invite( |
|
|
|
&body.user_id.as_ref().expect("user is authenticated"), |
|
|
|
&body.user_id.as_ref().expect("user is authenticated"), |
|
|
|
&body.room_id, |
|
|
|
&body.room_id, |
|
|
|
@ -1069,16 +1088,13 @@ pub fn search_users_route( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[get("/_matrix/client/r0/rooms/<_room_id>/members")] |
|
|
|
#[get("/_matrix/client/r0/rooms/<_room_id>/members")] |
|
|
|
pub fn get_member_events_route( |
|
|
|
pub fn get_member_events_route(_room_id: String) -> MatrixResult<get_member_events::Response> { |
|
|
|
_room_id: String, |
|
|
|
|
|
|
|
) -> MatrixResult<get_member_events::Response> { |
|
|
|
|
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
MatrixResult(Ok(get_member_events::Response { chunk: Vec::new() })) |
|
|
|
MatrixResult(Ok(get_member_events::Response { chunk: Vec::new() })) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[get("/_matrix/client/r0/thirdparty/protocols")] |
|
|
|
#[get("/_matrix/client/r0/thirdparty/protocols")] |
|
|
|
pub fn get_protocols_route( |
|
|
|
pub fn get_protocols_route() -> MatrixResult<get_protocols::Response> { |
|
|
|
) -> MatrixResult<get_protocols::Response> { |
|
|
|
|
|
|
|
// TODO
|
|
|
|
// TODO
|
|
|
|
MatrixResult(Ok(get_protocols::Response { |
|
|
|
MatrixResult(Ok(get_protocols::Response { |
|
|
|
protocols: BTreeMap::new(), |
|
|
|
protocols: BTreeMap::new(), |
|
|
|
@ -1114,7 +1130,9 @@ pub fn create_message_event_route( |
|
|
|
) |
|
|
|
) |
|
|
|
.expect("message events are always okay"); |
|
|
|
.expect("message events are always okay"); |
|
|
|
|
|
|
|
|
|
|
|
MatrixResult(Ok(create_message_event::Response { event_id: Some(event_id) })) |
|
|
|
MatrixResult(Ok(create_message_event::Response { |
|
|
|
|
|
|
|
event_id: Some(event_id), |
|
|
|
|
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[put(
|
|
|
|
#[put(
|
|
|
|
@ -1144,7 +1162,9 @@ pub fn create_state_event_for_key_route( |
|
|
|
) |
|
|
|
) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
MatrixResult(Ok(create_state_event_for_key::Response { event_id: Some(event_id) })) |
|
|
|
MatrixResult(Ok(create_state_event_for_key::Response { |
|
|
|
|
|
|
|
event_id: Some(event_id), |
|
|
|
|
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[put(
|
|
|
|
#[put(
|
|
|
|
@ -1173,7 +1193,9 @@ pub fn create_state_event_for_empty_key_route( |
|
|
|
) |
|
|
|
) |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
MatrixResult(Ok(create_state_event_for_empty_key::Response { event_id: Some(event_id) })) |
|
|
|
MatrixResult(Ok(create_state_event_for_empty_key::Response { |
|
|
|
|
|
|
|
event_id: Some(event_id), |
|
|
|
|
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[get("/_matrix/client/r0/sync", data = "<body>")] |
|
|
|
#[get("/_matrix/client/r0/sync", data = "<body>")] |
|
|
|
@ -1197,7 +1219,8 @@ pub fn sync_route( |
|
|
|
|
|
|
|
|
|
|
|
let mut pdus = db |
|
|
|
let mut pdus = db |
|
|
|
.rooms |
|
|
|
.rooms |
|
|
|
.pdus_since(&room_id, since).unwrap() |
|
|
|
.pdus_since(&room_id, since) |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
.map(|r| r.unwrap()) |
|
|
|
.map(|r| r.unwrap()) |
|
|
|
.collect::<Vec<_>>(); |
|
|
|
.collect::<Vec<_>>(); |
|
|
|
|
|
|
|
|
|
|
|
@ -1213,12 +1236,8 @@ pub fn sync_route( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let notification_count = if let Some(last_read) = db |
|
|
|
let notification_count = |
|
|
|
.rooms |
|
|
|
if let Some(last_read) = db.rooms.edus.room_read_get(&room_id, &user_id).unwrap() { |
|
|
|
.edus |
|
|
|
|
|
|
|
.room_read_get(&room_id, &user_id) |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Some((db.rooms.pdus_since(&room_id, last_read).unwrap().count() as u32).into()) |
|
|
|
Some((db.rooms.pdus_since(&room_id, last_read).unwrap().count() as u32).into()) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
None |
|
|
|
None |
|
|
|
@ -1262,10 +1281,10 @@ pub fn sync_route( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
edus.extend( |
|
|
|
edus.extend( |
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.edus |
|
|
|
.edus |
|
|
|
.roomlatests_since(&room_id, since).unwrap() |
|
|
|
.roomlatests_since(&room_id, since) |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
.map(|r| r.unwrap()), |
|
|
|
.map(|r| r.unwrap()), |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
@ -1273,8 +1292,10 @@ pub fn sync_route( |
|
|
|
room_id.clone().try_into().unwrap(), |
|
|
|
room_id.clone().try_into().unwrap(), |
|
|
|
sync_events::JoinedRoom { |
|
|
|
sync_events::JoinedRoom { |
|
|
|
account_data: Some(sync_events::AccountData { |
|
|
|
account_data: Some(sync_events::AccountData { |
|
|
|
events: db.account_data |
|
|
|
events: db |
|
|
|
.changes_since(Some(&room_id), &user_id, since).unwrap() |
|
|
|
.account_data |
|
|
|
|
|
|
|
.changes_since(Some(&room_id), &user_id, since) |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
.into_iter() |
|
|
|
.into_iter() |
|
|
|
.map(|(_, v)| v) |
|
|
|
.map(|(_, v)| v) |
|
|
|
.collect(), |
|
|
|
.collect(), |
|
|
|
@ -1304,8 +1325,7 @@ pub fn sync_route( |
|
|
|
// TODO: state before timeline
|
|
|
|
// TODO: state before timeline
|
|
|
|
state: sync_events::State { |
|
|
|
state: sync_events::State { |
|
|
|
events: if send_full_state { |
|
|
|
events: if send_full_state { |
|
|
|
db |
|
|
|
db.rooms |
|
|
|
.rooms |
|
|
|
|
|
|
|
.room_state(&room_id) |
|
|
|
.room_state(&room_id) |
|
|
|
.unwrap() |
|
|
|
.unwrap() |
|
|
|
.into_iter() |
|
|
|
.into_iter() |
|
|
|
@ -1332,17 +1352,12 @@ pub fn sync_route( |
|
|
|
let mut edus = db |
|
|
|
let mut edus = db |
|
|
|
.rooms |
|
|
|
.rooms |
|
|
|
.edus |
|
|
|
.edus |
|
|
|
.roomlatests_since(&room_id, since).unwrap() |
|
|
|
.roomlatests_since(&room_id, since) |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
.map(|r| r.unwrap()) |
|
|
|
.map(|r| r.unwrap()) |
|
|
|
.collect::<Vec<_>>(); |
|
|
|
.collect::<Vec<_>>(); |
|
|
|
|
|
|
|
|
|
|
|
edus.extend( |
|
|
|
edus.extend(db.rooms.edus.roomactives_all(&room_id).map(|r| r.unwrap())); |
|
|
|
db |
|
|
|
|
|
|
|
.rooms |
|
|
|
|
|
|
|
.edus |
|
|
|
|
|
|
|
.roomactives_all(&room_id) |
|
|
|
|
|
|
|
.map(|r| r.unwrap()), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
left_rooms.insert( |
|
|
|
left_rooms.insert( |
|
|
|
room_id.clone().try_into().unwrap(), |
|
|
|
room_id.clone().try_into().unwrap(), |
|
|
|
@ -1363,7 +1378,8 @@ pub fn sync_route( |
|
|
|
let room_id = room_id.unwrap(); |
|
|
|
let room_id = room_id.unwrap(); |
|
|
|
let events = db |
|
|
|
let events = db |
|
|
|
.rooms |
|
|
|
.rooms |
|
|
|
.pdus_since(&room_id, since).unwrap() |
|
|
|
.pdus_since(&room_id, since) |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
.into_iter() |
|
|
|
.into_iter() |
|
|
|
.map(|pdu| pdu.unwrap().to_stripped_state_event()) |
|
|
|
.map(|pdu| pdu.unwrap().to_stripped_state_event()) |
|
|
|
.collect(); |
|
|
|
.collect(); |
|
|
|
@ -1383,10 +1399,23 @@ pub fn sync_route( |
|
|
|
join: joined_rooms, |
|
|
|
join: joined_rooms, |
|
|
|
invite: invited_rooms, |
|
|
|
invite: invited_rooms, |
|
|
|
}, |
|
|
|
}, |
|
|
|
presence: sync_events::Presence { events: Vec::new() }, |
|
|
|
presence: sync_events::Presence { |
|
|
|
|
|
|
|
events: db |
|
|
|
|
|
|
|
.global_edus |
|
|
|
|
|
|
|
.globallatests_since(since) |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
|
|
|
|
.map(|edu| { |
|
|
|
|
|
|
|
EventJson::<ruma_events::presence::PresenceEvent>::from( |
|
|
|
|
|
|
|
edu.unwrap().json().to_owned(), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.collect(), |
|
|
|
|
|
|
|
}, |
|
|
|
account_data: sync_events::AccountData { |
|
|
|
account_data: sync_events::AccountData { |
|
|
|
events: db.account_data |
|
|
|
events: db |
|
|
|
.changes_since(None, &user_id, since).unwrap() |
|
|
|
.account_data |
|
|
|
|
|
|
|
.changes_since(None, &user_id, since) |
|
|
|
|
|
|
|
.unwrap() |
|
|
|
.into_iter() |
|
|
|
.into_iter() |
|
|
|
.map(|(_, v)| v) |
|
|
|
.map(|(_, v)| v) |
|
|
|
.collect(), |
|
|
|
.collect(), |
|
|
|
|