improvement: flush after every request that manipulates the db

This commit is contained in:
Timo Kösters 2020-10-21 21:28:02 +02:00
parent b2a1505535
commit 6dbe195695
No known key found for this signature in database
GPG Key ID: 24DA7517711A2BA4
30 changed files with 216 additions and 105 deletions

View File

@ -36,7 +36,7 @@ const GUEST_NAME_LENGTH: usize = 10;
feature = "conduit_bin",
get("/_matrix/client/r0/register/available", data = "<body>")
)]
pub fn get_register_available_route(
pub async fn get_register_available_route(
db: State<'_, Database>,
body: Ruma<get_username_availability::Request<'_>>,
) -> ConduitResult<get_username_availability::Response> {
@ -466,6 +466,8 @@ pub async fn register_route(
)?;
}
db.flush().await?;
Ok(register::Response {
access_token: Some(token),
user_id,
@ -485,7 +487,7 @@ pub async fn register_route(
feature = "conduit_bin",
post("/_matrix/client/r0/account/password", data = "<body>")
)]
pub fn change_password_route(
pub async fn change_password_route(
db: State<'_, Database>,
body: Ruma<change_password::Request<'_>>,
) -> ConduitResult<change_password::Response> {
@ -535,6 +537,8 @@ pub fn change_password_route(
db.users.remove_device(&sender_user, &id)?;
}
db.flush().await?;
Ok(change_password::Response.into())
}
@ -547,7 +551,7 @@ pub fn change_password_route(
feature = "conduit_bin",
get("/_matrix/client/r0/account/whoami", data = "<body>")
)]
pub fn whoami_route(body: Ruma<whoami::Request>) -> ConduitResult<whoami::Response> {
pub async fn whoami_route(body: Ruma<whoami::Request>) -> ConduitResult<whoami::Response> {
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
Ok(whoami::Response {
user_id: sender_user.clone(),
@ -637,6 +641,8 @@ pub async fn deactivate_route(
// Remove devices and mark account as deactivated
db.users.deactivate_account(&sender_user)?;
db.flush().await?;
Ok(deactivate::Response {
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
}

View File

@ -18,7 +18,7 @@ use rocket::{delete, get, put};
feature = "conduit_bin",
put("/_matrix/client/r0/directory/room/<_>", data = "<body>")
)]
pub fn create_alias_route(
pub async fn create_alias_route(
db: State<'_, Database>,
body: Ruma<create_alias::Request<'_>>,
) -> ConduitResult<create_alias::Response> {
@ -29,6 +29,8 @@ pub fn create_alias_route(
db.rooms
.set_alias(&body.room_alias, Some(&body.room_id), &db.globals)?;
db.flush().await?;
Ok(create_alias::Response::new().into())
}
@ -36,12 +38,14 @@ pub fn create_alias_route(
feature = "conduit_bin",
delete("/_matrix/client/r0/directory/room/<_>", data = "<body>")
)]
pub fn delete_alias_route(
pub async fn delete_alias_route(
db: State<'_, Database>,
body: Ruma<delete_alias::Request<'_>>,
) -> ConduitResult<delete_alias::Response> {
db.rooms.set_alias(&body.room_alias, None, &db.globals)?;
db.flush().await?;
Ok(delete_alias::Response::new().into())
}

View File

@ -17,7 +17,7 @@ use rocket::{delete, get, post, put};
feature = "conduit_bin",
post("/_matrix/client/unstable/room_keys/version", data = "<body>")
)]
pub fn create_backup_route(
pub async fn create_backup_route(
db: State<'_, Database>,
body: Ruma<create_backup::Request>,
) -> ConduitResult<create_backup::Response> {
@ -26,6 +26,8 @@ pub fn create_backup_route(
.key_backups
.create_backup(&sender_user, &body.algorithm, &db.globals)?;
db.flush().await?;
Ok(create_backup::Response { version }.into())
}
@ -33,7 +35,7 @@ pub fn create_backup_route(
feature = "conduit_bin",
put("/_matrix/client/unstable/room_keys/version/<_>", data = "<body>")
)]
pub fn update_backup_route(
pub async fn update_backup_route(
db: State<'_, Database>,
body: Ruma<update_backup::Request<'_>>,
) -> ConduitResult<update_backup::Response> {
@ -41,6 +43,8 @@ pub fn update_backup_route(
db.key_backups
.update_backup(&sender_user, &body.version, &body.algorithm, &db.globals)?;
db.flush().await?;
Ok(update_backup::Response.into())
}
@ -48,7 +52,7 @@ pub fn update_backup_route(
feature = "conduit_bin",
get("/_matrix/client/unstable/room_keys/version", data = "<body>")
)]
pub fn get_latest_backup_route(
pub async fn get_latest_backup_route(
db: State<'_, Database>,
body: Ruma<get_latest_backup::Request>,
) -> ConduitResult<get_latest_backup::Response> {
@ -75,7 +79,7 @@ pub fn get_latest_backup_route(
feature = "conduit_bin",
get("/_matrix/client/unstable/room_keys/version/<_>", data = "<body>")
)]
pub fn get_backup_route(
pub async fn get_backup_route(
db: State<'_, Database>,
body: Ruma<get_backup::Request<'_>>,
) -> ConduitResult<get_backup::Response> {
@ -101,7 +105,7 @@ pub fn get_backup_route(
feature = "conduit_bin",
delete("/_matrix/client/unstable/room_keys/version/<_>", data = "<body>")
)]
pub fn delete_backup_route(
pub async fn delete_backup_route(
db: State<'_, Database>,
body: Ruma<delete_backup::Request>,
) -> ConduitResult<delete_backup::Response> {
@ -109,6 +113,8 @@ pub fn delete_backup_route(
db.key_backups.delete_backup(&sender_user, &body.version)?;
db.flush().await?;
Ok(delete_backup::Response.into())
}
@ -117,7 +123,7 @@ pub fn delete_backup_route(
feature = "conduit_bin",
put("/_matrix/client/unstable/room_keys/keys", data = "<body>")
)]
pub fn add_backup_keys_route(
pub async fn add_backup_keys_route(
db: State<'_, Database>,
body: Ruma<add_backup_keys::Request<'_>>,
) -> ConduitResult<add_backup_keys::Response> {
@ -136,6 +142,8 @@ pub fn add_backup_keys_route(
}
}
db.flush().await?;
Ok(add_backup_keys::Response {
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
etag: db.key_backups.get_etag(sender_user, &body.version)?,
@ -148,7 +156,7 @@ pub fn add_backup_keys_route(
feature = "conduit_bin",
put("/_matrix/client/unstable/room_keys/keys/<_>", data = "<body>")
)]
pub fn add_backup_key_sessions_route(
pub async fn add_backup_key_sessions_route(
db: State<'_, Database>,
body: Ruma<add_backup_key_sessions::Request>,
) -> ConduitResult<add_backup_key_sessions::Response> {
@ -165,6 +173,8 @@ pub fn add_backup_key_sessions_route(
)?
}
db.flush().await?;
Ok(add_backup_key_sessions::Response {
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
etag: db.key_backups.get_etag(sender_user, &body.version)?,
@ -177,7 +187,7 @@ pub fn add_backup_key_sessions_route(
feature = "conduit_bin",
put("/_matrix/client/unstable/room_keys/keys/<_>/<_>", data = "<body>")
)]
pub fn add_backup_key_session_route(
pub async fn add_backup_key_session_route(
db: State<'_, Database>,
body: Ruma<add_backup_key_session::Request>,
) -> ConduitResult<add_backup_key_session::Response> {
@ -192,6 +202,8 @@ pub fn add_backup_key_session_route(
&db.globals,
)?;
db.flush().await?;
Ok(add_backup_key_session::Response {
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
etag: db.key_backups.get_etag(sender_user, &body.version)?,
@ -203,7 +215,7 @@ pub fn add_backup_key_session_route(
feature = "conduit_bin",
get("/_matrix/client/unstable/room_keys/keys", data = "<body>")
)]
pub fn get_backup_keys_route(
pub async fn get_backup_keys_route(
db: State<'_, Database>,
body: Ruma<get_backup_keys::Request<'_>>,
) -> ConduitResult<get_backup_keys::Response> {
@ -218,7 +230,7 @@ pub fn get_backup_keys_route(
feature = "conduit_bin",
get("/_matrix/client/unstable/room_keys/keys/<_>", data = "<body>")
)]
pub fn get_backup_key_sessions_route(
pub async fn get_backup_key_sessions_route(
db: State<'_, Database>,
body: Ruma<get_backup_key_sessions::Request>,
) -> ConduitResult<get_backup_key_sessions::Response> {
@ -235,7 +247,7 @@ pub fn get_backup_key_sessions_route(
feature = "conduit_bin",
get("/_matrix/client/unstable/room_keys/keys/<_>/<_>", data = "<body>")
)]
pub fn get_backup_key_session_route(
pub async fn get_backup_key_session_route(
db: State<'_, Database>,
body: Ruma<get_backup_key_session::Request>,
) -> ConduitResult<get_backup_key_session::Response> {
@ -252,7 +264,7 @@ pub fn get_backup_key_session_route(
feature = "conduit_bin",
delete("/_matrix/client/unstable/room_keys/keys", data = "<body>")
)]
pub fn delete_backup_keys_route(
pub async fn delete_backup_keys_route(
db: State<'_, Database>,
body: Ruma<delete_backup_keys::Request>,
) -> ConduitResult<delete_backup_keys::Response> {
@ -261,6 +273,8 @@ pub fn delete_backup_keys_route(
db.key_backups
.delete_all_keys(&sender_user, &body.version)?;
db.flush().await?;
Ok(delete_backup_keys::Response {
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
etag: db.key_backups.get_etag(sender_user, &body.version)?,
@ -272,7 +286,7 @@ pub fn delete_backup_keys_route(
feature = "conduit_bin",
delete("/_matrix/client/unstable/room_keys/keys/<_>", data = "<body>")
)]
pub fn delete_backup_key_sessions_route(
pub async fn delete_backup_key_sessions_route(
db: State<'_, Database>,
body: Ruma<delete_backup_key_sessions::Request>,
) -> ConduitResult<delete_backup_key_sessions::Response> {
@ -281,6 +295,8 @@ pub fn delete_backup_key_sessions_route(
db.key_backups
.delete_room_keys(&sender_user, &body.version, &body.room_id)?;
db.flush().await?;
Ok(delete_backup_key_sessions::Response {
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
etag: db.key_backups.get_etag(sender_user, &body.version)?,
@ -292,7 +308,7 @@ pub fn delete_backup_key_sessions_route(
feature = "conduit_bin",
delete("/_matrix/client/unstable/room_keys/keys/<_>/<_>", data = "<body>")
)]
pub fn delete_backup_key_session_route(
pub async fn delete_backup_key_session_route(
db: State<'_, Database>,
body: Ruma<delete_backup_key_session::Request>,
) -> ConduitResult<delete_backup_key_session::Response> {
@ -301,6 +317,8 @@ pub fn delete_backup_key_session_route(
db.key_backups
.delete_room_key(&sender_user, &body.version, &body.room_id, &body.session_id)?;
db.flush().await?;
Ok(delete_backup_key_session::Response {
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
etag: db.key_backups.get_etag(sender_user, &body.version)?,

View File

@ -9,7 +9,7 @@ use rocket::get;
///
/// Get information on this server's supported feature set and other relevent capabilities.
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/capabilities"))]
pub fn get_capabilities_route() -> ConduitResult<get_capabilities::Response> {
pub async fn get_capabilities_route() -> ConduitResult<get_capabilities::Response> {
let mut available = BTreeMap::new();
available.insert(
RoomVersionId::Version5,

View File

@ -16,7 +16,7 @@ use rocket::{get, put};
feature = "conduit_bin",
put("/_matrix/client/r0/user/<_>/account_data/<_>", data = "<body>")
)]
pub fn set_global_account_data_route(
pub async fn set_global_account_data_route(
db: State<'_, Database>,
body: Ruma<set_global_account_data::Request<'_>>,
) -> ConduitResult<set_global_account_data::Response> {
@ -40,6 +40,8 @@ pub fn set_global_account_data_route(
&db.globals,
)?;
db.flush().await?;
Ok(set_global_account_data::Response.into())
}
@ -47,7 +49,7 @@ pub fn set_global_account_data_route(
feature = "conduit_bin",
get("/_matrix/client/r0/user/<_>/account_data/<_>", data = "<body>")
)]
pub fn get_global_account_data_route(
pub async fn get_global_account_data_route(
db: State<'_, Database>,
body: Ruma<get_global_account_data::Request<'_>>,
) -> ConduitResult<get_global_account_data::Response> {
@ -58,5 +60,7 @@ pub fn get_global_account_data_route(
.get::<Raw<ruma::events::AnyBasicEvent>>(None, sender_user, body.event_type.clone().into())?
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?;
db.flush().await?;
Ok(get_global_account_data::Response { account_data: data }.into())
}

View File

@ -10,7 +10,7 @@ use rocket::get;
feature = "conduit_bin",
get("/_matrix/client/r0/rooms/<_>/context/<_>", data = "<body>")
)]
pub fn get_context_route(
pub async fn get_context_route(
db: State<'_, Database>,
body: Ruma<get_context::Request<'_>>,
) -> ConduitResult<get_context::Response> {

View File

@ -16,7 +16,7 @@ use rocket::{delete, get, post, put};
feature = "conduit_bin",
get("/_matrix/client/r0/devices", data = "<body>")
)]
pub fn get_devices_route(
pub async fn get_devices_route(
db: State<'_, Database>,
body: Ruma<get_devices::Request>,
) -> ConduitResult<get_devices::Response> {
@ -35,7 +35,7 @@ pub fn get_devices_route(
feature = "conduit_bin",
get("/_matrix/client/r0/devices/<_>", data = "<body>")
)]
pub fn get_device_route(
pub async fn get_device_route(
db: State<'_, Database>,
body: Ruma<get_device::Request<'_>>,
) -> ConduitResult<get_device::Response> {
@ -53,7 +53,7 @@ pub fn get_device_route(
feature = "conduit_bin",
put("/_matrix/client/r0/devices/<_>", data = "<body>")
)]
pub fn update_device_route(
pub async fn update_device_route(
db: State<'_, Database>,
body: Ruma<update_device::Request<'_>>,
) -> ConduitResult<update_device::Response> {
@ -69,6 +69,8 @@ pub fn update_device_route(
db.users
.update_device_metadata(&sender_user, &body.device_id, &device)?;
db.flush().await?;
Ok(update_device::Response.into())
}
@ -76,7 +78,7 @@ pub fn update_device_route(
feature = "conduit_bin",
delete("/_matrix/client/r0/devices/<_>", data = "<body>")
)]
pub fn delete_device_route(
pub async fn delete_device_route(
db: State<'_, Database>,
body: Ruma<delete_device::Request<'_>>,
) -> ConduitResult<delete_device::Response> {
@ -115,6 +117,8 @@ pub fn delete_device_route(
db.users.remove_device(&sender_user, &body.device_id)?;
db.flush().await?;
Ok(delete_device::Response.into())
}
@ -122,7 +126,7 @@ pub fn delete_device_route(
feature = "conduit_bin",
post("/_matrix/client/r0/delete_devices", data = "<body>")
)]
pub fn delete_devices_route(
pub async fn delete_devices_route(
db: State<'_, Database>,
body: Ruma<delete_devices::Request<'_>>,
) -> ConduitResult<delete_devices::Response> {
@ -163,5 +167,7 @@ pub fn delete_devices_route(
db.users.remove_device(&sender_user, &device_id)?
}
db.flush().await?;
Ok(delete_devices::Response.into())
}

View File

@ -87,6 +87,8 @@ pub async fn set_room_visibility_route(
room::Visibility::Private => db.rooms.set_public(&body.room_id, false)?,
}
db.flush().await?;
Ok(set_room_visibility::Response.into())
}

View File

@ -5,7 +5,7 @@ use ruma::api::client::r0::filter::{self, create_filter, get_filter};
use rocket::{get, post};
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/user/<_>/filter/<_>"))]
pub fn get_filter_route() -> ConduitResult<get_filter::Response> {
pub async fn get_filter_route() -> ConduitResult<get_filter::Response> {
// TODO
Ok(get_filter::Response::new(filter::IncomingFilterDefinition {
event_fields: None,
@ -18,7 +18,7 @@ pub fn get_filter_route() -> ConduitResult<get_filter::Response> {
}
#[cfg_attr(feature = "conduit_bin", post("/_matrix/client/r0/user/<_>/filter"))]
pub fn create_filter_route() -> ConduitResult<create_filter::Response> {
pub async fn create_filter_route() -> ConduitResult<create_filter::Response> {
// TODO
Ok(create_filter::Response::new(utils::random_string(10)).into())
}

View File

@ -22,7 +22,7 @@ use rocket::{get, post};
feature = "conduit_bin",
post("/_matrix/client/r0/keys/upload", data = "<body>")
)]
pub fn upload_keys_route(
pub async fn upload_keys_route(
db: State<'_, Database>,
body: Ruma<upload_keys::Request<'_>>,
) -> ConduitResult<upload_keys::Response> {
@ -58,6 +58,8 @@ pub fn upload_keys_route(
}
}
db.flush().await?;
Ok(upload_keys::Response {
one_time_key_counts: db.users.count_one_time_keys(sender_user, sender_device)?,
}
@ -68,7 +70,7 @@ pub fn upload_keys_route(
feature = "conduit_bin",
post("/_matrix/client/r0/keys/query", data = "<body>")
)]
pub fn get_keys_route(
pub async fn get_keys_route(
db: State<'_, Database>,
body: Ruma<get_keys::Request<'_>>,
) -> ConduitResult<get_keys::Response> {
@ -148,7 +150,7 @@ pub fn get_keys_route(
feature = "conduit_bin",
post("/_matrix/client/r0/keys/claim", data = "<body>")
)]
pub fn claim_keys_route(
pub async fn claim_keys_route(
db: State<'_, Database>,
body: Ruma<claim_keys::Request>,
) -> ConduitResult<claim_keys::Response> {
@ -168,6 +170,8 @@ pub fn claim_keys_route(
one_time_keys.insert(user_id.clone(), container);
}
db.flush().await?;
Ok(claim_keys::Response {
failures: BTreeMap::new(),
one_time_keys,
@ -179,7 +183,7 @@ pub fn claim_keys_route(
feature = "conduit_bin",
post("/_matrix/client/unstable/keys/device_signing/upload", data = "<body>")
)]
pub fn upload_signing_keys_route(
pub async fn upload_signing_keys_route(
db: State<'_, Database>,
body: Ruma<upload_signing_keys::Request<'_>>,
) -> ConduitResult<upload_signing_keys::Response> {
@ -227,6 +231,8 @@ pub fn upload_signing_keys_route(
)?;
}
db.flush().await?;
Ok(upload_signing_keys::Response.into())
}
@ -234,7 +240,7 @@ pub fn upload_signing_keys_route(
feature = "conduit_bin",
post("/_matrix/client/unstable/keys/signatures/upload", data = "<body>")
)]
pub fn upload_signatures_route(
pub async fn upload_signatures_route(
db: State<'_, Database>,
body: Ruma<upload_signatures::Request>,
) -> ConduitResult<upload_signatures::Response> {
@ -285,6 +291,8 @@ pub fn upload_signatures_route(
}
}
db.flush().await?;
Ok(upload_signatures::Response.into())
}
@ -292,7 +300,7 @@ pub fn upload_signatures_route(
feature = "conduit_bin",
get("/_matrix/client/r0/keys/changes", data = "<body>")
)]
pub fn get_key_changes_route(
pub async fn get_key_changes_route(
db: State<'_, Database>,
body: Ruma<get_key_changes::Request<'_>>,
) -> ConduitResult<get_key_changes::Response> {

View File

@ -14,7 +14,7 @@ use std::convert::TryInto;
const MXC_LENGTH: usize = 32;
#[cfg_attr(feature = "conduit_bin", get("/_matrix/media/r0/config"))]
pub fn get_media_config_route(
pub async fn get_media_config_route(
db: State<'_, Database>,
) -> ConduitResult<get_media_config::Response> {
Ok(get_media_config::Response {
@ -27,7 +27,7 @@ pub fn get_media_config_route(
feature = "conduit_bin",
post("/_matrix/media/r0/upload", data = "<body>")
)]
pub fn create_content_route(
pub async fn create_content_route(
db: State<'_, Database>,
body: Ruma<create_content::Request<'_>>,
) -> ConduitResult<create_content::Response> {
@ -43,6 +43,8 @@ pub fn create_content_route(
&body.file,
)?;
db.flush().await?;
Ok(create_content::Response { content_uri: mxc }.into())
}

View File

@ -65,17 +65,19 @@ pub async fn join_room_by_id_or_alias_route(
}
};
Ok(join_room_by_id_or_alias::Response {
room_id: join_room_by_id_helper(
let join_room_response = join_room_by_id_helper(
&db,
body.sender_user.as_ref(),
&room_id,
&servers,
body.third_party_signed.as_ref(),
)
.await?
.0
.room_id,
.await?;
db.flush().await?;
Ok(join_room_by_id_or_alias::Response {
room_id: join_room_response.0.room_id,
}
.into())
}
@ -124,6 +126,8 @@ pub async fn leave_room_route(
&db.account_data,
)?;
db.flush().await?;
Ok(leave_room::Response::new().into())
}
@ -160,6 +164,8 @@ pub async fn invite_user_route(
&db.account_data,
)?;
db.flush().await?;
Ok(invite_user::Response.into())
} else {
Err(Error::BadRequest(ErrorKind::NotFound, "User not found."))
@ -211,6 +217,8 @@ pub async fn kick_user_route(
&db.account_data,
)?;
db.flush().await?;
Ok(kick_user::Response::new().into())
}
@ -267,6 +275,8 @@ pub async fn ban_user_route(
&db.account_data,
)?;
db.flush().await?;
Ok(ban_user::Response::new().into())
}
@ -314,6 +324,8 @@ pub async fn unban_user_route(
&db.account_data,
)?;
db.flush().await?;
Ok(unban_user::Response::new().into())
}
@ -321,7 +333,7 @@ pub async fn unban_user_route(
feature = "conduit_bin",
post("/_matrix/client/r0/rooms/<_>/forget", data = "<body>")
)]
pub fn forget_room_route(
pub async fn forget_room_route(
db: State<'_, Database>,
body: Ruma<forget_room::Request<'_>>,
) -> ConduitResult<forget_room::Response> {
@ -329,6 +341,8 @@ pub fn forget_room_route(
db.rooms.forget(&body.room_id, &sender_user)?;
db.flush().await?;
Ok(forget_room::Response::new().into())
}
@ -336,7 +350,7 @@ pub fn forget_room_route(
feature = "conduit_bin",
get("/_matrix/client/r0/joined_rooms", data = "<body>")
)]
pub fn joined_rooms_route(
pub async fn joined_rooms_route(
db: State<'_, Database>,
body: Ruma<joined_rooms::Request>,
) -> ConduitResult<joined_rooms::Response> {
@ -356,7 +370,7 @@ pub fn joined_rooms_route(
feature = "conduit_bin",
get("/_matrix/client/r0/rooms/<_>/members", data = "<body>")
)]
pub fn get_member_events_route(
pub async fn get_member_events_route(
db: State<'_, Database>,
body: Ruma<get_member_events::Request<'_>>,
) -> ConduitResult<get_member_events::Response> {
@ -384,7 +398,7 @@ pub fn get_member_events_route(
feature = "conduit_bin",
get("/_matrix/client/r0/rooms/<_>/joined_members", data = "<body>")
)]
pub fn joined_members_route(
pub async fn joined_members_route(
db: State<'_, Database>,
body: Ruma<joined_members::Request<'_>>,
) -> ConduitResult<joined_members::Response> {

View File

@ -77,6 +77,8 @@ pub async fn send_message_event_route(
event_id.as_bytes(),
)?;
db.flush().await?;
Ok(send_message_event::Response::new(event_id).into())
}
@ -84,7 +86,7 @@ pub async fn send_message_event_route(
feature = "conduit_bin",
get("/_matrix/client/r0/rooms/<_>/messages", data = "<body>")
)]
pub fn get_message_events_route(
pub async fn get_message_events_route(
db: State<'_, Database>,
body: Ruma<get_message_events::Request<'_>>,
) -> ConduitResult<get_message_events::Response> {

View File

@ -75,6 +75,6 @@ const SESSION_ID_LENGTH: usize = 256;
#[cfg(feature = "conduit_bin")]
#[options("/<_..>")]
pub fn options_route() -> ConduitResult<send_event_to_device::Response> {
pub async fn options_route() -> ConduitResult<send_event_to_device::Response> {
Ok(send_event_to_device::Response.into())
}

View File

@ -10,7 +10,7 @@ use rocket::put;
feature = "conduit_bin",
put("/_matrix/client/r0/presence/<_>/status", data = "<body>")
)]
pub fn set_presence_route(
pub async fn set_presence_route(
db: State<'_, Database>,
body: Ruma<set_presence::Request<'_>>,
) -> ConduitResult<set_presence::Response> {
@ -41,5 +41,7 @@ pub fn set_presence_route(
)?;
}
db.flush().await?;
Ok(set_presence::Response.into())
}

View File

@ -90,6 +90,8 @@ pub async fn set_displayname_route(
)?;
}
db.flush().await?;
Ok(set_display_name::Response.into())
}
@ -97,7 +99,7 @@ pub async fn set_displayname_route(
feature = "conduit_bin",
get("/_matrix/client/r0/profile/<_>/displayname", data = "<body>")
)]
pub fn get_displayname_route(
pub async fn get_displayname_route(
db: State<'_, Database>,
body: Ruma<get_display_name::Request<'_>>,
) -> ConduitResult<get_display_name::Response> {
@ -182,6 +184,8 @@ pub async fn set_avatar_url_route(
)?;
}
db.flush().await?;
Ok(set_avatar_url::Response.into())
}
@ -189,7 +193,7 @@ pub async fn set_avatar_url_route(
feature = "conduit_bin",
get("/_matrix/client/r0/profile/<_>/avatar_url", data = "<body>")
)]
pub fn get_avatar_url_route(
pub async fn get_avatar_url_route(
db: State<'_, Database>,
body: Ruma<get_avatar_url::Request<'_>>,
) -> ConduitResult<get_avatar_url::Response> {
@ -203,7 +207,7 @@ pub fn get_avatar_url_route(
feature = "conduit_bin",
get("/_matrix/client/r0/profile/<_>", data = "<body>")
)]
pub fn get_profile_route(
pub async fn get_profile_route(
db: State<'_, Database>,
body: Ruma<get_profile::Request<'_>>,
) -> ConduitResult<get_profile::Response> {

View File

@ -16,7 +16,7 @@ use rocket::{get, post, put};
feature = "conduit_bin",
get("/_matrix/client/r0/pushrules", data = "<body>")
)]
pub fn get_pushrules_all_route(
pub async fn get_pushrules_all_route(
db: State<'_, Database>,
body: Ruma<get_pushrules_all::Request>,
) -> ConduitResult<get_pushrules_all::Response> {
@ -40,11 +40,15 @@ pub fn get_pushrules_all_route(
"/_matrix/client/r0/pushrules/<_>/<_>/<_>",
//data = "<body>"
))]
pub fn set_pushrule_route(//db: State<'_, Database>,
pub async fn set_pushrule_route(
db: State<'_, Database>,
//body: Ruma<set_pushrule::Request>,
) -> ConduitResult<set_pushrule::Response> {
// TODO
warn!("TODO: set_pushrule_route");
db.flush().await?;
Ok(set_pushrule::Response.into())
}
@ -52,14 +56,19 @@ pub fn set_pushrule_route(//db: State<'_, Database>,
feature = "conduit_bin",
put("/_matrix/client/r0/pushrules/<_>/<_>/<_>/enabled")
)]
pub fn set_pushrule_enabled_route() -> ConduitResult<set_pushrule_enabled::Response> {
pub async fn set_pushrule_enabled_route(
db: State<'_, Database>,
) -> ConduitResult<set_pushrule_enabled::Response> {
// TODO
warn!("TODO: set_pushrule_enabled_route");
db.flush().await?;
Ok(set_pushrule_enabled::Response.into())
}
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/pushers"))]
pub fn get_pushers_route() -> ConduitResult<get_pushers::Response> {
pub async fn get_pushers_route() -> ConduitResult<get_pushers::Response> {
Ok(get_pushers::Response {
pushers: Vec::new(),
}
@ -67,7 +76,9 @@ pub fn get_pushers_route() -> ConduitResult<get_pushers::Response> {
}
#[cfg_attr(feature = "conduit_bin", post("/_matrix/client/r0/pushers/set"))]
pub fn set_pushers_route() -> ConduitResult<get_pushers::Response> {
pub async fn set_pushers_route(db: State<'_, Database>) -> ConduitResult<get_pushers::Response> {
db.flush().await?;
Ok(get_pushers::Response {
pushers: Vec::new(),
}

View File

@ -13,7 +13,7 @@ use std::{collections::BTreeMap, time::SystemTime};
feature = "conduit_bin",
post("/_matrix/client/r0/rooms/<_>/read_markers", data = "<body>")
)]
pub fn set_read_marker_route(
pub async fn set_read_marker_route(
db: State<'_, Database>,
body: Ruma<set_read_marker::Request<'_>>,
) -> ConduitResult<set_read_marker::Response> {
@ -71,5 +71,8 @@ pub fn set_read_marker_route(
&db.globals,
)?;
}
db.flush().await?;
Ok(set_read_marker::Response.into())
}

View File

@ -36,5 +36,7 @@ pub async fn redact_event_route(
&db.account_data,
)?;
db.flush().await?;
Ok(redact_event::Response { event_id }.into())
}

View File

@ -313,6 +313,8 @@ pub async fn create_room_route(
db.rooms.set_public(&room_id, true)?;
}
db.flush().await?;
Ok(create_room::Response::new(room_id).into())
}
@ -320,7 +322,7 @@ pub async fn create_room_route(
feature = "conduit_bin",
get("/_matrix/client/r0/rooms/<_>/event/<_>", data = "<body>")
)]
pub fn get_room_event_route(
pub async fn get_room_event_route(
db: State<'_, Database>,
body: Ruma<get_room_event::Request<'_>>,
) -> ConduitResult<get_room_event::Response> {
@ -531,6 +533,8 @@ pub async fn upgrade_room_route(
&db.account_data,
)?;
db.flush().await?;
// Return the replacement room id
Ok(upgrade_room::Response { replacement_room }.into())
}

View File

@ -11,7 +11,7 @@ use std::collections::BTreeMap;
feature = "conduit_bin",
post("/_matrix/client/r0/search", data = "<body>")
)]
pub fn search_events_route(
pub async fn search_events_route(
db: State<'_, Database>,
body: Ruma<search_events::Request<'_>>,
) -> ConduitResult<search_events::Response> {

View File

@ -16,7 +16,7 @@ use rocket::{get, post};
/// Get the homeserver's supported login types. One of these should be used as the `type` field
/// when logging in.
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/login"))]
pub fn get_login_types_route() -> ConduitResult<get_login_types::Response> {
pub async fn get_login_types_route() -> ConduitResult<get_login_types::Response> {
Ok(get_login_types::Response::new(vec![get_login_types::LoginType::Password]).into())
}
@ -34,7 +34,7 @@ pub fn get_login_types_route() -> ConduitResult<get_login_types::Response> {
feature = "conduit_bin",
post("/_matrix/client/r0/login", data = "<body>")
)]
pub fn login_route(
pub async fn login_route(
db: State<'_, Database>,
body: Ruma<login::Request<'_>>,
) -> ConduitResult<login::Response> {
@ -93,6 +93,8 @@ pub fn login_route(
body.initial_device_display_name.clone(),
)?;
db.flush().await?;
Ok(login::Response {
user_id,
access_token: token,
@ -113,7 +115,7 @@ pub fn login_route(
feature = "conduit_bin",
post("/_matrix/client/r0/logout", data = "<body>")
)]
pub fn logout_route(
pub async fn logout_route(
db: State<'_, Database>,
body: Ruma<logout::Request>,
) -> ConduitResult<logout::Response> {
@ -122,6 +124,8 @@ pub fn logout_route(
db.users.remove_device(&sender_user, sender_device)?;
db.flush().await?;
Ok(logout::Response::new().into())
}
@ -138,7 +142,7 @@ pub fn logout_route(
feature = "conduit_bin",
post("/_matrix/client/r0/logout/all", data = "<body>")
)]
pub fn logout_all_route(
pub async fn logout_all_route(
db: State<'_, Database>,
body: Ruma<logout_all::Request>,
) -> ConduitResult<logout_all::Response> {
@ -150,5 +154,7 @@ pub fn logout_all_route(
}
}
db.flush().await?;
Ok(logout_all::Response::new().into())
}

View File

@ -37,8 +37,7 @@ pub async fn send_state_event_for_key_route(
)
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Invalid JSON body."))?;
Ok(send_state_event_for_key::Response::new(
send_state_event_for_key_helper(
let event_id = send_state_event_for_key_helper(
&db,
sender_user,
&body.content,
@ -46,9 +45,11 @@ pub async fn send_state_event_for_key_route(
&body.room_id,
Some(body.state_key.to_owned()),
)
.await?,
)
.into())
.await?;
db.flush().await?;
Ok(send_state_event_for_key::Response { event_id }.into())
}
#[cfg_attr(
@ -75,8 +76,7 @@ pub async fn send_state_event_for_empty_key_route(
)
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Invalid JSON body."))?;
Ok(send_state_event_for_empty_key::Response::new(
send_state_event_for_key_helper(
let event_id = send_state_event_for_key_helper(
&db,
sender_user
.as_ref()
@ -86,16 +86,18 @@ pub async fn send_state_event_for_empty_key_route(
&body.room_id,
Some("".into()),
)
.await?,
)
.into())
.await?;
db.flush().await?;
Ok(send_state_event_for_empty_key::Response { event_id }.into())
}
#[cfg_attr(
feature = "conduit_bin",
get("/_matrix/client/r0/rooms/<_>/state", data = "<body>")
)]
pub fn get_state_events_route(
pub async fn get_state_events_route(
db: State<'_, Database>,
body: Ruma<get_state_events::Request>,
) -> ConduitResult<get_state_events::Response> {
@ -140,7 +142,7 @@ pub fn get_state_events_route(
feature = "conduit_bin",
get("/_matrix/client/r0/rooms/<_>/state/<_>/<_>", data = "<body>")
)]
pub fn get_state_events_for_key_route(
pub async fn get_state_events_for_key_route(
db: State<'_, Database>,
body: Ruma<get_state_events_for_key::Request>,
) -> ConduitResult<get_state_events_for_key::Response> {
@ -189,7 +191,7 @@ pub fn get_state_events_for_key_route(
feature = "conduit_bin",
get("/_matrix/client/r0/rooms/<_>/state/<_>", data = "<body>")
)]
pub fn get_state_events_for_empty_key_route(
pub async fn get_state_events_for_empty_key_route(
db: State<'_, Database>,
body: Ruma<get_state_events_for_empty_key::Request>,
) -> ConduitResult<get_state_events_for_empty_key::Response> {

View File

@ -13,7 +13,7 @@ use rocket::{delete, get, put};
feature = "conduit_bin",
put("/_matrix/client/r0/user/<_>/rooms/<_>/tags/<_>", data = "<body>")
)]
pub fn update_tag_route(
pub async fn update_tag_route(
db: State<'_, Database>,
body: Ruma<create_tag::Request<'_>>,
) -> ConduitResult<create_tag::Response> {
@ -40,6 +40,8 @@ pub fn update_tag_route(
&db.globals,
)?;
db.flush().await?;
Ok(create_tag::Response.into())
}
@ -47,7 +49,7 @@ pub fn update_tag_route(
feature = "conduit_bin",
delete("/_matrix/client/r0/user/<_>/rooms/<_>/tags/<_>", data = "<body>")
)]
pub fn delete_tag_route(
pub async fn delete_tag_route(
db: State<'_, Database>,
body: Ruma<delete_tag::Request<'_>>,
) -> ConduitResult<delete_tag::Response> {
@ -71,6 +73,8 @@ pub fn delete_tag_route(
&db.globals,
)?;
db.flush().await?;
Ok(delete_tag::Response.into())
}
@ -78,7 +82,7 @@ pub fn delete_tag_route(
feature = "conduit_bin",
get("/_matrix/client/r0/user/<_>/rooms/<_>/tags", data = "<body>")
)]
pub fn get_tags_route(
pub async fn get_tags_route(
db: State<'_, Database>,
body: Ruma<get_tags::Request<'_>>,
) -> ConduitResult<get_tags::Response> {

View File

@ -10,7 +10,7 @@ use std::collections::BTreeMap;
feature = "conduit_bin",
get("/_matrix/client/r0/thirdparty/protocols")
)]
pub fn get_protocols_route() -> ConduitResult<get_protocols::Response> {
pub async fn get_protocols_route() -> ConduitResult<get_protocols::Response> {
warn!("TODO: get_protocols_route");
Ok(get_protocols::Response {
protocols: BTreeMap::new(),

View File

@ -12,7 +12,7 @@ use rocket::put;
feature = "conduit_bin",
put("/_matrix/client/r0/sendToDevice/<_>/<_>", data = "<body>")
)]
pub fn send_event_to_device_route(
pub async fn send_event_to_device_route(
db: State<'_, Database>,
body: Ruma<send_event_to_device::Request<'_>>,
) -> ConduitResult<send_event_to_device::Response> {
@ -66,5 +66,7 @@ pub fn send_event_to_device_route(
db.transaction_ids
.add_txnid(sender_user, sender_device, &body.txn_id, &[])?;
db.flush().await?;
Ok(send_event_to_device::Response.into())
}

View File

@ -15,7 +15,7 @@ use rocket::get;
/// Note: Unstable features are used while developing new features. Clients should avoid using
/// unstable features in their stable releases
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/versions"))]
pub fn get_supported_versions_route() -> ConduitResult<get_supported_versions::Response> {
pub async fn get_supported_versions_route() -> ConduitResult<get_supported_versions::Response> {
let mut resp =
get_supported_versions::Response::new(vec!["r0.5.0".to_owned(), "r0.6.0".to_owned()]);

View File

@ -9,7 +9,7 @@ use rocket::post;
feature = "conduit_bin",
post("/_matrix/client/r0/user_directory/search", data = "<body>")
)]
pub fn search_users_route(
pub async fn search_users_route(
db: State<'_, Database>,
body: Ruma<search_users::Request<'_>>,
) -> ConduitResult<search_users::Response> {

View File

@ -5,7 +5,7 @@ use ruma::api::client::{error::ErrorKind, r0::message::send_message_event};
use rocket::get;
#[cfg_attr(feature = "conduit_bin", get("/_matrix/client/r0/voip/turnServer"))]
pub fn turn_server_route() -> ConduitResult<send_message_event::Response> {
pub async fn turn_server_route() -> ConduitResult<send_message_event::Response> {
Err(Error::BadRequest(
ErrorKind::NotFound,
"There is no turn server yet.",

View File

@ -227,4 +227,9 @@ impl Database {
// Wait until one of them finds something
futures.next().await;
}
pub async fn flush(&self) -> Result<()> {
self._db.flush_async().await?;
Ok(())
}
}