Move to depend on ruma monorepo and ruma-events0.22
parent
9c095f1538
commit
7c38e53839
File diff suppressed because it is too large
Load Diff
12
Cargo.toml
12
Cargo.toml
|
@ -29,16 +29,16 @@ thiserror = "1.0.19"
|
||||||
image = { version = "0.23.4", default-features = false, features = ["jpeg", "png", "gif"] }
|
image = { version = "0.23.4", default-features = false, features = ["jpeg", "png", "gif"] }
|
||||||
|
|
||||||
[dependencies.ruma]
|
[dependencies.ruma]
|
||||||
git = "https://github.com/timokoesters/ruma"
|
git = "https://github.com/DevinR528/ruma"
|
||||||
#rev = "baa87104569b45dc07a9a7a16d3c7592ab8f4d6b"
|
branch = "matrix-sdk2"
|
||||||
#path = "../ruma/ruma"
|
#path = "../ruma/ruma"
|
||||||
features = ["rand", "client-api", "federation-api"]
|
features = ["rand", "client-api", "federation-api"]
|
||||||
|
|
||||||
# These are required only until ruma-events and ruma-federation-api are merged into ruma/ruma
|
# These are required only until ruma-events and ruma-federation-api are merged into ruma/ruma
|
||||||
[patch.crates-io]
|
# [patch.crates-io]
|
||||||
ruma-common = { git = "https://github.com/timokoesters/ruma" }
|
# ruma-common = { git = "https://github.com/ruma/ruma", rev = "baa87104569b45dc07a9a7a16d3c7592ab8f4d6b" }
|
||||||
ruma-serde = { git = "https://github.com/timokoesters/ruma" }
|
# ruma-serde = { git = "https://github.com/ruma/ruma", rev = "baa87104569b45dc07a9a7a16d3c7592ab8f4d6b" }
|
||||||
ruma-identifiers = { git = "https://github.com/timokoesters/ruma" }
|
# ruma-identifiers = { git = "https://github.com/ruma/ruma", rev = "baa87104569b45dc07a9a7a16d3c7592ab8f4d6b" }
|
||||||
#ruma-common = { path = "../ruma/ruma-common" }
|
#ruma-common = { path = "../ruma/ruma-common" }
|
||||||
#ruma-serde = { path = "../ruma/ruma-serde" }
|
#ruma-serde = { path = "../ruma/ruma-serde" }
|
||||||
#ruma-identifiers = { path = "../ruma/ruma-identifiers" }
|
#ruma-identifiers = { path = "../ruma/ruma-identifiers" }
|
||||||
|
|
|
@ -60,12 +60,11 @@ use ruma::{
|
||||||
unversioned::get_supported_versions,
|
unversioned::get_supported_versions,
|
||||||
},
|
},
|
||||||
events::{
|
events::{
|
||||||
collections::only::Event as EduEvent,
|
|
||||||
room::{
|
room::{
|
||||||
canonical_alias, guest_access, history_visibility, join_rules, member, name, redaction,
|
canonical_alias, guest_access, history_visibility, join_rules, member, name, redaction,
|
||||||
topic,
|
topic,
|
||||||
},
|
},
|
||||||
EventJson, EventType,
|
AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent as EduEvent, EventJson, EventType,
|
||||||
},
|
},
|
||||||
identifiers::{RoomAliasId, RoomId, RoomVersionId, UserId},
|
identifiers::{RoomAliasId, RoomId, RoomVersionId, UserId},
|
||||||
};
|
};
|
||||||
|
@ -77,7 +76,7 @@ const TOKEN_LENGTH: usize = 256;
|
||||||
const MXC_LENGTH: usize = 256;
|
const MXC_LENGTH: usize = 256;
|
||||||
const SESSION_ID_LENGTH: usize = 256;
|
const SESSION_ID_LENGTH: usize = 256;
|
||||||
|
|
||||||
#[get("/_matrix/client/versions")]
|
// #[get("/_matrix/client/versions")]
|
||||||
pub fn get_supported_versions_route() -> ConduitResult<get_supported_versions::Response> {
|
pub fn get_supported_versions_route() -> ConduitResult<get_supported_versions::Response> {
|
||||||
let mut unstable_features = BTreeMap::new();
|
let mut unstable_features = BTreeMap::new();
|
||||||
|
|
||||||
|
@ -90,7 +89,7 @@ pub fn get_supported_versions_route() -> ConduitResult<get_supported_versions::R
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/register/available", data = "<body>")]
|
// #[get("/_matrix/client/r0/register/available", data = "<body>")]
|
||||||
pub fn get_register_available_route(
|
pub fn get_register_available_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_username_availability::Request>,
|
body: Ruma<get_username_availability::Request>,
|
||||||
|
@ -120,7 +119,7 @@ pub fn get_register_available_route(
|
||||||
Ok(get_username_availability::Response { available: true }.into())
|
Ok(get_username_availability::Response { available: true }.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/register", data = "<body>")]
|
// #[post("/_matrix/client/r0/register", data = "<body>")]
|
||||||
pub fn register_route(
|
pub fn register_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<register::Request>,
|
body: Ruma<register::Request>,
|
||||||
|
@ -226,7 +225,7 @@ pub fn register_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/login")]
|
// #[get("/_matrix/client/r0/login")]
|
||||||
pub fn get_login_route() -> ConduitResult<get_login_types::Response> {
|
pub fn get_login_route() -> ConduitResult<get_login_types::Response> {
|
||||||
Ok(get_login_types::Response {
|
Ok(get_login_types::Response {
|
||||||
flows: vec![get_login_types::LoginType::Password],
|
flows: vec![get_login_types::LoginType::Password],
|
||||||
|
@ -234,7 +233,7 @@ pub fn get_login_route() -> ConduitResult<get_login_types::Response> {
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/login", data = "<body>")]
|
// #[post("/_matrix/client/r0/login", data = "<body>")]
|
||||||
pub fn login_route(
|
pub fn login_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<login::Request>,
|
body: Ruma<login::Request>,
|
||||||
|
@ -285,14 +284,14 @@ pub fn login_route(
|
||||||
Ok(login::Response {
|
Ok(login::Response {
|
||||||
user_id,
|
user_id,
|
||||||
access_token: token,
|
access_token: token,
|
||||||
home_server: Some(db.globals.server_name().to_owned()),
|
home_server: Some(db.globals.server_name().to_string()),
|
||||||
device_id,
|
device_id,
|
||||||
well_known: None,
|
well_known: None,
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/logout", data = "<body>")]
|
// #[post("/_matrix/client/r0/logout", data = "<body>")]
|
||||||
pub fn logout_route(
|
pub fn logout_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<logout::Request>,
|
body: Ruma<logout::Request>,
|
||||||
|
@ -473,14 +472,14 @@ pub fn get_capabilities_route() -> ConduitResult<get_capabilities::Response> {
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/pushrules", data = "<body>")]
|
// #[get("/_matrix/client/r0/pushrules", data = "<body>")]
|
||||||
pub fn get_pushrules_all_route(
|
pub fn get_pushrules_all_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_pushrules_all::Request>,
|
body: Ruma<get_pushrules_all::Request>,
|
||||||
) -> ConduitResult<get_pushrules_all::Response> {
|
) -> ConduitResult<get_pushrules_all::Response> {
|
||||||
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if let EduEvent::PushRules(pushrules) = db
|
if let EduEvent::Basic(AnyBasicEvent::PushRules(pushrules)) = db
|
||||||
.account_data
|
.account_data
|
||||||
.get(None, &user_id, &EventType::PushRules)?
|
.get(None, &user_id, &EventType::PushRules)?
|
||||||
.ok_or(Error::BadRequest(
|
.ok_or(Error::BadRequest(
|
||||||
|
@ -515,7 +514,7 @@ pub fn set_pushrule_route(
|
||||||
Ok(set_pushrule::Response.into())
|
Ok(set_pushrule::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/_matrix/client/r0/pushrules/<_scope>/<_kind>/<_rule_id>/enabled")]
|
// #[put("/_matrix/client/r0/pushrules/<_scope>/<_kind>/<_rule_id>/enabled")]
|
||||||
pub fn set_pushrule_enabled_route(
|
pub fn set_pushrule_enabled_route(
|
||||||
_scope: String,
|
_scope: String,
|
||||||
_kind: String,
|
_kind: String,
|
||||||
|
@ -526,7 +525,7 @@ pub fn set_pushrule_enabled_route(
|
||||||
Ok(set_pushrule_enabled::Response.into())
|
Ok(set_pushrule_enabled::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/user/<_user_id>/filter/<_filter_id>")]
|
// #[get("/_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,
|
||||||
|
@ -544,7 +543,7 @@ pub fn get_filter_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/user/<_user_id>/filter")]
|
// #[post("/_matrix/client/r0/user/<_user_id>/filter")]
|
||||||
pub fn create_filter_route(_user_id: String) -> ConduitResult<create_filter::Response> {
|
pub fn create_filter_route(_user_id: String) -> ConduitResult<create_filter::Response> {
|
||||||
// TODO
|
// TODO
|
||||||
Ok(create_filter::Response {
|
Ok(create_filter::Response {
|
||||||
|
@ -553,10 +552,10 @@ pub fn create_filter_route(_user_id: String) -> ConduitResult<create_filter::Res
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put(
|
// #[put(
|
||||||
"/_matrix/client/r0/user/<_user_id>/account_data/<_type>",
|
// "/_matrix/client/r0/user/<_user_id>/account_data/<_type>",
|
||||||
data = "<body>"
|
// data = "<body>"
|
||||||
)]
|
// )]
|
||||||
pub fn set_global_account_data_route(
|
pub fn set_global_account_data_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<set_global_account_data::Request>,
|
body: Ruma<set_global_account_data::Request>,
|
||||||
|
@ -582,10 +581,10 @@ pub fn set_global_account_data_route(
|
||||||
Ok(set_global_account_data::Response.into())
|
Ok(set_global_account_data::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get(
|
// #[get(
|
||||||
"/_matrix/client/r0/user/<_user_id>/account_data/<_type>",
|
// "/_matrix/client/r0/user/<_user_id>/account_data/<_type>",
|
||||||
data = "<body>"
|
// data = "<body>"
|
||||||
)]
|
// )]
|
||||||
pub fn get_global_account_data_route(
|
pub fn get_global_account_data_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_global_account_data::Request>,
|
body: Ruma<get_global_account_data::Request>,
|
||||||
|
@ -603,10 +602,19 @@ pub fn get_global_account_data_route(
|
||||||
)?
|
)?
|
||||||
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
|
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
|
||||||
|
|
||||||
Ok(get_global_account_data::Response { account_data: data }.into())
|
// TODO clearly this is not ideal...
|
||||||
|
// NOTE: EventJson is no longer needed as all the enums and event structs impl ser/de
|
||||||
|
let data: Result<EduEvent, Error> = data.deserialize().map_err(Into::into);
|
||||||
|
match data? {
|
||||||
|
EduEvent::Basic(data) => Ok(get_global_account_data::Response {
|
||||||
|
account_data: EventJson::from(data),
|
||||||
|
}
|
||||||
|
.into()),
|
||||||
|
_ => panic!("timo what do i do here"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")]
|
// #[put("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")]
|
||||||
pub fn set_displayname_route(
|
pub fn set_displayname_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<set_display_name::Request>,
|
body: Ruma<set_display_name::Request>,
|
||||||
|
@ -672,7 +680,7 @@ pub fn set_displayname_route(
|
||||||
Ok(set_display_name::Response.into())
|
Ok(set_display_name::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")]
|
// #[get("/_matrix/client/r0/profile/<_user_id>/displayname", data = "<body>")]
|
||||||
pub fn get_displayname_route(
|
pub fn get_displayname_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_display_name::Request>,
|
body: Ruma<get_display_name::Request>,
|
||||||
|
@ -685,7 +693,7 @@ pub fn get_displayname_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/_matrix/client/r0/profile/<_user_id>/avatar_url", data = "<body>")]
|
// #[put("/_matrix/client/r0/profile/<_user_id>/avatar_url", data = "<body>")]
|
||||||
pub fn set_avatar_url_route(
|
pub fn set_avatar_url_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<set_avatar_url::Request>,
|
body: Ruma<set_avatar_url::Request>,
|
||||||
|
@ -762,7 +770,7 @@ pub fn set_avatar_url_route(
|
||||||
Ok(set_avatar_url::Response.into())
|
Ok(set_avatar_url::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/profile/<_user_id>/avatar_url", data = "<body>")]
|
// #[get("/_matrix/client/r0/profile/<_user_id>/avatar_url", data = "<body>")]
|
||||||
pub fn get_avatar_url_route(
|
pub fn get_avatar_url_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_avatar_url::Request>,
|
body: Ruma<get_avatar_url::Request>,
|
||||||
|
@ -775,7 +783,7 @@ pub fn get_avatar_url_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/profile/<_user_id>", data = "<body>")]
|
// #[get("/_matrix/client/r0/profile/<_user_id>", data = "<body>")]
|
||||||
pub fn get_profile_route(
|
pub fn get_profile_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_profile::Request>,
|
body: Ruma<get_profile::Request>,
|
||||||
|
@ -800,7 +808,7 @@ pub fn get_profile_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/_matrix/client/r0/presence/<_user_id>/status", data = "<body>")]
|
// #[put("/_matrix/client/r0/presence/<_user_id>/status", data = "<body>")]
|
||||||
pub fn set_presence_route(
|
pub fn set_presence_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<set_presence::Request>,
|
body: Ruma<set_presence::Request>,
|
||||||
|
@ -830,7 +838,7 @@ pub fn set_presence_route(
|
||||||
Ok(set_presence::Response.into())
|
Ok(set_presence::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/keys/upload", data = "<body>")]
|
// #[post("/_matrix/client/r0/keys/upload", data = "<body>")]
|
||||||
pub fn upload_keys_route(
|
pub fn upload_keys_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<upload_keys::Request>,
|
body: Ruma<upload_keys::Request>,
|
||||||
|
@ -859,7 +867,7 @@ pub fn upload_keys_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/keys/query", data = "<body>")]
|
// #[post("/_matrix/client/r0/keys/query", data = "<body>")]
|
||||||
pub fn get_keys_route(
|
pub fn get_keys_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_keys::Request>,
|
body: Ruma<get_keys::Request>,
|
||||||
|
@ -936,7 +944,7 @@ pub fn get_keys_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/keys/claim", data = "<body>")]
|
// #[post("/_matrix/client/r0/keys/claim", data = "<body>")]
|
||||||
pub fn claim_keys_route(
|
pub fn claim_keys_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<claim_keys::Request>,
|
body: Ruma<claim_keys::Request>,
|
||||||
|
@ -1099,7 +1107,7 @@ pub fn set_read_marker_route(
|
||||||
content: ruma::events::fully_read::FullyReadEventContent {
|
content: ruma::events::fully_read::FullyReadEventContent {
|
||||||
event_id: body.fully_read.clone(),
|
event_id: body.fully_read.clone(),
|
||||||
},
|
},
|
||||||
room_id: Some(body.room_id.clone()),
|
room_id: body.room_id.clone(),
|
||||||
})
|
})
|
||||||
.expect("we just created a valid event")
|
.expect("we just created a valid event")
|
||||||
.as_object_mut()
|
.as_object_mut()
|
||||||
|
@ -1135,20 +1143,22 @@ pub fn set_read_marker_route(
|
||||||
db.rooms.edus.roomlatest_update(
|
db.rooms.edus.roomlatest_update(
|
||||||
&user_id,
|
&user_id,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
EduEvent::Receipt(ruma::events::receipt::ReceiptEvent {
|
EduEvent::Ephemeral(AnyEphemeralRoomEvent::Receipt(
|
||||||
content: receipt_content,
|
ruma::events::receipt::ReceiptEvent {
|
||||||
room_id: None, // None because it can be inferred
|
content: ruma::events::receipt::ReceiptEventContent(receipt_content),
|
||||||
}),
|
room_id: body.room_id.clone(),
|
||||||
|
},
|
||||||
|
)),
|
||||||
&db.globals,
|
&db.globals,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
Ok(set_read_marker::Response.into())
|
Ok(set_read_marker::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put(
|
// #[put(
|
||||||
"/_matrix/client/r0/rooms/<_room_id>/typing/<_user_id>",
|
// "/_matrix/client/r0/rooms/<_room_id>/typing/<_user_id>",
|
||||||
data = "<body>"
|
// data = "<body>"
|
||||||
)]
|
// )]
|
||||||
pub fn create_typing_event_route(
|
pub fn create_typing_event_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<create_typing_event::Request>,
|
body: Ruma<create_typing_event::Request>,
|
||||||
|
@ -1174,15 +1184,14 @@ pub fn create_typing_event_route(
|
||||||
Ok(create_typing_event::Response.into())
|
Ok(create_typing_event::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/createRoom", data = "<body>")]
|
// #[post("/_matrix/client/r0/createRoom", data = "<body>")]
|
||||||
pub fn create_room_route(
|
pub fn create_room_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<create_room::Request>,
|
body: Ruma<create_room::Request>,
|
||||||
) -> ConduitResult<create_room::Response> {
|
) -> ConduitResult<create_room::Response> {
|
||||||
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
let user_id = body.user_id.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let room_id = RoomId::new(db.globals.server_name())
|
let room_id = RoomId::new(db.globals.server_name());
|
||||||
.map_err(|_| Error::bad_database("Server name is invalid."))?;
|
|
||||||
|
|
||||||
let alias = body
|
let alias = body
|
||||||
.room_alias_name
|
.room_alias_name
|
||||||
|
@ -1439,10 +1448,10 @@ pub fn create_room_route(
|
||||||
Ok(create_room::Response { room_id }.into())
|
Ok(create_room::Response { room_id }.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put(
|
// #[put(
|
||||||
"/_matrix/client/r0/rooms/<_room_id>/redact/<_event_id>/<_txn_id>",
|
// "/_matrix/client/r0/rooms/<_room_id>/redact/<_event_id>/<_txn_id>",
|
||||||
data = "<body>"
|
// data = "<body>"
|
||||||
)]
|
// )]
|
||||||
pub fn redact_event_route(
|
pub fn redact_event_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<redact_event::Request>,
|
body: Ruma<redact_event::Request>,
|
||||||
|
@ -1469,7 +1478,7 @@ pub fn redact_event_route(
|
||||||
Ok(redact_event::Response { event_id }.into())
|
Ok(redact_event::Response { event_id }.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/_matrix/client/r0/directory/room/<_room_alias>", data = "<body>")]
|
// #[put("/_matrix/client/r0/directory/room/<_room_alias>", data = "<body>")]
|
||||||
pub fn create_alias_route(
|
pub fn create_alias_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<create_alias::Request>,
|
body: Ruma<create_alias::Request>,
|
||||||
|
@ -1485,7 +1494,7 @@ pub fn create_alias_route(
|
||||||
Ok(create_alias::Response.into())
|
Ok(create_alias::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[delete("/_matrix/client/r0/directory/room/<_room_alias>", data = "<body>")]
|
// #[delete("/_matrix/client/r0/directory/room/<_room_alias>", data = "<body>")]
|
||||||
pub fn delete_alias_route(
|
pub fn delete_alias_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<delete_alias::Request>,
|
body: Ruma<delete_alias::Request>,
|
||||||
|
@ -1496,7 +1505,7 @@ pub fn delete_alias_route(
|
||||||
Ok(delete_alias::Response.into())
|
Ok(delete_alias::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/directory/room/<_room_alias>", data = "<body>")]
|
// #[get("/_matrix/client/r0/directory/room/<_room_alias>", data = "<body>")]
|
||||||
pub fn get_alias_route(
|
pub fn get_alias_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_alias::Request>,
|
body: Ruma<get_alias::Request>,
|
||||||
|
@ -1516,12 +1525,12 @@ pub fn get_alias_route(
|
||||||
|
|
||||||
Ok(get_alias::Response {
|
Ok(get_alias::Response {
|
||||||
room_id,
|
room_id,
|
||||||
servers: vec![db.globals.server_name().to_owned()],
|
servers: vec![db.globals.server_name().to_string()],
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/rooms/<_room_id>/join", data = "<body>")]
|
// #[post("/_matrix/client/r0/rooms/<_room_id>/join", data = "<body>")]
|
||||||
pub fn join_room_by_id_route(
|
pub fn join_room_by_id_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<join_room_by_id::Request>,
|
body: Ruma<join_room_by_id::Request>,
|
||||||
|
@ -1556,7 +1565,7 @@ pub fn join_room_by_id_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/join/<_room_id_or_alias>", data = "<body>")]
|
// #[post("/_matrix/client/r0/join/<_room_id_or_alias>", data = "<body>")]
|
||||||
pub fn join_room_by_id_or_alias_route(
|
pub fn join_room_by_id_or_alias_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<join_room_by_id_or_alias::Request>,
|
body: Ruma<join_room_by_id_or_alias::Request>,
|
||||||
|
@ -1585,7 +1594,7 @@ pub fn join_room_by_id_or_alias_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/rooms/<_room_id>/leave", data = "<body>")]
|
// #[post("/_matrix/client/r0/rooms/<_room_id>/leave", data = "<body>")]
|
||||||
pub fn leave_room_route(
|
pub fn leave_room_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<leave_room::Request>,
|
body: Ruma<leave_room::Request>,
|
||||||
|
@ -1623,7 +1632,7 @@ pub fn leave_room_route(
|
||||||
Ok(leave_room::Response.into())
|
Ok(leave_room::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/rooms/<_room_id>/kick", data = "<body>")]
|
// #[post("/_matrix/client/r0/rooms/<_room_id>/kick", data = "<body>")]
|
||||||
pub fn kick_user_route(
|
pub fn kick_user_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<kick_user::Request>,
|
body: Ruma<kick_user::Request>,
|
||||||
|
@ -1663,7 +1672,7 @@ pub fn kick_user_route(
|
||||||
Ok(kick_user::Response.into())
|
Ok(kick_user::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/rooms/<_room_id>/ban", data = "<body>")]
|
// #[post("/_matrix/client/r0/rooms/<_room_id>/ban", data = "<body>")]
|
||||||
pub fn ban_user_route(
|
pub fn ban_user_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<ban_user::Request>,
|
body: Ruma<ban_user::Request>,
|
||||||
|
@ -1710,7 +1719,7 @@ pub fn ban_user_route(
|
||||||
Ok(ban_user::Response.into())
|
Ok(ban_user::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/rooms/<_room_id>/unban", data = "<body>")]
|
// #[post("/_matrix/client/r0/rooms/<_room_id>/unban", data = "<body>")]
|
||||||
pub fn unban_user_route(
|
pub fn unban_user_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<unban_user::Request>,
|
body: Ruma<unban_user::Request>,
|
||||||
|
@ -1749,7 +1758,7 @@ pub fn unban_user_route(
|
||||||
Ok(unban_user::Response.into())
|
Ok(unban_user::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/rooms/<_room_id>/forget", data = "<body>")]
|
// #[post("/_matrix/client/r0/rooms/<_room_id>/forget", data = "<body>")]
|
||||||
pub fn forget_room_route(
|
pub fn forget_room_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<forget_room::Request>,
|
body: Ruma<forget_room::Request>,
|
||||||
|
@ -1762,7 +1771,7 @@ pub fn forget_room_route(
|
||||||
Ok(forget_room::Response.into())
|
Ok(forget_room::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<invite_user::Request>,
|
body: Ruma<invite_user::Request>,
|
||||||
|
@ -1793,7 +1802,7 @@ pub fn invite_user_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/_matrix/client/r0/directory/list/room/<_room_id>", data = "<body>")]
|
// #[put("/_matrix/client/r0/directory/list/room/<_room_id>", data = "<body>")]
|
||||||
pub async fn set_room_visibility_route(
|
pub async fn set_room_visibility_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<set_room_visibility::Request>,
|
body: Ruma<set_room_visibility::Request>,
|
||||||
|
@ -1807,7 +1816,7 @@ pub async fn set_room_visibility_route(
|
||||||
Ok(set_room_visibility::Response.into())
|
Ok(set_room_visibility::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/directory/list/room/<_room_id>", data = "<body>")]
|
// #[get("/_matrix/client/r0/directory/list/room/<_room_id>", data = "<body>")]
|
||||||
pub async fn get_room_visibility_route(
|
pub async fn get_room_visibility_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_room_visibility::Request>,
|
body: Ruma<get_room_visibility::Request>,
|
||||||
|
@ -1823,7 +1832,7 @@ pub async fn get_room_visibility_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/publicRooms", data = "<body>")]
|
// #[get("/_matrix/client/r0/publicRooms", data = "<body>")]
|
||||||
pub async fn get_public_rooms_route(
|
pub async fn get_public_rooms_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_public_rooms::Request>,
|
body: Ruma<get_public_rooms::Request>,
|
||||||
|
@ -1872,7 +1881,7 @@ pub async fn get_public_rooms_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/publicRooms", data = "<body>")]
|
// #[post("/_matrix/client/r0/publicRooms", data = "<body>")]
|
||||||
pub async fn get_public_rooms_filtered_route(
|
pub async fn get_public_rooms_filtered_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_public_rooms_filtered::Request>,
|
body: Ruma<get_public_rooms_filtered::Request>,
|
||||||
|
@ -1984,7 +1993,7 @@ pub async fn get_public_rooms_filtered_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/user_directory/search", data = "<body>")]
|
// #[post("/_matrix/client/r0/user_directory/search", data = "<body>")]
|
||||||
pub fn search_users_route(
|
pub fn search_users_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<search_users::Request>,
|
body: Ruma<search_users::Request>,
|
||||||
|
@ -2050,7 +2059,7 @@ pub fn get_member_events_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/thirdparty/protocols")]
|
// #[get("/_matrix/client/r0/thirdparty/protocols")]
|
||||||
pub fn get_protocols_route() -> ConduitResult<get_protocols::Response> {
|
pub fn get_protocols_route() -> ConduitResult<get_protocols::Response> {
|
||||||
warn!("TODO: get_protocols_route");
|
warn!("TODO: get_protocols_route");
|
||||||
Ok(get_protocols::Response {
|
Ok(get_protocols::Response {
|
||||||
|
@ -2124,7 +2133,7 @@ pub fn create_message_event_route(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put(
|
#[put(
|
||||||
"/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>/<_state_key>",
|
// "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>/<_state_key>",
|
||||||
data = "<body>"
|
data = "<body>"
|
||||||
)]
|
)]
|
||||||
pub fn create_state_event_for_key_route(
|
pub fn create_state_event_for_key_route(
|
||||||
|
@ -2185,10 +2194,10 @@ pub fn create_state_event_for_key_route(
|
||||||
Ok(create_state_event_for_key::Response { event_id }.into())
|
Ok(create_state_event_for_key::Response { event_id }.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put(
|
// #[put(
|
||||||
"/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>",
|
// "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>",
|
||||||
data = "<body>"
|
// data = "<body>"
|
||||||
)]
|
// )]
|
||||||
pub fn create_state_event_for_empty_key_route(
|
pub fn create_state_event_for_empty_key_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<create_state_event_for_empty_key::Request>,
|
body: Ruma<create_state_event_for_empty_key::Request>,
|
||||||
|
@ -2232,7 +2241,7 @@ pub fn create_state_event_for_empty_key_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/rooms/<_room_id>/state", data = "<body>")]
|
// #[get("/_matrix/client/r0/rooms/<_room_id>/state", data = "<body>")]
|
||||||
pub fn get_state_events_route(
|
pub fn get_state_events_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_state_events::Request>,
|
body: Ruma<get_state_events::Request>,
|
||||||
|
@ -2258,10 +2267,10 @@ pub fn get_state_events_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get(
|
// #[get(
|
||||||
"/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>/<_state_key>",
|
// "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>/<_state_key>",
|
||||||
data = "<body>"
|
// data = "<body>"
|
||||||
)]
|
// )]
|
||||||
pub fn get_state_events_for_key_route(
|
pub fn get_state_events_for_key_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_state_events_for_key::Request>,
|
body: Ruma<get_state_events_for_key::Request>,
|
||||||
|
@ -2293,10 +2302,10 @@ pub fn get_state_events_for_key_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get(
|
// #[get(
|
||||||
"/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>",
|
// "/_matrix/client/r0/rooms/<_room_id>/state/<_event_type>",
|
||||||
data = "<body>"
|
// data = "<body>"
|
||||||
)]
|
// )]
|
||||||
pub fn get_state_events_for_empty_key_route(
|
pub fn get_state_events_for_empty_key_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_state_events_for_empty_key::Request>,
|
body: Ruma<get_state_events_for_empty_key::Request>,
|
||||||
|
@ -2327,7 +2336,7 @@ pub fn get_state_events_for_empty_key_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/sync", data = "<body>")]
|
// #[get("/_matrix/client/r0/sync", data = "<body>")]
|
||||||
pub fn sync_route(
|
pub fn sync_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<sync_events::Request>,
|
body: Ruma<sync_events::Request>,
|
||||||
|
@ -2522,9 +2531,9 @@ pub fn sync_route(
|
||||||
{
|
{
|
||||||
edus.push(
|
edus.push(
|
||||||
serde_json::from_str(
|
serde_json::from_str(
|
||||||
&serde_json::to_string(&EduEvent::Typing(
|
&serde_json::to_string(&EduEvent::Ephemeral(AnyEphemeralRoomEvent::Typing(
|
||||||
db.rooms.edus.roomactives_all(&room_id)?,
|
db.rooms.edus.roomactives_all(&room_id)?,
|
||||||
))
|
)))
|
||||||
.expect("event is valid, we just created it"),
|
.expect("event is valid, we just created it"),
|
||||||
)
|
)
|
||||||
.expect("event is valid, we just created it"),
|
.expect("event is valid, we just created it"),
|
||||||
|
@ -2537,7 +2546,13 @@ pub fn sync_route(
|
||||||
.account_data
|
.account_data
|
||||||
.changes_since(Some(&room_id), &user_id, since)?
|
.changes_since(Some(&room_id), &user_id, since)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(_, v)| v)
|
.flat_map(|(_, v)| {
|
||||||
|
if let Some(EduEvent::Basic(account_event)) = v.deserialize().ok() {
|
||||||
|
Some(EventJson::from(account_event))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
},
|
},
|
||||||
summary: sync_events::RoomSummary {
|
summary: sync_events::RoomSummary {
|
||||||
|
@ -2701,10 +2716,10 @@ pub fn sync_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get(
|
// #[get(
|
||||||
"/_matrix/client/r0/rooms/<_room_id>/context/<_event_id>",
|
// "/_matrix/client/r0/rooms/<_room_id>/context/<_event_id>",
|
||||||
data = "<body>"
|
// data = "<body>"
|
||||||
)]
|
// )]
|
||||||
pub fn get_context_route(
|
pub fn get_context_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_context::Request>,
|
body: Ruma<get_context::Request>,
|
||||||
|
@ -2802,7 +2817,7 @@ pub fn get_context_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/rooms/<_room_id>/messages", data = "<body>")]
|
// #[get("/_matrix/client/r0/rooms/<_room_id>/messages", data = "<body>")]
|
||||||
pub fn get_message_events_route(
|
pub fn get_message_events_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_message_events::Request>,
|
body: Ruma<get_message_events::Request>,
|
||||||
|
@ -2824,15 +2839,16 @@ pub fn get_message_events_route(
|
||||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from` value."))?;
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from` value."))?;
|
||||||
match body.dir {
|
match body.dir {
|
||||||
get_message_events::Direction::Forward => {
|
get_message_events::Direction::Forward => {
|
||||||
|
let limit = body
|
||||||
|
.limit
|
||||||
|
.try_into()
|
||||||
|
.map_or(Ok::<_, Error>(10_usize), |l: u32| Ok(l as usize))?;
|
||||||
|
|
||||||
let events_after = db
|
let events_after = db
|
||||||
.rooms
|
.rooms
|
||||||
.pdus_after(&user_id, &body.room_id, from)
|
.pdus_after(&user_id, &body.room_id, from)
|
||||||
// Use limit or else 10
|
// Use limit or else 10
|
||||||
.take(body.limit.map_or(Ok::<_, Error>(10_usize), |l| {
|
.take(limit)
|
||||||
Ok(u32::try_from(l).map_err(|_| {
|
|
||||||
Error::BadRequest(ErrorKind::InvalidParam, "Limit value is invalid.")
|
|
||||||
})? as usize)
|
|
||||||
})?)
|
|
||||||
.filter_map(|r| r.ok()) // Filter out buggy events
|
.filter_map(|r| r.ok()) // Filter out buggy events
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
@ -2859,15 +2875,16 @@ pub fn get_message_events_route(
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
get_message_events::Direction::Backward => {
|
get_message_events::Direction::Backward => {
|
||||||
|
let limit = body
|
||||||
|
.limit
|
||||||
|
.try_into()
|
||||||
|
.map_or(Ok::<_, Error>(10_usize), |l: u32| Ok(l as usize))?;
|
||||||
|
|
||||||
let events_before = db
|
let events_before = db
|
||||||
.rooms
|
.rooms
|
||||||
.pdus_until(&user_id, &body.room_id, from)
|
.pdus_until(&user_id, &body.room_id, from)
|
||||||
// Use limit or else 10
|
// Use limit or else 10
|
||||||
.take(body.limit.map_or(Ok::<_, Error>(10_usize), |l| {
|
.take(limit)
|
||||||
Ok(u32::try_from(l).map_err(|_| {
|
|
||||||
Error::BadRequest(ErrorKind::InvalidParam, "Limit value is invalid.")
|
|
||||||
})? as usize)
|
|
||||||
})?)
|
|
||||||
.filter_map(|r| r.ok()) // Filter out buggy events
|
.filter_map(|r| r.ok()) // Filter out buggy events
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
@ -2896,7 +2913,7 @@ pub fn get_message_events_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/voip/turnServer")]
|
// #[get("/_matrix/client/r0/voip/turnServer")]
|
||||||
pub fn turn_server_route() -> ConduitResult<create_message_event::Response> {
|
pub fn turn_server_route() -> ConduitResult<create_message_event::Response> {
|
||||||
Err(Error::BadRequest(
|
Err(Error::BadRequest(
|
||||||
ErrorKind::NotFound,
|
ErrorKind::NotFound,
|
||||||
|
@ -2904,7 +2921,7 @@ pub fn turn_server_route() -> ConduitResult<create_message_event::Response> {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/publicised_groups")]
|
// #[post("/_matrix/client/r0/publicised_groups")]
|
||||||
pub fn publicised_groups_route() -> ConduitResult<create_message_event::Response> {
|
pub fn publicised_groups_route() -> ConduitResult<create_message_event::Response> {
|
||||||
Err(Error::BadRequest(
|
Err(Error::BadRequest(
|
||||||
ErrorKind::NotFound,
|
ErrorKind::NotFound,
|
||||||
|
@ -2912,10 +2929,10 @@ pub fn publicised_groups_route() -> ConduitResult<create_message_event::Response
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put(
|
// #[put(
|
||||||
"/_matrix/client/r0/sendToDevice/<_event_type>/<_txn_id>",
|
// "/_matrix/client/r0/sendToDevice/<_event_type>/<_txn_id>",
|
||||||
data = "<body>"
|
// data = "<body>"
|
||||||
)]
|
// )]
|
||||||
pub fn send_event_to_device_route(
|
pub fn send_event_to_device_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<send_event_to_device::Request>,
|
body: Ruma<send_event_to_device::Request>,
|
||||||
|
@ -2961,7 +2978,7 @@ pub fn send_event_to_device_route(
|
||||||
Ok(send_event_to_device::Response.into())
|
Ok(send_event_to_device::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/media/r0/config")]
|
// #[get("/_matrix/media/r0/config")]
|
||||||
pub fn get_media_config_route() -> ConduitResult<get_media_config::Response> {
|
pub fn get_media_config_route() -> ConduitResult<get_media_config::Response> {
|
||||||
Ok(get_media_config::Response {
|
Ok(get_media_config::Response {
|
||||||
upload_size: (20_u32 * 1024 * 1024).into(), // 20 MB
|
upload_size: (20_u32 * 1024 * 1024).into(), // 20 MB
|
||||||
|
@ -2969,7 +2986,7 @@ pub fn get_media_config_route() -> ConduitResult<get_media_config::Response> {
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/media/r0/upload", data = "<body>")]
|
// #[post("/_matrix/media/r0/upload", data = "<body>")]
|
||||||
pub fn create_content_route(
|
pub fn create_content_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<create_content::Request>,
|
body: Ruma<create_content::Request>,
|
||||||
|
@ -2989,10 +3006,10 @@ pub fn create_content_route(
|
||||||
Ok(create_content::Response { content_uri: mxc }.into())
|
Ok(create_content::Response { content_uri: mxc }.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get(
|
// #[get(
|
||||||
"/_matrix/media/r0/download/<_server_name>/<_media_id>",
|
// "/_matrix/media/r0/download/<_server_name>/<_media_id>",
|
||||||
data = "<body>"
|
// data = "<body>"
|
||||||
)]
|
// )]
|
||||||
pub fn get_content_route(
|
pub fn get_content_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_content::Request>,
|
body: Ruma<get_content::Request>,
|
||||||
|
@ -3014,10 +3031,10 @@ pub fn get_content_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get(
|
// #[get(
|
||||||
"/_matrix/media/r0/thumbnail/<_server_name>/<_media_id>",
|
// "/_matrix/media/r0/thumbnail/<_server_name>/<_media_id>",
|
||||||
data = "<body>"
|
// data = "<body>"
|
||||||
)]
|
// )]
|
||||||
pub fn get_content_thumbnail_route(
|
pub fn get_content_thumbnail_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_content_thumbnail::Request>,
|
body: Ruma<get_content_thumbnail::Request>,
|
||||||
|
@ -3039,7 +3056,7 @@ pub fn get_content_thumbnail_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/devices", data = "<body>")]
|
// #[get("/_matrix/client/r0/devices", data = "<body>")]
|
||||||
pub fn get_devices_route(
|
pub fn get_devices_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_devices::Request>,
|
body: Ruma<get_devices::Request>,
|
||||||
|
@ -3055,7 +3072,7 @@ pub fn get_devices_route(
|
||||||
Ok(get_devices::Response { devices }.into())
|
Ok(get_devices::Response { devices }.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/_matrix/client/r0/devices/<_device_id>", data = "<body>")]
|
// #[get("/_matrix/client/r0/devices/<_device_id>", data = "<body>")]
|
||||||
pub fn get_device_route(
|
pub fn get_device_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_device::Request>,
|
body: Ruma<get_device::Request>,
|
||||||
|
@ -3071,7 +3088,7 @@ pub fn get_device_route(
|
||||||
Ok(get_device::Response { device }.into())
|
Ok(get_device::Response { device }.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/_matrix/client/r0/devices/<_device_id>", data = "<body>")]
|
// #[put("/_matrix/client/r0/devices/<_device_id>", data = "<body>")]
|
||||||
pub fn update_device_route(
|
pub fn update_device_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<update_device::Request>,
|
body: Ruma<update_device::Request>,
|
||||||
|
@ -3092,7 +3109,7 @@ pub fn update_device_route(
|
||||||
Ok(update_device::Response.into())
|
Ok(update_device::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[delete("/_matrix/client/r0/devices/<_device_id>", data = "<body>")]
|
// #[delete("/_matrix/client/r0/devices/<_device_id>", data = "<body>")]
|
||||||
pub fn delete_device_route(
|
pub fn delete_device_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<delete_device::Request>,
|
body: Ruma<delete_device::Request>,
|
||||||
|
@ -3136,7 +3153,7 @@ pub fn delete_device_route(
|
||||||
Ok(delete_device::Response.into())
|
Ok(delete_device::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/_matrix/client/r0/delete_devices", data = "<body>")]
|
// #[post("/_matrix/client/r0/delete_devices", data = "<body>")]
|
||||||
pub fn delete_devices_route(
|
pub fn delete_devices_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<delete_devices::Request>,
|
body: Ruma<delete_devices::Request>,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::{utils, Error, Result};
|
use crate::{utils, Error, Result};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::error::ErrorKind,
|
api::client::error::ErrorKind,
|
||||||
events::{collections::only::Event as EduEvent, EventJson, EventType},
|
events::{AnyEvent as EduEvent, EventJson, EventType},
|
||||||
identifiers::{RoomId, UserId},
|
identifiers::{RoomId, UserId},
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, convert::TryFrom};
|
use std::{collections::HashMap, convert::TryFrom};
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
use crate::{utils, Error, Result};
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
|
use crate::{utils, Error, Result};
|
||||||
|
use ruma::identifiers::{ServerName, ServerNameRef};
|
||||||
pub const COUNTER: &str = "c";
|
pub const COUNTER: &str = "c";
|
||||||
|
|
||||||
pub struct Globals {
|
pub struct Globals {
|
||||||
pub(super) globals: sled::Tree,
|
pub(super) globals: sled::Tree,
|
||||||
keypair: ruma::signatures::Ed25519KeyPair,
|
keypair: ruma::signatures::Ed25519KeyPair,
|
||||||
reqwest_client: reqwest::Client,
|
reqwest_client: reqwest::Client,
|
||||||
server_name: String,
|
server_name: ServerName,
|
||||||
registration_disabled: bool,
|
registration_disabled: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,10 +26,13 @@ impl Globals {
|
||||||
globals,
|
globals,
|
||||||
keypair,
|
keypair,
|
||||||
reqwest_client: reqwest::Client::new(),
|
reqwest_client: reqwest::Client::new(),
|
||||||
server_name: config
|
server_name: ServerName::try_from(
|
||||||
.get_str("server_name")
|
config
|
||||||
.unwrap_or("localhost")
|
.get_str("server_name")
|
||||||
.to_owned(),
|
.unwrap_or("localhost")
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.map_err(|_| Error::bad_database("Invalid server name"))?,
|
||||||
registration_disabled: config.get_bool("registration_disabled").unwrap_or(false),
|
registration_disabled: config.get_bool("registration_disabled").unwrap_or(false),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -59,8 +64,8 @@ impl Globals {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn server_name(&self) -> &str {
|
pub fn server_name(&self) -> ServerNameRef<'_> {
|
||||||
&self.server_name
|
self.server_name.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn registration_disabled(&self) -> bool {
|
pub fn registration_disabled(&self) -> bool {
|
||||||
|
|
|
@ -515,7 +515,7 @@ impl Rooms {
|
||||||
event_id: EventId::try_from("$thiswillbefilledinlater").expect("we know this is valid"),
|
event_id: EventId::try_from("$thiswillbefilledinlater").expect("we know this is valid"),
|
||||||
room_id: room_id.clone(),
|
room_id: room_id.clone(),
|
||||||
sender: sender.clone(),
|
sender: sender.clone(),
|
||||||
origin: globals.server_name().to_owned(),
|
origin: globals.server_name().to_string(),
|
||||||
origin_server_ts: utils::millis_since_unix_epoch()
|
origin_server_ts: utils::millis_since_unix_epoch()
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("time is valid"),
|
.expect("time is valid"),
|
||||||
|
@ -529,7 +529,7 @@ impl Rooms {
|
||||||
auth_events: Vec::new(),
|
auth_events: Vec::new(),
|
||||||
redacts: redacts.clone(),
|
redacts: redacts.clone(),
|
||||||
unsigned,
|
unsigned,
|
||||||
hashes: ruma::api::federation::EventHash {
|
hashes: ruma::events::pdu::EventHash {
|
||||||
sha256: "aaa".to_owned(),
|
sha256: "aaa".to_owned(),
|
||||||
},
|
},
|
||||||
signatures: HashMap::new(),
|
signatures: HashMap::new(),
|
||||||
|
@ -547,7 +547,7 @@ impl Rooms {
|
||||||
|
|
||||||
let mut pdu_json = serde_json::to_value(&pdu).expect("event is valid, we just created it");
|
let mut pdu_json = serde_json::to_value(&pdu).expect("event is valid, we just created it");
|
||||||
ruma::signatures::hash_and_sign_event(
|
ruma::signatures::hash_and_sign_event(
|
||||||
globals.server_name(),
|
globals.server_name().as_str(),
|
||||||
globals.keypair(),
|
globals.keypair(),
|
||||||
&mut pdu_json,
|
&mut pdu_json,
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{utils, Error, Result};
|
use crate::{utils, Error, Result};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
events::{collections::only::Event as EduEvent, EventJson},
|
events::{AnyEvent as EduEvent, EventJson},
|
||||||
identifiers::{RoomId, UserId},
|
identifiers::{RoomId, UserId},
|
||||||
};
|
};
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
@ -235,7 +235,7 @@ impl RoomEdus {
|
||||||
|
|
||||||
Ok(ruma::events::typing::TypingEvent {
|
Ok(ruma::events::typing::TypingEvent {
|
||||||
content: ruma::events::typing::TypingEventContent { user_ids },
|
content: ruma::events::typing::TypingEventContent { user_ids },
|
||||||
room_id: None, // Can be inferred
|
room_id: room_id.clone(), // Can be inferred
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use ruma::{
|
||||||
keys::{AlgorithmAndDeviceId, CrossSigningKey, DeviceKeys, KeyAlgorithm, OneTimeKey},
|
keys::{AlgorithmAndDeviceId, CrossSigningKey, DeviceKeys, KeyAlgorithm, OneTimeKey},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
events::{to_device::AnyToDeviceEvent, EventJson, EventType},
|
events::{AnyToDeviceEvent, EventJson, EventType},
|
||||||
identifiers::UserId,
|
identifiers::UserId,
|
||||||
};
|
};
|
||||||
use std::{collections::BTreeMap, convert::TryFrom, time::SystemTime};
|
use std::{collections::BTreeMap, convert::TryFrom, time::SystemTime};
|
||||||
|
|
|
@ -25,6 +25,11 @@ pub enum Error {
|
||||||
#[from]
|
#[from]
|
||||||
source: image::error::ImageError,
|
source: image::error::ImageError,
|
||||||
},
|
},
|
||||||
|
#[error("Could not deserialize json")]
|
||||||
|
SerdeError {
|
||||||
|
#[from]
|
||||||
|
source: serde_json::Error,
|
||||||
|
},
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
BadConfig(&'static str),
|
BadConfig(&'static str),
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
|
|
19
src/pdu.rs
19
src/pdu.rs
|
@ -1,12 +1,9 @@
|
||||||
use crate::{Error, Result};
|
use crate::{Error, Result};
|
||||||
use js_int::UInt;
|
use js_int::UInt;
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::federation::EventHash,
|
|
||||||
events::{
|
events::{
|
||||||
collections::all::{RoomEvent, StateEvent},
|
pdu::EventHash, AnyRoomEvent, AnyStateEvent, AnyStrippedStateEventStub, EventJson,
|
||||||
room::member::MemberEvent,
|
EventType,
|
||||||
stripped::AnyStrippedStateEvent,
|
|
||||||
EventJson, EventType,
|
|
||||||
},
|
},
|
||||||
identifiers::{EventId, RoomId, UserId},
|
identifiers::{EventId, RoomId, UserId},
|
||||||
};
|
};
|
||||||
|
@ -81,19 +78,19 @@ impl PduEvent {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_room_event(&self) -> EventJson<RoomEvent> {
|
pub fn to_room_event(&self) -> EventJson<AnyRoomEvent> {
|
||||||
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
||||||
serde_json::from_str::<EventJson<RoomEvent>>(&json)
|
serde_json::from_str::<EventJson<AnyRoomEvent>>(&json)
|
||||||
.expect("EventJson::from_str always works")
|
.expect("EventJson::from_str always works")
|
||||||
}
|
}
|
||||||
pub fn to_state_event(&self) -> EventJson<StateEvent> {
|
pub fn to_state_event(&self) -> EventJson<AnyStateEvent> {
|
||||||
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
||||||
serde_json::from_str::<EventJson<StateEvent>>(&json)
|
serde_json::from_str::<EventJson<AnyStateEvent>>(&json)
|
||||||
.expect("EventJson::from_str always works")
|
.expect("EventJson::from_str always works")
|
||||||
}
|
}
|
||||||
pub fn to_stripped_state_event(&self) -> EventJson<AnyStrippedStateEvent> {
|
pub fn to_stripped_state_event(&self) -> EventJson<AnyStrippedStateEventStub> {
|
||||||
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
let json = serde_json::to_string(&self).expect("PDUs are always valid");
|
||||||
serde_json::from_str::<EventJson<AnyStrippedStateEvent>>(&json)
|
serde_json::from_str::<EventJson<AnyStrippedStateEventStub>>(&json)
|
||||||
.expect("EventJson::from_str always works")
|
.expect("EventJson::from_str always works")
|
||||||
}
|
}
|
||||||
pub fn to_member_event(&self) -> EventJson<MemberEvent> {
|
pub fn to_member_event(&self) -> EventJson<MemberEvent> {
|
||||||
|
|
Loading…
Reference in New Issue