fix: use device_id when registering
TIL body.device_id != (*body).device_id, which is pretty bad, so I renamed body.device_id to body.sender_device
This commit is contained in:
parent
fccd3fdb88
commit
f0a21b6165
23 changed files with 325 additions and 307 deletions
|
@ -489,8 +489,8 @@ pub fn change_password_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<change_password::Request<'_>>,
|
body: Ruma<change_password::Request<'_>>,
|
||||||
) -> ConduitResult<change_password::Response> {
|
) -> ConduitResult<change_password::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut uiaainfo = UiaaInfo {
|
let mut uiaainfo = UiaaInfo {
|
||||||
flows: vec![AuthFlow {
|
flows: vec![AuthFlow {
|
||||||
|
@ -504,8 +504,8 @@ pub fn change_password_route(
|
||||||
|
|
||||||
if let Some(auth) = &body.auth {
|
if let Some(auth) = &body.auth {
|
||||||
let (worked, uiaainfo) = db.uiaa.try_auth(
|
let (worked, uiaainfo) = db.uiaa.try_auth(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
device_id,
|
sender_device,
|
||||||
auth,
|
auth,
|
||||||
&uiaainfo,
|
&uiaainfo,
|
||||||
&db.users,
|
&db.users,
|
||||||
|
@ -517,22 +517,22 @@ pub fn change_password_route(
|
||||||
// Success!
|
// Success!
|
||||||
} else {
|
} else {
|
||||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||||
db.uiaa.create(&sender_id, &device_id, &uiaainfo)?;
|
db.uiaa.create(&sender_user, &sender_device, &uiaainfo)?;
|
||||||
return Err(Error::Uiaa(uiaainfo));
|
return Err(Error::Uiaa(uiaainfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
db.users.set_password(&sender_id, &body.new_password)?;
|
db.users.set_password(&sender_user, &body.new_password)?;
|
||||||
|
|
||||||
// TODO: Read logout_devices field when it's available and respect that, currently not supported in Ruma
|
// TODO: Read logout_devices field when it's available and respect that, currently not supported in Ruma
|
||||||
// See: https://github.com/ruma/ruma/issues/107
|
// See: https://github.com/ruma/ruma/issues/107
|
||||||
// Logout all devices except the current one
|
// Logout all devices except the current one
|
||||||
for id in db
|
for id in db
|
||||||
.users
|
.users
|
||||||
.all_device_ids(&sender_id)
|
.all_device_ids(&sender_user)
|
||||||
.filter_map(|id| id.ok())
|
.filter_map(|id| id.ok())
|
||||||
.filter(|id| id != device_id)
|
.filter(|id| id != sender_device)
|
||||||
{
|
{
|
||||||
db.users.remove_device(&sender_id, &id)?;
|
db.users.remove_device(&sender_user, &id)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(change_password::Response.into())
|
Ok(change_password::Response.into())
|
||||||
|
@ -548,9 +548,9 @@ pub fn change_password_route(
|
||||||
get("/_matrix/client/r0/account/whoami", data = "<body>")
|
get("/_matrix/client/r0/account/whoami", data = "<body>")
|
||||||
)]
|
)]
|
||||||
pub fn whoami_route(body: Ruma<whoami::Request>) -> ConduitResult<whoami::Response> {
|
pub fn whoami_route(body: Ruma<whoami::Request>) -> ConduitResult<whoami::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
Ok(whoami::Response {
|
Ok(whoami::Response {
|
||||||
user_id: sender_id.clone(),
|
user_id: sender_user.clone(),
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
@ -571,8 +571,8 @@ pub async fn deactivate_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<deactivate::Request<'_>>,
|
body: Ruma<deactivate::Request<'_>>,
|
||||||
) -> ConduitResult<deactivate::Response> {
|
) -> ConduitResult<deactivate::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut uiaainfo = UiaaInfo {
|
let mut uiaainfo = UiaaInfo {
|
||||||
flows: vec![AuthFlow {
|
flows: vec![AuthFlow {
|
||||||
|
@ -586,8 +586,8 @@ pub async fn deactivate_route(
|
||||||
|
|
||||||
if let Some(auth) = &body.auth {
|
if let Some(auth) = &body.auth {
|
||||||
let (worked, uiaainfo) = db.uiaa.try_auth(
|
let (worked, uiaainfo) = db.uiaa.try_auth(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&device_id,
|
&sender_device,
|
||||||
auth,
|
auth,
|
||||||
&uiaainfo,
|
&uiaainfo,
|
||||||
&db.users,
|
&db.users,
|
||||||
|
@ -599,15 +599,15 @@ pub async fn deactivate_route(
|
||||||
// Success!
|
// Success!
|
||||||
} else {
|
} else {
|
||||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||||
db.uiaa.create(&sender_id, &device_id, &uiaainfo)?;
|
db.uiaa.create(&sender_user, &sender_device, &uiaainfo)?;
|
||||||
return Err(Error::Uiaa(uiaainfo));
|
return Err(Error::Uiaa(uiaainfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leave all joined rooms and reject all invitations
|
// Leave all joined rooms and reject all invitations
|
||||||
for room_id in db
|
for room_id in db
|
||||||
.rooms
|
.rooms
|
||||||
.rooms_joined(&sender_id)
|
.rooms_joined(&sender_user)
|
||||||
.chain(db.rooms.rooms_invited(&sender_id))
|
.chain(db.rooms.rooms_invited(&sender_user))
|
||||||
{
|
{
|
||||||
let room_id = room_id?;
|
let room_id = room_id?;
|
||||||
let event = member::MemberEventContent {
|
let event = member::MemberEventContent {
|
||||||
|
@ -623,10 +623,10 @@ pub async fn deactivate_route(
|
||||||
event_type: EventType::RoomMember,
|
event_type: EventType::RoomMember,
|
||||||
content: serde_json::to_value(event).expect("event is valid, we just created it"),
|
content: serde_json::to_value(event).expect("event is valid, we just created it"),
|
||||||
unsigned: None,
|
unsigned: None,
|
||||||
state_key: Some(sender_id.to_string()),
|
state_key: Some(sender_user.to_string()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -635,7 +635,7 @@ pub async fn deactivate_route(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove devices and mark account as deactivated
|
// Remove devices and mark account as deactivated
|
||||||
db.users.deactivate_account(&sender_id)?;
|
db.users.deactivate_account(&sender_user)?;
|
||||||
|
|
||||||
Ok(deactivate::Response {
|
Ok(deactivate::Response {
|
||||||
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
|
id_server_unbind_result: ThirdPartyIdRemovalStatus::NoSupport,
|
||||||
|
|
|
@ -21,10 +21,10 @@ pub fn create_backup_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<create_backup::Request>,
|
body: Ruma<create_backup::Request>,
|
||||||
) -> ConduitResult<create_backup::Response> {
|
) -> ConduitResult<create_backup::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let version = db
|
let version = db
|
||||||
.key_backups
|
.key_backups
|
||||||
.create_backup(&sender_id, &body.algorithm, &db.globals)?;
|
.create_backup(&sender_user, &body.algorithm, &db.globals)?;
|
||||||
|
|
||||||
Ok(create_backup::Response { version }.into())
|
Ok(create_backup::Response { version }.into())
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,9 @@ pub fn update_backup_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<update_backup::Request<'_>>,
|
body: Ruma<update_backup::Request<'_>>,
|
||||||
) -> ConduitResult<update_backup::Response> {
|
) -> ConduitResult<update_backup::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
db.key_backups
|
db.key_backups
|
||||||
.update_backup(&sender_id, &body.version, &body.algorithm, &db.globals)?;
|
.update_backup(&sender_user, &body.version, &body.algorithm, &db.globals)?;
|
||||||
|
|
||||||
Ok(update_backup::Response.into())
|
Ok(update_backup::Response.into())
|
||||||
}
|
}
|
||||||
|
@ -52,11 +52,11 @@ pub fn get_latest_backup_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_latest_backup::Request>,
|
body: Ruma<get_latest_backup::Request>,
|
||||||
) -> ConduitResult<get_latest_backup::Response> {
|
) -> ConduitResult<get_latest_backup::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let (version, algorithm) =
|
let (version, algorithm) =
|
||||||
db.key_backups
|
db.key_backups
|
||||||
.get_latest_backup(&sender_id)?
|
.get_latest_backup(&sender_user)?
|
||||||
.ok_or(Error::BadRequest(
|
.ok_or(Error::BadRequest(
|
||||||
ErrorKind::NotFound,
|
ErrorKind::NotFound,
|
||||||
"Key backup does not exist.",
|
"Key backup does not exist.",
|
||||||
|
@ -64,8 +64,8 @@ pub fn get_latest_backup_route(
|
||||||
|
|
||||||
Ok(get_latest_backup::Response {
|
Ok(get_latest_backup::Response {
|
||||||
algorithm,
|
algorithm,
|
||||||
count: (db.key_backups.count_keys(sender_id, &version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_id, &version)?,
|
etag: db.key_backups.get_etag(sender_user, &version)?,
|
||||||
version,
|
version,
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
|
@ -79,10 +79,10 @@ pub fn get_backup_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_backup::Request<'_>>,
|
body: Ruma<get_backup::Request<'_>>,
|
||||||
) -> ConduitResult<get_backup::Response> {
|
) -> ConduitResult<get_backup::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let algorithm = db
|
let algorithm = db
|
||||||
.key_backups
|
.key_backups
|
||||||
.get_backup(&sender_id, &body.version)?
|
.get_backup(&sender_user, &body.version)?
|
||||||
.ok_or(Error::BadRequest(
|
.ok_or(Error::BadRequest(
|
||||||
ErrorKind::NotFound,
|
ErrorKind::NotFound,
|
||||||
"Key backup does not exist.",
|
"Key backup does not exist.",
|
||||||
|
@ -90,8 +90,8 @@ pub fn get_backup_route(
|
||||||
|
|
||||||
Ok(get_backup::Response {
|
Ok(get_backup::Response {
|
||||||
algorithm,
|
algorithm,
|
||||||
count: (db.key_backups.count_keys(sender_id, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_id, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
version: body.version.to_owned(),
|
version: body.version.to_owned(),
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
|
@ -105,9 +105,9 @@ pub fn delete_backup_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<delete_backup::Request>,
|
body: Ruma<delete_backup::Request>,
|
||||||
) -> ConduitResult<delete_backup::Response> {
|
) -> ConduitResult<delete_backup::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
db.key_backups.delete_backup(&sender_id, &body.version)?;
|
db.key_backups.delete_backup(&sender_user, &body.version)?;
|
||||||
|
|
||||||
Ok(delete_backup::Response.into())
|
Ok(delete_backup::Response.into())
|
||||||
}
|
}
|
||||||
|
@ -121,12 +121,12 @@ pub fn add_backup_keys_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<add_backup_keys::Request<'_>>,
|
body: Ruma<add_backup_keys::Request<'_>>,
|
||||||
) -> ConduitResult<add_backup_keys::Response> {
|
) -> ConduitResult<add_backup_keys::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
for (room_id, room) in &body.rooms {
|
for (room_id, room) in &body.rooms {
|
||||||
for (session_id, key_data) in &room.sessions {
|
for (session_id, key_data) in &room.sessions {
|
||||||
db.key_backups.add_key(
|
db.key_backups.add_key(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&body.version,
|
&body.version,
|
||||||
&room_id,
|
&room_id,
|
||||||
&session_id,
|
&session_id,
|
||||||
|
@ -137,8 +137,8 @@ pub fn add_backup_keys_route(
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(add_backup_keys::Response {
|
Ok(add_backup_keys::Response {
|
||||||
count: (db.key_backups.count_keys(sender_id, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_id, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
@ -152,11 +152,11 @@ pub fn add_backup_key_sessions_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<add_backup_key_sessions::Request>,
|
body: Ruma<add_backup_key_sessions::Request>,
|
||||||
) -> ConduitResult<add_backup_key_sessions::Response> {
|
) -> ConduitResult<add_backup_key_sessions::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
for (session_id, key_data) in &body.sessions {
|
for (session_id, key_data) in &body.sessions {
|
||||||
db.key_backups.add_key(
|
db.key_backups.add_key(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&body.version,
|
&body.version,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&session_id,
|
&session_id,
|
||||||
|
@ -166,8 +166,8 @@ pub fn add_backup_key_sessions_route(
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(add_backup_key_sessions::Response {
|
Ok(add_backup_key_sessions::Response {
|
||||||
count: (db.key_backups.count_keys(sender_id, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_id, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
@ -181,10 +181,10 @@ pub fn add_backup_key_session_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<add_backup_key_session::Request>,
|
body: Ruma<add_backup_key_session::Request>,
|
||||||
) -> ConduitResult<add_backup_key_session::Response> {
|
) -> ConduitResult<add_backup_key_session::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
db.key_backups.add_key(
|
db.key_backups.add_key(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&body.version,
|
&body.version,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&body.session_id,
|
&body.session_id,
|
||||||
|
@ -193,8 +193,8 @@ pub fn add_backup_key_session_route(
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(add_backup_key_session::Response {
|
Ok(add_backup_key_session::Response {
|
||||||
count: (db.key_backups.count_keys(sender_id, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_id, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
@ -207,9 +207,9 @@ pub fn get_backup_keys_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_backup_keys::Request<'_>>,
|
body: Ruma<get_backup_keys::Request<'_>>,
|
||||||
) -> ConduitResult<get_backup_keys::Response> {
|
) -> ConduitResult<get_backup_keys::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let rooms = db.key_backups.get_all(&sender_id, &body.version)?;
|
let rooms = db.key_backups.get_all(&sender_user, &body.version)?;
|
||||||
|
|
||||||
Ok(get_backup_keys::Response { rooms }.into())
|
Ok(get_backup_keys::Response { rooms }.into())
|
||||||
}
|
}
|
||||||
|
@ -222,11 +222,11 @@ pub fn get_backup_key_sessions_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_backup_key_sessions::Request>,
|
body: Ruma<get_backup_key_sessions::Request>,
|
||||||
) -> ConduitResult<get_backup_key_sessions::Response> {
|
) -> ConduitResult<get_backup_key_sessions::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let sessions = db
|
let sessions = db
|
||||||
.key_backups
|
.key_backups
|
||||||
.get_room(&sender_id, &body.version, &body.room_id);
|
.get_room(&sender_user, &body.version, &body.room_id);
|
||||||
|
|
||||||
Ok(get_backup_key_sessions::Response { sessions }.into())
|
Ok(get_backup_key_sessions::Response { sessions }.into())
|
||||||
}
|
}
|
||||||
|
@ -239,11 +239,11 @@ pub fn get_backup_key_session_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_backup_key_session::Request>,
|
body: Ruma<get_backup_key_session::Request>,
|
||||||
) -> ConduitResult<get_backup_key_session::Response> {
|
) -> ConduitResult<get_backup_key_session::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let key_data =
|
let key_data =
|
||||||
db.key_backups
|
db.key_backups
|
||||||
.get_session(&sender_id, &body.version, &body.room_id, &body.session_id)?;
|
.get_session(&sender_user, &body.version, &body.room_id, &body.session_id)?;
|
||||||
|
|
||||||
Ok(get_backup_key_session::Response { key_data }.into())
|
Ok(get_backup_key_session::Response { key_data }.into())
|
||||||
}
|
}
|
||||||
|
@ -256,13 +256,14 @@ pub fn delete_backup_keys_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<delete_backup_keys::Request>,
|
body: Ruma<delete_backup_keys::Request>,
|
||||||
) -> ConduitResult<delete_backup_keys::Response> {
|
) -> ConduitResult<delete_backup_keys::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
db.key_backups.delete_all_keys(&sender_id, &body.version)?;
|
db.key_backups
|
||||||
|
.delete_all_keys(&sender_user, &body.version)?;
|
||||||
|
|
||||||
Ok(delete_backup_keys::Response {
|
Ok(delete_backup_keys::Response {
|
||||||
count: (db.key_backups.count_keys(sender_id, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_id, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
@ -275,14 +276,14 @@ pub fn delete_backup_key_sessions_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<delete_backup_key_sessions::Request>,
|
body: Ruma<delete_backup_key_sessions::Request>,
|
||||||
) -> ConduitResult<delete_backup_key_sessions::Response> {
|
) -> ConduitResult<delete_backup_key_sessions::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
db.key_backups
|
db.key_backups
|
||||||
.delete_room_keys(&sender_id, &body.version, &body.room_id)?;
|
.delete_room_keys(&sender_user, &body.version, &body.room_id)?;
|
||||||
|
|
||||||
Ok(delete_backup_key_sessions::Response {
|
Ok(delete_backup_key_sessions::Response {
|
||||||
count: (db.key_backups.count_keys(sender_id, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_id, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
@ -295,14 +296,14 @@ pub fn delete_backup_key_session_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<delete_backup_key_session::Request>,
|
body: Ruma<delete_backup_key_session::Request>,
|
||||||
) -> ConduitResult<delete_backup_key_session::Response> {
|
) -> ConduitResult<delete_backup_key_session::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
db.key_backups
|
db.key_backups
|
||||||
.delete_room_key(&sender_id, &body.version, &body.room_id, &body.session_id)?;
|
.delete_room_key(&sender_user, &body.version, &body.room_id, &body.session_id)?;
|
||||||
|
|
||||||
Ok(delete_backup_key_session::Response {
|
Ok(delete_backup_key_session::Response {
|
||||||
count: (db.key_backups.count_keys(sender_id, &body.version)? as u32).into(),
|
count: (db.key_backups.count_keys(sender_user, &body.version)? as u32).into(),
|
||||||
etag: db.key_backups.get_etag(sender_id, &body.version)?,
|
etag: db.key_backups.get_etag(sender_user, &body.version)?,
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ 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<'_>>,
|
||||||
) -> ConduitResult<set_global_account_data::Response> {
|
) -> ConduitResult<set_global_account_data::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let content = serde_json::from_str::<serde_json::Value>(body.data.get())
|
let content = serde_json::from_str::<serde_json::Value>(body.data.get())
|
||||||
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Data is invalid."))?;
|
.map_err(|_| Error::BadRequest(ErrorKind::BadJson, "Data is invalid."))?;
|
||||||
|
@ -29,7 +29,7 @@ pub fn set_global_account_data_route(
|
||||||
|
|
||||||
db.account_data.update(
|
db.account_data.update(
|
||||||
None,
|
None,
|
||||||
sender_id,
|
sender_user,
|
||||||
event_type.clone().into(),
|
event_type.clone().into(),
|
||||||
&BasicEvent {
|
&BasicEvent {
|
||||||
content: CustomEventContent {
|
content: CustomEventContent {
|
||||||
|
@ -51,11 +51,11 @@ 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<'_>>,
|
||||||
) -> ConduitResult<get_global_account_data::Response> {
|
) -> ConduitResult<get_global_account_data::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let data = db
|
let data = db
|
||||||
.account_data
|
.account_data
|
||||||
.get::<Raw<ruma::events::AnyBasicEvent>>(None, sender_id, body.event_type.clone().into())?
|
.get::<Raw<ruma::events::AnyBasicEvent>>(None, sender_user, body.event_type.clone().into())?
|
||||||
.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())
|
Ok(get_global_account_data::Response { account_data: data }.into())
|
||||||
|
|
|
@ -14,9 +14,9 @@ pub fn get_context_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_context::Request<'_>>,
|
body: Ruma<get_context::Request<'_>>,
|
||||||
) -> ConduitResult<get_context::Response> {
|
) -> ConduitResult<get_context::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !db.rooms.is_joined(sender_id, &body.room_id)? {
|
if !db.rooms.is_joined(sender_user, &body.room_id)? {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::Forbidden,
|
ErrorKind::Forbidden,
|
||||||
"You don't have permission to view this room.",
|
"You don't have permission to view this room.",
|
||||||
|
@ -39,7 +39,7 @@ pub fn get_context_route(
|
||||||
|
|
||||||
let events_before = db
|
let events_before = db
|
||||||
.rooms
|
.rooms
|
||||||
.pdus_until(&sender_id, &body.room_id, base_token)
|
.pdus_until(&sender_user, &body.room_id, base_token)
|
||||||
.take(
|
.take(
|
||||||
u32::try_from(body.limit).map_err(|_| {
|
u32::try_from(body.limit).map_err(|_| {
|
||||||
Error::BadRequest(ErrorKind::InvalidParam, "Limit value is invalid.")
|
Error::BadRequest(ErrorKind::InvalidParam, "Limit value is invalid.")
|
||||||
|
@ -61,7 +61,7 @@ pub fn get_context_route(
|
||||||
|
|
||||||
let events_after = db
|
let events_after = db
|
||||||
.rooms
|
.rooms
|
||||||
.pdus_after(&sender_id, &body.room_id, base_token)
|
.pdus_after(&sender_user, &body.room_id, base_token)
|
||||||
.take(
|
.take(
|
||||||
u32::try_from(body.limit).map_err(|_| {
|
u32::try_from(body.limit).map_err(|_| {
|
||||||
Error::BadRequest(ErrorKind::InvalidParam, "Limit value is invalid.")
|
Error::BadRequest(ErrorKind::InvalidParam, "Limit value is invalid.")
|
||||||
|
|
|
@ -20,11 +20,11 @@ pub fn get_devices_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_devices::Request>,
|
body: Ruma<get_devices::Request>,
|
||||||
) -> ConduitResult<get_devices::Response> {
|
) -> ConduitResult<get_devices::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let devices = db
|
let devices = db
|
||||||
.users
|
.users
|
||||||
.all_devices_metadata(sender_id)
|
.all_devices_metadata(sender_user)
|
||||||
.filter_map(|r| r.ok()) // Filter out buggy devices
|
.filter_map(|r| r.ok()) // Filter out buggy devices
|
||||||
.collect::<Vec<device::Device>>();
|
.collect::<Vec<device::Device>>();
|
||||||
|
|
||||||
|
@ -33,18 +33,17 @@ pub fn get_devices_route(
|
||||||
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "conduit_bin",
|
feature = "conduit_bin",
|
||||||
get("/_matrix/client/r0/devices/<_device_id>", data = "<body>")
|
get("/_matrix/client/r0/devices/<_>", 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<'_>>,
|
||||||
_device_id: String,
|
|
||||||
) -> ConduitResult<get_device::Response> {
|
) -> ConduitResult<get_device::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let device = db
|
let device = db
|
||||||
.users
|
.users
|
||||||
.get_device_metadata(&sender_id, &body.body.device_id)?
|
.get_device_metadata(&sender_user, &body.body.device_id)?
|
||||||
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Device not found."))?;
|
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Device not found."))?;
|
||||||
|
|
||||||
Ok(get_device::Response { device }.into())
|
Ok(get_device::Response { device }.into())
|
||||||
|
@ -52,39 +51,37 @@ pub fn get_device_route(
|
||||||
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "conduit_bin",
|
feature = "conduit_bin",
|
||||||
put("/_matrix/client/r0/devices/<_device_id>", data = "<body>")
|
put("/_matrix/client/r0/devices/<_>", 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<'_>>,
|
||||||
_device_id: String,
|
|
||||||
) -> ConduitResult<update_device::Response> {
|
) -> ConduitResult<update_device::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut device = db
|
let mut device = db
|
||||||
.users
|
.users
|
||||||
.get_device_metadata(&sender_id, &body.body.device_id)?
|
.get_device_metadata(&sender_user, &body.device_id)?
|
||||||
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Device not found."))?;
|
.ok_or(Error::BadRequest(ErrorKind::NotFound, "Device not found."))?;
|
||||||
|
|
||||||
device.display_name = body.display_name.clone();
|
device.display_name = body.display_name.clone();
|
||||||
|
|
||||||
db.users
|
db.users
|
||||||
.update_device_metadata(&sender_id, &body.body.device_id, &device)?;
|
.update_device_metadata(&sender_user, &body.device_id, &device)?;
|
||||||
|
|
||||||
Ok(update_device::Response.into())
|
Ok(update_device::Response.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "conduit_bin",
|
feature = "conduit_bin",
|
||||||
delete("/_matrix/client/r0/devices/<_device_id>", data = "<body>")
|
delete("/_matrix/client/r0/devices/<_>", 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<'_>>,
|
||||||
_device_id: String,
|
|
||||||
) -> ConduitResult<delete_device::Response> {
|
) -> ConduitResult<delete_device::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
// UIAA
|
// UIAA
|
||||||
let mut uiaainfo = UiaaInfo {
|
let mut uiaainfo = UiaaInfo {
|
||||||
|
@ -99,8 +96,8 @@ pub fn delete_device_route(
|
||||||
|
|
||||||
if let Some(auth) = &body.auth {
|
if let Some(auth) = &body.auth {
|
||||||
let (worked, uiaainfo) = db.uiaa.try_auth(
|
let (worked, uiaainfo) = db.uiaa.try_auth(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&device_id,
|
&sender_device,
|
||||||
auth,
|
auth,
|
||||||
&uiaainfo,
|
&uiaainfo,
|
||||||
&db.users,
|
&db.users,
|
||||||
|
@ -112,11 +109,11 @@ pub fn delete_device_route(
|
||||||
// Success!
|
// Success!
|
||||||
} else {
|
} else {
|
||||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||||
db.uiaa.create(&sender_id, &device_id, &uiaainfo)?;
|
db.uiaa.create(&sender_user, &sender_device, &uiaainfo)?;
|
||||||
return Err(Error::Uiaa(uiaainfo));
|
return Err(Error::Uiaa(uiaainfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
db.users.remove_device(&sender_id, &body.body.device_id)?;
|
db.users.remove_device(&sender_user, &body.device_id)?;
|
||||||
|
|
||||||
Ok(delete_device::Response.into())
|
Ok(delete_device::Response.into())
|
||||||
}
|
}
|
||||||
|
@ -129,8 +126,8 @@ pub fn delete_devices_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<delete_devices::Request<'_>>,
|
body: Ruma<delete_devices::Request<'_>>,
|
||||||
) -> ConduitResult<delete_devices::Response> {
|
) -> ConduitResult<delete_devices::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
// UIAA
|
// UIAA
|
||||||
let mut uiaainfo = UiaaInfo {
|
let mut uiaainfo = UiaaInfo {
|
||||||
|
@ -145,8 +142,8 @@ pub fn delete_devices_route(
|
||||||
|
|
||||||
if let Some(auth) = &body.auth {
|
if let Some(auth) = &body.auth {
|
||||||
let (worked, uiaainfo) = db.uiaa.try_auth(
|
let (worked, uiaainfo) = db.uiaa.try_auth(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&device_id,
|
&sender_device,
|
||||||
auth,
|
auth,
|
||||||
&uiaainfo,
|
&uiaainfo,
|
||||||
&db.users,
|
&db.users,
|
||||||
|
@ -158,12 +155,12 @@ pub fn delete_devices_route(
|
||||||
// Success!
|
// Success!
|
||||||
} else {
|
} else {
|
||||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||||
db.uiaa.create(&sender_id, &device_id, &uiaainfo)?;
|
db.uiaa.create(&sender_user, &sender_device, &uiaainfo)?;
|
||||||
return Err(Error::Uiaa(uiaainfo));
|
return Err(Error::Uiaa(uiaainfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
for device_id in &body.devices {
|
for device_id in &body.devices {
|
||||||
db.users.remove_device(&sender_id, &device_id)?
|
db.users.remove_device(&sender_user, &device_id)?
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(delete_devices::Response.into())
|
Ok(delete_devices::Response.into())
|
||||||
|
|
|
@ -26,26 +26,40 @@ pub fn upload_keys_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<upload_keys::Request<'_>>,
|
body: Ruma<upload_keys::Request<'_>>,
|
||||||
) -> ConduitResult<upload_keys::Response> {
|
) -> ConduitResult<upload_keys::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if let Some(one_time_keys) = &body.one_time_keys {
|
if let Some(one_time_keys) = &body.one_time_keys {
|
||||||
for (key_key, key_value) in one_time_keys {
|
for (key_key, key_value) in one_time_keys {
|
||||||
db.users
|
db.users.add_one_time_key(
|
||||||
.add_one_time_key(sender_id, device_id, key_key, key_value, &db.globals)?;
|
sender_user,
|
||||||
|
sender_device,
|
||||||
|
key_key,
|
||||||
|
key_value,
|
||||||
|
&db.globals,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(device_keys) = &body.device_keys {
|
if let Some(device_keys) = &body.device_keys {
|
||||||
// This check is needed to assure that signatures are kept
|
// This check is needed to assure that signatures are kept
|
||||||
if db.users.get_device_keys(sender_id, device_id)?.is_none() {
|
if db
|
||||||
db.users
|
.users
|
||||||
.add_device_keys(sender_id, device_id, device_keys, &db.rooms, &db.globals)?;
|
.get_device_keys(sender_user, sender_device)?
|
||||||
|
.is_none()
|
||||||
|
{
|
||||||
|
db.users.add_device_keys(
|
||||||
|
sender_user,
|
||||||
|
sender_device,
|
||||||
|
device_keys,
|
||||||
|
&db.rooms,
|
||||||
|
&db.globals,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(upload_keys::Response {
|
Ok(upload_keys::Response {
|
||||||
one_time_key_counts: db.users.count_one_time_keys(sender_id, device_id)?,
|
one_time_key_counts: db.users.count_one_time_keys(sender_user, sender_device)?,
|
||||||
}
|
}
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
@ -58,7 +72,7 @@ pub fn get_keys_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_keys::Request<'_>>,
|
body: Ruma<get_keys::Request<'_>>,
|
||||||
) -> ConduitResult<get_keys::Response> {
|
) -> ConduitResult<get_keys::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut master_keys = BTreeMap::new();
|
let mut master_keys = BTreeMap::new();
|
||||||
let mut self_signing_keys = BTreeMap::new();
|
let mut self_signing_keys = BTreeMap::new();
|
||||||
|
@ -107,14 +121,14 @@ pub fn get_keys_route(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(master_key) = db.users.get_master_key(user_id, sender_id)? {
|
if let Some(master_key) = db.users.get_master_key(user_id, sender_user)? {
|
||||||
master_keys.insert(user_id.clone(), master_key);
|
master_keys.insert(user_id.clone(), master_key);
|
||||||
}
|
}
|
||||||
if let Some(self_signing_key) = db.users.get_self_signing_key(user_id, sender_id)? {
|
if let Some(self_signing_key) = db.users.get_self_signing_key(user_id, sender_user)? {
|
||||||
self_signing_keys.insert(user_id.clone(), self_signing_key);
|
self_signing_keys.insert(user_id.clone(), self_signing_key);
|
||||||
}
|
}
|
||||||
if user_id == sender_id {
|
if user_id == sender_user {
|
||||||
if let Some(user_signing_key) = db.users.get_user_signing_key(sender_id)? {
|
if let Some(user_signing_key) = db.users.get_user_signing_key(sender_user)? {
|
||||||
user_signing_keys.insert(user_id.clone(), user_signing_key);
|
user_signing_keys.insert(user_id.clone(), user_signing_key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,8 +183,8 @@ pub fn upload_signing_keys_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<upload_signing_keys::Request<'_>>,
|
body: Ruma<upload_signing_keys::Request<'_>>,
|
||||||
) -> ConduitResult<upload_signing_keys::Response> {
|
) -> ConduitResult<upload_signing_keys::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
// UIAA
|
// UIAA
|
||||||
let mut uiaainfo = UiaaInfo {
|
let mut uiaainfo = UiaaInfo {
|
||||||
|
@ -185,8 +199,8 @@ pub fn upload_signing_keys_route(
|
||||||
|
|
||||||
if let Some(auth) = &body.auth {
|
if let Some(auth) = &body.auth {
|
||||||
let (worked, uiaainfo) = db.uiaa.try_auth(
|
let (worked, uiaainfo) = db.uiaa.try_auth(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&device_id,
|
&sender_device,
|
||||||
auth,
|
auth,
|
||||||
&uiaainfo,
|
&uiaainfo,
|
||||||
&db.users,
|
&db.users,
|
||||||
|
@ -198,13 +212,13 @@ pub fn upload_signing_keys_route(
|
||||||
// Success!
|
// Success!
|
||||||
} else {
|
} else {
|
||||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||||
db.uiaa.create(&sender_id, &device_id, &uiaainfo)?;
|
db.uiaa.create(&sender_user, &sender_device, &uiaainfo)?;
|
||||||
return Err(Error::Uiaa(uiaainfo));
|
return Err(Error::Uiaa(uiaainfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(master_key) = &body.master_key {
|
if let Some(master_key) = &body.master_key {
|
||||||
db.users.add_cross_signing_keys(
|
db.users.add_cross_signing_keys(
|
||||||
sender_id,
|
sender_user,
|
||||||
&master_key,
|
&master_key,
|
||||||
&body.self_signing_key,
|
&body.self_signing_key,
|
||||||
&body.user_signing_key,
|
&body.user_signing_key,
|
||||||
|
@ -224,7 +238,7 @@ pub fn upload_signatures_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<upload_signatures::Request>,
|
body: Ruma<upload_signatures::Request>,
|
||||||
) -> ConduitResult<upload_signatures::Response> {
|
) -> ConduitResult<upload_signatures::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
for (user_id, signed_keys) in &body.signed_keys {
|
for (user_id, signed_keys) in &body.signed_keys {
|
||||||
for (key_id, signed_key) in signed_keys {
|
for (key_id, signed_key) in signed_keys {
|
||||||
|
@ -234,7 +248,7 @@ pub fn upload_signatures_route(
|
||||||
ErrorKind::InvalidParam,
|
ErrorKind::InvalidParam,
|
||||||
"Missing signatures field.",
|
"Missing signatures field.",
|
||||||
))?
|
))?
|
||||||
.get(sender_id.to_string())
|
.get(sender_user.to_string())
|
||||||
.ok_or(Error::BadRequest(
|
.ok_or(Error::BadRequest(
|
||||||
ErrorKind::InvalidParam,
|
ErrorKind::InvalidParam,
|
||||||
"Invalid user in signatures field.",
|
"Invalid user in signatures field.",
|
||||||
|
@ -263,7 +277,7 @@ pub fn upload_signatures_route(
|
||||||
&user_id,
|
&user_id,
|
||||||
&key_id,
|
&key_id,
|
||||||
signature,
|
signature,
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&db.rooms,
|
&db.rooms,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
)?;
|
)?;
|
||||||
|
@ -282,14 +296,14 @@ pub fn get_key_changes_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_key_changes::Request<'_>>,
|
body: Ruma<get_key_changes::Request<'_>>,
|
||||||
) -> ConduitResult<get_key_changes::Response> {
|
) -> ConduitResult<get_key_changes::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut device_list_updates = HashSet::new();
|
let mut device_list_updates = HashSet::new();
|
||||||
|
|
||||||
device_list_updates.extend(
|
device_list_updates.extend(
|
||||||
db.users
|
db.users
|
||||||
.keys_changed(
|
.keys_changed(
|
||||||
&sender_id.to_string(),
|
&sender_user.to_string(),
|
||||||
body.from
|
body.from
|
||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from`."))?,
|
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from`."))?,
|
||||||
|
@ -302,7 +316,7 @@ pub fn get_key_changes_route(
|
||||||
.filter_map(|r| r.ok()),
|
.filter_map(|r| r.ok()),
|
||||||
);
|
);
|
||||||
|
|
||||||
for room_id in db.rooms.rooms_joined(sender_id).filter_map(|r| r.ok()) {
|
for room_id in db.rooms.rooms_joined(sender_user).filter_map(|r| r.ok()) {
|
||||||
device_list_updates.extend(
|
device_list_updates.extend(
|
||||||
db.users
|
db.users
|
||||||
.keys_changed(
|
.keys_changed(
|
||||||
|
|
|
@ -40,7 +40,7 @@ pub async fn join_room_by_id_route(
|
||||||
) -> ConduitResult<join_room_by_id::Response> {
|
) -> ConduitResult<join_room_by_id::Response> {
|
||||||
join_room_by_id_helper(
|
join_room_by_id_helper(
|
||||||
&db,
|
&db,
|
||||||
body.sender_id.as_ref(),
|
body.sender_user.as_ref(),
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&[body.room_id.server_name().to_owned()],
|
&[body.room_id.server_name().to_owned()],
|
||||||
body.third_party_signed.as_ref(),
|
body.third_party_signed.as_ref(),
|
||||||
|
@ -68,7 +68,7 @@ pub async fn join_room_by_id_or_alias_route(
|
||||||
Ok(join_room_by_id_or_alias::Response {
|
Ok(join_room_by_id_or_alias::Response {
|
||||||
room_id: join_room_by_id_helper(
|
room_id: join_room_by_id_helper(
|
||||||
&db,
|
&db,
|
||||||
body.sender_id.as_ref(),
|
body.sender_user.as_ref(),
|
||||||
&room_id,
|
&room_id,
|
||||||
&servers,
|
&servers,
|
||||||
body.third_party_signed.as_ref(),
|
body.third_party_signed.as_ref(),
|
||||||
|
@ -88,14 +88,14 @@ pub async fn leave_room_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<leave_room::Request<'_>>,
|
body: Ruma<leave_room::Request<'_>>,
|
||||||
) -> ConduitResult<leave_room::Response> {
|
) -> ConduitResult<leave_room::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>(
|
let mut event = serde_json::from_value::<Raw<member::MemberEventContent>>(
|
||||||
db.rooms
|
db.rooms
|
||||||
.room_state_get(
|
.room_state_get(
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&EventType::RoomMember,
|
&EventType::RoomMember,
|
||||||
&sender_id.to_string(),
|
&sender_user.to_string(),
|
||||||
)?
|
)?
|
||||||
.ok_or(Error::BadRequest(
|
.ok_or(Error::BadRequest(
|
||||||
ErrorKind::BadState,
|
ErrorKind::BadState,
|
||||||
|
@ -114,10 +114,10 @@ pub async fn leave_room_route(
|
||||||
event_type: EventType::RoomMember,
|
event_type: EventType::RoomMember,
|
||||||
content: serde_json::to_value(event).expect("event is valid, we just created it"),
|
content: serde_json::to_value(event).expect("event is valid, we just created it"),
|
||||||
unsigned: None,
|
unsigned: None,
|
||||||
state_key: Some(sender_id.to_string()),
|
state_key: Some(sender_user.to_string()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -135,7 +135,7 @@ pub async fn invite_user_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<invite_user::Request<'_>>,
|
body: Ruma<invite_user::Request<'_>>,
|
||||||
) -> ConduitResult<invite_user::Response> {
|
) -> ConduitResult<invite_user::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if let invite_user::IncomingInvitationRecipient::UserId { user_id } = &body.recipient {
|
if let invite_user::IncomingInvitationRecipient::UserId { user_id } = &body.recipient {
|
||||||
db.rooms.build_and_append_pdu(
|
db.rooms.build_and_append_pdu(
|
||||||
|
@ -153,7 +153,7 @@ pub async fn invite_user_route(
|
||||||
state_key: Some(user_id.to_string()),
|
state_key: Some(user_id.to_string()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -174,7 +174,7 @@ pub async fn kick_user_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<kick_user::Request<'_>>,
|
body: Ruma<kick_user::Request<'_>>,
|
||||||
) -> ConduitResult<kick_user::Response> {
|
) -> ConduitResult<kick_user::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut event = serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
|
let mut event = serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
|
||||||
db.rooms
|
db.rooms
|
||||||
|
@ -204,7 +204,7 @@ pub async fn kick_user_route(
|
||||||
state_key: Some(body.user_id.to_string()),
|
state_key: Some(body.user_id.to_string()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -222,7 +222,7 @@ pub async fn ban_user_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<ban_user::Request<'_>>,
|
body: Ruma<ban_user::Request<'_>>,
|
||||||
) -> ConduitResult<ban_user::Response> {
|
) -> ConduitResult<ban_user::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
// TODO: reason
|
// TODO: reason
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ pub async fn ban_user_route(
|
||||||
state_key: Some(body.user_id.to_string()),
|
state_key: Some(body.user_id.to_string()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -278,7 +278,7 @@ pub async fn unban_user_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<unban_user::Request<'_>>,
|
body: Ruma<unban_user::Request<'_>>,
|
||||||
) -> ConduitResult<unban_user::Response> {
|
) -> ConduitResult<unban_user::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut event = serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
|
let mut event = serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
|
||||||
db.rooms
|
db.rooms
|
||||||
|
@ -307,7 +307,7 @@ pub async fn unban_user_route(
|
||||||
state_key: Some(body.user_id.to_string()),
|
state_key: Some(body.user_id.to_string()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -325,9 +325,9 @@ pub fn forget_room_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<forget_room::Request<'_>>,
|
body: Ruma<forget_room::Request<'_>>,
|
||||||
) -> ConduitResult<forget_room::Response> {
|
) -> ConduitResult<forget_room::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
db.rooms.forget(&body.room_id, &sender_id)?;
|
db.rooms.forget(&body.room_id, &sender_user)?;
|
||||||
|
|
||||||
Ok(forget_room::Response::new().into())
|
Ok(forget_room::Response::new().into())
|
||||||
}
|
}
|
||||||
|
@ -340,12 +340,12 @@ pub fn joined_rooms_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<joined_rooms::Request>,
|
body: Ruma<joined_rooms::Request>,
|
||||||
) -> ConduitResult<joined_rooms::Response> {
|
) -> ConduitResult<joined_rooms::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
Ok(joined_rooms::Response {
|
Ok(joined_rooms::Response {
|
||||||
joined_rooms: db
|
joined_rooms: db
|
||||||
.rooms
|
.rooms
|
||||||
.rooms_joined(&sender_id)
|
.rooms_joined(&sender_user)
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
|
@ -360,9 +360,9 @@ pub fn get_member_events_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_member_events::Request<'_>>,
|
body: Ruma<get_member_events::Request<'_>>,
|
||||||
) -> ConduitResult<get_member_events::Response> {
|
) -> ConduitResult<get_member_events::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !db.rooms.is_joined(sender_id, &body.room_id)? {
|
if !db.rooms.is_joined(sender_user, &body.room_id)? {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::Forbidden,
|
ErrorKind::Forbidden,
|
||||||
"You don't have permission to view this room.",
|
"You don't have permission to view this room.",
|
||||||
|
@ -388,11 +388,11 @@ pub fn joined_members_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<joined_members::Request<'_>>,
|
body: Ruma<joined_members::Request<'_>>,
|
||||||
) -> ConduitResult<joined_members::Response> {
|
) -> ConduitResult<joined_members::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !db
|
if !db
|
||||||
.rooms
|
.rooms
|
||||||
.is_joined(&sender_id, &body.room_id)
|
.is_joined(&sender_user, &body.room_id)
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
|
@ -420,12 +420,12 @@ pub fn joined_members_route(
|
||||||
|
|
||||||
async fn join_room_by_id_helper(
|
async fn join_room_by_id_helper(
|
||||||
db: &Database,
|
db: &Database,
|
||||||
sender_id: Option<&UserId>,
|
sender_user: Option<&UserId>,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
servers: &[Box<ServerName>],
|
servers: &[Box<ServerName>],
|
||||||
_third_party_signed: Option<&IncomingThirdPartySigned>,
|
_third_party_signed: Option<&IncomingThirdPartySigned>,
|
||||||
) -> ConduitResult<join_room_by_id::Response> {
|
) -> ConduitResult<join_room_by_id::Response> {
|
||||||
let sender_id = sender_id.expect("user is authenticated");
|
let sender_user = sender_user.expect("user is authenticated");
|
||||||
|
|
||||||
// Ask a remote server if we don't have this room
|
// Ask a remote server if we don't have this room
|
||||||
if !db.rooms.exists(&room_id)? && room_id.server_name() != db.globals.server_name() {
|
if !db.rooms.exists(&room_id)? && room_id.server_name() != db.globals.server_name() {
|
||||||
|
@ -439,7 +439,7 @@ async fn join_room_by_id_helper(
|
||||||
remote_server.clone(),
|
remote_server.clone(),
|
||||||
federation::membership::create_join_event_template::v1::Request {
|
federation::membership::create_join_event_template::v1::Request {
|
||||||
room_id,
|
room_id,
|
||||||
user_id: sender_id,
|
user_id: sender_user,
|
||||||
ver: &[RoomVersionId::Version5, RoomVersionId::Version6],
|
ver: &[RoomVersionId::Version5, RoomVersionId::Version6],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -479,8 +479,8 @@ async fn join_room_by_id_helper(
|
||||||
"content".to_owned(),
|
"content".to_owned(),
|
||||||
serde_json::to_value(member::MemberEventContent {
|
serde_json::to_value(member::MemberEventContent {
|
||||||
membership: member::MembershipState::Join,
|
membership: member::MembershipState::Join,
|
||||||
displayname: db.users.displayname(&sender_id)?,
|
displayname: db.users.displayname(&sender_user)?,
|
||||||
avatar_url: db.users.avatar_url(&sender_id)?,
|
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||||
is_direct: None,
|
is_direct: None,
|
||||||
third_party_invite: None,
|
third_party_invite: None,
|
||||||
})
|
})
|
||||||
|
@ -668,8 +668,8 @@ async fn join_room_by_id_helper(
|
||||||
} else {
|
} else {
|
||||||
let event = member::MemberEventContent {
|
let event = member::MemberEventContent {
|
||||||
membership: member::MembershipState::Join,
|
membership: member::MembershipState::Join,
|
||||||
displayname: db.users.displayname(&sender_id)?,
|
displayname: db.users.displayname(&sender_user)?,
|
||||||
avatar_url: db.users.avatar_url(&sender_id)?,
|
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||||
is_direct: None,
|
is_direct: None,
|
||||||
third_party_invite: None,
|
third_party_invite: None,
|
||||||
};
|
};
|
||||||
|
@ -679,10 +679,10 @@ async fn join_room_by_id_helper(
|
||||||
event_type: EventType::RoomMember,
|
event_type: EventType::RoomMember,
|
||||||
content: serde_json::to_value(event).expect("event is valid, we just created it"),
|
content: serde_json::to_value(event).expect("event is valid, we just created it"),
|
||||||
unsigned: None,
|
unsigned: None,
|
||||||
state_key: Some(sender_id.to_string()),
|
state_key: Some(sender_user.to_string()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
|
|
@ -21,13 +21,13 @@ pub async fn send_message_event_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<send_message_event::Request<'_>>,
|
body: Ruma<send_message_event::Request<'_>>,
|
||||||
) -> ConduitResult<send_message_event::Response> {
|
) -> ConduitResult<send_message_event::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
// Check if this is a new transaction id
|
// Check if this is a new transaction id
|
||||||
if let Some(response) = db
|
if let Some(response) =
|
||||||
.transaction_ids
|
db.transaction_ids
|
||||||
.existing_txnid(sender_id, device_id, &body.txn_id)?
|
.existing_txnid(sender_user, sender_device, &body.txn_id)?
|
||||||
{
|
{
|
||||||
// The client might have sent a txnid of the /sendToDevice endpoint
|
// The client might have sent a txnid of the /sendToDevice endpoint
|
||||||
// This txnid has no response associated with it
|
// This txnid has no response associated with it
|
||||||
|
@ -63,15 +63,19 @@ pub async fn send_message_event_route(
|
||||||
state_key: None,
|
state_key: None,
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
&db.account_data,
|
&db.account_data,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
db.transaction_ids
|
db.transaction_ids.add_txnid(
|
||||||
.add_txnid(sender_id, device_id, &body.txn_id, event_id.as_bytes())?;
|
sender_user,
|
||||||
|
sender_device,
|
||||||
|
&body.txn_id,
|
||||||
|
event_id.as_bytes(),
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(send_message_event::Response::new(event_id).into())
|
Ok(send_message_event::Response::new(event_id).into())
|
||||||
}
|
}
|
||||||
|
@ -84,9 +88,9 @@ pub fn get_message_events_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_message_events::Request<'_>>,
|
body: Ruma<get_message_events::Request<'_>>,
|
||||||
) -> ConduitResult<get_message_events::Response> {
|
) -> ConduitResult<get_message_events::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !db.rooms.is_joined(sender_id, &body.room_id)? {
|
if !db.rooms.is_joined(sender_user, &body.room_id)? {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::Forbidden,
|
ErrorKind::Forbidden,
|
||||||
"You don't have permission to view this room.",
|
"You don't have permission to view this room.",
|
||||||
|
@ -111,7 +115,7 @@ pub fn get_message_events_route(
|
||||||
get_message_events::Direction::Forward => {
|
get_message_events::Direction::Forward => {
|
||||||
let events_after = db
|
let events_after = db
|
||||||
.rooms
|
.rooms
|
||||||
.pdus_after(&sender_id, &body.room_id, from)
|
.pdus_after(&sender_user, &body.room_id, from)
|
||||||
.take(limit)
|
.take(limit)
|
||||||
.filter_map(|r| r.ok()) // Filter out buggy events
|
.filter_map(|r| r.ok()) // Filter out buggy events
|
||||||
.filter_map(|(pdu_id, pdu)| {
|
.filter_map(|(pdu_id, pdu)| {
|
||||||
|
@ -141,7 +145,7 @@ pub fn get_message_events_route(
|
||||||
get_message_events::Direction::Backward => {
|
get_message_events::Direction::Backward => {
|
||||||
let events_before = db
|
let events_before = db
|
||||||
.rooms
|
.rooms
|
||||||
.pdus_until(&sender_id, &body.room_id, from)
|
.pdus_until(&sender_user, &body.room_id, from)
|
||||||
.take(limit)
|
.take(limit)
|
||||||
.filter_map(|r| r.ok()) // Filter out buggy events
|
.filter_map(|r| r.ok()) // Filter out buggy events
|
||||||
.filter_map(|(pdu_id, pdu)| {
|
.filter_map(|(pdu_id, pdu)| {
|
||||||
|
|
|
@ -14,19 +14,19 @@ pub fn set_presence_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<set_presence::Request<'_>>,
|
body: Ruma<set_presence::Request<'_>>,
|
||||||
) -> ConduitResult<set_presence::Response> {
|
) -> ConduitResult<set_presence::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
for room_id in db.rooms.rooms_joined(&sender_id) {
|
for room_id in db.rooms.rooms_joined(&sender_user) {
|
||||||
let room_id = room_id?;
|
let room_id = room_id?;
|
||||||
|
|
||||||
db.rooms.edus.update_presence(
|
db.rooms.edus.update_presence(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
ruma::events::presence::PresenceEvent {
|
ruma::events::presence::PresenceEvent {
|
||||||
content: ruma::events::presence::PresenceEventContent {
|
content: ruma::events::presence::PresenceEventContent {
|
||||||
avatar_url: db.users.avatar_url(&sender_id)?,
|
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||||
currently_active: None,
|
currently_active: None,
|
||||||
displayname: db.users.displayname(&sender_id)?,
|
displayname: db.users.displayname(&sender_user)?,
|
||||||
last_active_ago: Some(
|
last_active_ago: Some(
|
||||||
utils::millis_since_unix_epoch()
|
utils::millis_since_unix_epoch()
|
||||||
.try_into()
|
.try_into()
|
||||||
|
@ -35,7 +35,7 @@ pub fn set_presence_route(
|
||||||
presence: body.presence,
|
presence: body.presence,
|
||||||
status_msg: body.status_msg.clone(),
|
status_msg: body.status_msg.clone(),
|
||||||
},
|
},
|
||||||
sender: sender_id.clone(),
|
sender: sender_user.clone(),
|
||||||
},
|
},
|
||||||
&db.globals,
|
&db.globals,
|
||||||
)?;
|
)?;
|
||||||
|
|
|
@ -23,13 +23,13 @@ pub async fn set_displayname_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<set_display_name::Request<'_>>,
|
body: Ruma<set_display_name::Request<'_>>,
|
||||||
) -> ConduitResult<set_display_name::Response> {
|
) -> ConduitResult<set_display_name::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
db.users
|
db.users
|
||||||
.set_displayname(&sender_id, body.displayname.clone())?;
|
.set_displayname(&sender_user, body.displayname.clone())?;
|
||||||
|
|
||||||
// Send a new membership event and presence update into all joined rooms
|
// Send a new membership event and presence update into all joined rooms
|
||||||
for room_id in db.rooms.rooms_joined(&sender_id) {
|
for room_id in db.rooms.rooms_joined(&sender_user) {
|
||||||
let room_id = room_id?;
|
let room_id = room_id?;
|
||||||
db.rooms.build_and_append_pdu(
|
db.rooms.build_and_append_pdu(
|
||||||
PduBuilder {
|
PduBuilder {
|
||||||
|
@ -41,7 +41,7 @@ pub async fn set_displayname_route(
|
||||||
.room_state_get(
|
.room_state_get(
|
||||||
&room_id,
|
&room_id,
|
||||||
&EventType::RoomMember,
|
&EventType::RoomMember,
|
||||||
&sender_id.to_string(),
|
&sender_user.to_string(),
|
||||||
)?
|
)?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::bad_database(
|
Error::bad_database(
|
||||||
|
@ -57,10 +57,10 @@ pub async fn set_displayname_route(
|
||||||
})
|
})
|
||||||
.expect("event is valid, we just created it"),
|
.expect("event is valid, we just created it"),
|
||||||
unsigned: None,
|
unsigned: None,
|
||||||
state_key: Some(sender_id.to_string()),
|
state_key: Some(sender_user.to_string()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -69,13 +69,13 @@ pub async fn set_displayname_route(
|
||||||
|
|
||||||
// Presence update
|
// Presence update
|
||||||
db.rooms.edus.update_presence(
|
db.rooms.edus.update_presence(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
ruma::events::presence::PresenceEvent {
|
ruma::events::presence::PresenceEvent {
|
||||||
content: ruma::events::presence::PresenceEventContent {
|
content: ruma::events::presence::PresenceEventContent {
|
||||||
avatar_url: db.users.avatar_url(&sender_id)?,
|
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||||
currently_active: None,
|
currently_active: None,
|
||||||
displayname: db.users.displayname(&sender_id)?,
|
displayname: db.users.displayname(&sender_user)?,
|
||||||
last_active_ago: Some(
|
last_active_ago: Some(
|
||||||
utils::millis_since_unix_epoch()
|
utils::millis_since_unix_epoch()
|
||||||
.try_into()
|
.try_into()
|
||||||
|
@ -84,7 +84,7 @@ pub async fn set_displayname_route(
|
||||||
presence: ruma::presence::PresenceState::Online,
|
presence: ruma::presence::PresenceState::Online,
|
||||||
status_msg: None,
|
status_msg: None,
|
||||||
},
|
},
|
||||||
sender: sender_id.clone(),
|
sender: sender_user.clone(),
|
||||||
},
|
},
|
||||||
&db.globals,
|
&db.globals,
|
||||||
)?;
|
)?;
|
||||||
|
@ -115,13 +115,13 @@ pub async fn set_avatar_url_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<set_avatar_url::Request<'_>>,
|
body: Ruma<set_avatar_url::Request<'_>>,
|
||||||
) -> ConduitResult<set_avatar_url::Response> {
|
) -> ConduitResult<set_avatar_url::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
db.users
|
db.users
|
||||||
.set_avatar_url(&sender_id, body.avatar_url.clone())?;
|
.set_avatar_url(&sender_user, body.avatar_url.clone())?;
|
||||||
|
|
||||||
// Send a new membership event and presence update into all joined rooms
|
// Send a new membership event and presence update into all joined rooms
|
||||||
for room_id in db.rooms.rooms_joined(&sender_id) {
|
for room_id in db.rooms.rooms_joined(&sender_user) {
|
||||||
let room_id = room_id?;
|
let room_id = room_id?;
|
||||||
db.rooms.build_and_append_pdu(
|
db.rooms.build_and_append_pdu(
|
||||||
PduBuilder {
|
PduBuilder {
|
||||||
|
@ -133,7 +133,7 @@ pub async fn set_avatar_url_route(
|
||||||
.room_state_get(
|
.room_state_get(
|
||||||
&room_id,
|
&room_id,
|
||||||
&EventType::RoomMember,
|
&EventType::RoomMember,
|
||||||
&sender_id.to_string(),
|
&sender_user.to_string(),
|
||||||
)?
|
)?
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
Error::bad_database(
|
Error::bad_database(
|
||||||
|
@ -149,10 +149,10 @@ pub async fn set_avatar_url_route(
|
||||||
})
|
})
|
||||||
.expect("event is valid, we just created it"),
|
.expect("event is valid, we just created it"),
|
||||||
unsigned: None,
|
unsigned: None,
|
||||||
state_key: Some(sender_id.to_string()),
|
state_key: Some(sender_user.to_string()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -161,13 +161,13 @@ pub async fn set_avatar_url_route(
|
||||||
|
|
||||||
// Presence update
|
// Presence update
|
||||||
db.rooms.edus.update_presence(
|
db.rooms.edus.update_presence(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
ruma::events::presence::PresenceEvent {
|
ruma::events::presence::PresenceEvent {
|
||||||
content: ruma::events::presence::PresenceEventContent {
|
content: ruma::events::presence::PresenceEventContent {
|
||||||
avatar_url: db.users.avatar_url(&sender_id)?,
|
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||||
currently_active: None,
|
currently_active: None,
|
||||||
displayname: db.users.displayname(&sender_id)?,
|
displayname: db.users.displayname(&sender_user)?,
|
||||||
last_active_ago: Some(
|
last_active_ago: Some(
|
||||||
utils::millis_since_unix_epoch()
|
utils::millis_since_unix_epoch()
|
||||||
.try_into()
|
.try_into()
|
||||||
|
@ -176,7 +176,7 @@ pub async fn set_avatar_url_route(
|
||||||
presence: ruma::presence::PresenceState::Online,
|
presence: ruma::presence::PresenceState::Online,
|
||||||
status_msg: None,
|
status_msg: None,
|
||||||
},
|
},
|
||||||
sender: sender_id.clone(),
|
sender: sender_user.clone(),
|
||||||
},
|
},
|
||||||
&db.globals,
|
&db.globals,
|
||||||
)?;
|
)?;
|
||||||
|
|
|
@ -20,11 +20,11 @@ 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 sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let event = db
|
let event = db
|
||||||
.account_data
|
.account_data
|
||||||
.get::<ruma::events::push_rules::PushRulesEvent>(None, &sender_id, EventType::PushRules)?
|
.get::<ruma::events::push_rules::PushRulesEvent>(None, &sender_user, EventType::PushRules)?
|
||||||
.ok_or(Error::BadRequest(
|
.ok_or(Error::BadRequest(
|
||||||
ErrorKind::NotFound,
|
ErrorKind::NotFound,
|
||||||
"PushRules event not found.",
|
"PushRules event not found.",
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub fn set_read_marker_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<set_read_marker::Request<'_>>,
|
body: Ruma<set_read_marker::Request<'_>>,
|
||||||
) -> ConduitResult<set_read_marker::Response> {
|
) -> ConduitResult<set_read_marker::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let fully_read_event = ruma::events::fully_read::FullyReadEvent {
|
let fully_read_event = ruma::events::fully_read::FullyReadEvent {
|
||||||
content: ruma::events::fully_read::FullyReadEventContent {
|
content: ruma::events::fully_read::FullyReadEventContent {
|
||||||
|
@ -27,7 +27,7 @@ pub fn set_read_marker_route(
|
||||||
};
|
};
|
||||||
db.account_data.update(
|
db.account_data.update(
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
&sender_id,
|
&sender_user,
|
||||||
EventType::FullyRead,
|
EventType::FullyRead,
|
||||||
&fully_read_event,
|
&fully_read_event,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
|
@ -36,7 +36,7 @@ pub fn set_read_marker_route(
|
||||||
if let Some(event) = &body.read_receipt {
|
if let Some(event) = &body.read_receipt {
|
||||||
db.rooms.edus.private_read_set(
|
db.rooms.edus.private_read_set(
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&sender_id,
|
&sender_user,
|
||||||
db.rooms.get_pdu_count(event)?.ok_or(Error::BadRequest(
|
db.rooms.get_pdu_count(event)?.ok_or(Error::BadRequest(
|
||||||
ErrorKind::InvalidParam,
|
ErrorKind::InvalidParam,
|
||||||
"Event does not exist.",
|
"Event does not exist.",
|
||||||
|
@ -46,7 +46,7 @@ pub fn set_read_marker_route(
|
||||||
|
|
||||||
let mut user_receipts = BTreeMap::new();
|
let mut user_receipts = BTreeMap::new();
|
||||||
user_receipts.insert(
|
user_receipts.insert(
|
||||||
sender_id.clone(),
|
sender_user.clone(),
|
||||||
ruma::events::receipt::Receipt {
|
ruma::events::receipt::Receipt {
|
||||||
ts: Some(SystemTime::now()),
|
ts: Some(SystemTime::now()),
|
||||||
},
|
},
|
||||||
|
@ -60,7 +60,7 @@ pub fn set_read_marker_route(
|
||||||
);
|
);
|
||||||
|
|
||||||
db.rooms.edus.readreceipt_update(
|
db.rooms.edus.readreceipt_update(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
AnyEvent::Ephemeral(AnyEphemeralRoomEvent::Receipt(
|
AnyEvent::Ephemeral(AnyEphemeralRoomEvent::Receipt(
|
||||||
ruma::events::receipt::ReceiptEvent {
|
ruma::events::receipt::ReceiptEvent {
|
||||||
|
|
|
@ -16,7 +16,7 @@ pub async fn redact_event_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<redact_event::Request<'_>>,
|
body: Ruma<redact_event::Request<'_>>,
|
||||||
) -> ConduitResult<redact_event::Response> {
|
) -> ConduitResult<redact_event::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let event_id = db.rooms.build_and_append_pdu(
|
let event_id = db.rooms.build_and_append_pdu(
|
||||||
PduBuilder {
|
PduBuilder {
|
||||||
|
@ -29,7 +29,7 @@ pub async fn redact_event_route(
|
||||||
state_key: None,
|
state_key: None,
|
||||||
redacts: Some(body.event_id.clone()),
|
redacts: Some(body.event_id.clone()),
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
|
|
@ -24,7 +24,7 @@ pub async 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 sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let room_id = RoomId::new(db.globals.server_name());
|
let room_id = RoomId::new(db.globals.server_name());
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ pub async fn create_room_route(
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut content = ruma::events::room::create::CreateEventContent::new(sender_id.clone());
|
let mut content = ruma::events::room::create::CreateEventContent::new(sender_user.clone());
|
||||||
content.federate = body.creation_content.federate;
|
content.federate = body.creation_content.federate;
|
||||||
content.predecessor = body.creation_content.predecessor.clone();
|
content.predecessor = body.creation_content.predecessor.clone();
|
||||||
content.room_version = RoomVersionId::Version6;
|
content.room_version = RoomVersionId::Version6;
|
||||||
|
@ -61,7 +61,7 @@ pub async fn create_room_route(
|
||||||
state_key: Some("".to_owned()),
|
state_key: Some("".to_owned()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -74,17 +74,17 @@ pub async fn create_room_route(
|
||||||
event_type: EventType::RoomMember,
|
event_type: EventType::RoomMember,
|
||||||
content: serde_json::to_value(member::MemberEventContent {
|
content: serde_json::to_value(member::MemberEventContent {
|
||||||
membership: member::MembershipState::Join,
|
membership: member::MembershipState::Join,
|
||||||
displayname: db.users.displayname(&sender_id)?,
|
displayname: db.users.displayname(&sender_user)?,
|
||||||
avatar_url: db.users.avatar_url(&sender_id)?,
|
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||||
is_direct: Some(body.is_direct),
|
is_direct: Some(body.is_direct),
|
||||||
third_party_invite: None,
|
third_party_invite: None,
|
||||||
})
|
})
|
||||||
.expect("event is valid, we just created it"),
|
.expect("event is valid, we just created it"),
|
||||||
unsigned: None,
|
unsigned: None,
|
||||||
state_key: Some(sender_id.to_string()),
|
state_key: Some(sender_user.to_string()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -93,7 +93,7 @@ pub async fn create_room_route(
|
||||||
|
|
||||||
// 3. Power levels
|
// 3. Power levels
|
||||||
let mut users = BTreeMap::new();
|
let mut users = BTreeMap::new();
|
||||||
users.insert(sender_id.clone(), 100.into());
|
users.insert(sender_user.clone(), 100.into());
|
||||||
for invite_ in &body.invite {
|
for invite_ in &body.invite {
|
||||||
users.insert(invite_.clone(), 100.into());
|
users.insert(invite_.clone(), 100.into());
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ pub async fn create_room_route(
|
||||||
state_key: Some("".to_owned()),
|
state_key: Some("".to_owned()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -161,7 +161,7 @@ pub async fn create_room_route(
|
||||||
state_key: Some("".to_owned()),
|
state_key: Some("".to_owned()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -180,7 +180,7 @@ pub async fn create_room_route(
|
||||||
state_key: Some("".to_owned()),
|
state_key: Some("".to_owned()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -207,7 +207,7 @@ pub async fn create_room_route(
|
||||||
state_key: Some("".to_owned()),
|
state_key: Some("".to_owned()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -228,7 +228,7 @@ pub async fn create_room_route(
|
||||||
|
|
||||||
db.rooms.build_and_append_pdu(
|
db.rooms.build_and_append_pdu(
|
||||||
pdu_builder,
|
pdu_builder,
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -251,7 +251,7 @@ pub async fn create_room_route(
|
||||||
state_key: Some("".to_owned()),
|
state_key: Some("".to_owned()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -271,7 +271,7 @@ pub async fn create_room_route(
|
||||||
state_key: Some("".to_owned()),
|
state_key: Some("".to_owned()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -296,7 +296,7 @@ pub async fn create_room_route(
|
||||||
state_key: Some(user.to_string()),
|
state_key: Some(user.to_string()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -324,9 +324,9 @@ pub fn get_room_event_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_room_event::Request<'_>>,
|
body: Ruma<get_room_event::Request<'_>>,
|
||||||
) -> ConduitResult<get_room_event::Response> {
|
) -> ConduitResult<get_room_event::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !db.rooms.is_joined(sender_id, &body.room_id)? {
|
if !db.rooms.is_joined(sender_user, &body.room_id)? {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::Forbidden,
|
ErrorKind::Forbidden,
|
||||||
"You don't have permission to view this room.",
|
"You don't have permission to view this room.",
|
||||||
|
@ -352,7 +352,7 @@ pub async fn upgrade_room_route(
|
||||||
body: Ruma<upgrade_room::Request<'_>>,
|
body: Ruma<upgrade_room::Request<'_>>,
|
||||||
_room_id: String,
|
_room_id: String,
|
||||||
) -> ConduitResult<upgrade_room::Response> {
|
) -> ConduitResult<upgrade_room::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if !matches!(
|
if !matches!(
|
||||||
body.new_version,
|
body.new_version,
|
||||||
|
@ -381,7 +381,7 @@ pub async fn upgrade_room_route(
|
||||||
state_key: Some("".to_owned()),
|
state_key: Some("".to_owned()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
sender_id,
|
sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -408,7 +408,7 @@ pub async fn upgrade_room_route(
|
||||||
|
|
||||||
// Send a m.room.create event containing a predecessor field and the applicable room_version
|
// Send a m.room.create event containing a predecessor field and the applicable room_version
|
||||||
let mut create_event_content =
|
let mut create_event_content =
|
||||||
ruma::events::room::create::CreateEventContent::new(sender_id.clone());
|
ruma::events::room::create::CreateEventContent::new(sender_user.clone());
|
||||||
create_event_content.federate = federate;
|
create_event_content.federate = federate;
|
||||||
create_event_content.room_version = body.new_version.clone();
|
create_event_content.room_version = body.new_version.clone();
|
||||||
create_event_content.predecessor = predecessor;
|
create_event_content.predecessor = predecessor;
|
||||||
|
@ -422,7 +422,7 @@ pub async fn upgrade_room_route(
|
||||||
state_key: Some("".to_owned()),
|
state_key: Some("".to_owned()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
sender_id,
|
sender_user,
|
||||||
&replacement_room,
|
&replacement_room,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -435,17 +435,17 @@ pub async fn upgrade_room_route(
|
||||||
event_type: EventType::RoomMember,
|
event_type: EventType::RoomMember,
|
||||||
content: serde_json::to_value(member::MemberEventContent {
|
content: serde_json::to_value(member::MemberEventContent {
|
||||||
membership: member::MembershipState::Join,
|
membership: member::MembershipState::Join,
|
||||||
displayname: db.users.displayname(&sender_id)?,
|
displayname: db.users.displayname(&sender_user)?,
|
||||||
avatar_url: db.users.avatar_url(&sender_id)?,
|
avatar_url: db.users.avatar_url(&sender_user)?,
|
||||||
is_direct: None,
|
is_direct: None,
|
||||||
third_party_invite: None,
|
third_party_invite: None,
|
||||||
})
|
})
|
||||||
.expect("event is valid, we just created it"),
|
.expect("event is valid, we just created it"),
|
||||||
unsigned: None,
|
unsigned: None,
|
||||||
state_key: Some(sender_id.to_string()),
|
state_key: Some(sender_user.to_string()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
sender_id,
|
sender_user,
|
||||||
&replacement_room,
|
&replacement_room,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -480,7 +480,7 @@ pub async fn upgrade_room_route(
|
||||||
state_key: Some("".to_owned()),
|
state_key: Some("".to_owned()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
sender_id,
|
sender_user,
|
||||||
&replacement_room,
|
&replacement_room,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
@ -524,7 +524,7 @@ pub async fn upgrade_room_route(
|
||||||
state_key: Some("".to_owned()),
|
state_key: Some("".to_owned()),
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
sender_id,
|
sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub fn search_events_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<search_events::Request<'_>>,
|
body: Ruma<search_events::Request<'_>>,
|
||||||
) -> ConduitResult<search_events::Response> {
|
) -> ConduitResult<search_events::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let search_criteria = body.search_categories.room_events.as_ref().unwrap();
|
let search_criteria = body.search_categories.room_events.as_ref().unwrap();
|
||||||
let filter = search_criteria.filter.as_ref().unwrap();
|
let filter = search_criteria.filter.as_ref().unwrap();
|
||||||
|
@ -24,7 +24,7 @@ pub fn search_events_route(
|
||||||
|
|
||||||
let limit = filter.limit.map_or(10, |l| u64::from(l) as usize);
|
let limit = filter.limit.map_or(10, |l| u64::from(l) as usize);
|
||||||
|
|
||||||
if !db.rooms.is_joined(sender_id, &room_id)? {
|
if !db.rooms.is_joined(sender_user, &room_id)? {
|
||||||
return Err(Error::BadRequest(
|
return Err(Error::BadRequest(
|
||||||
ErrorKind::Forbidden,
|
ErrorKind::Forbidden,
|
||||||
"You don't have permission to view this room.",
|
"You don't have permission to view this room.",
|
||||||
|
|
|
@ -117,10 +117,10 @@ pub fn logout_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<logout::Request>,
|
body: Ruma<logout::Request>,
|
||||||
) -> ConduitResult<logout::Response> {
|
) -> ConduitResult<logout::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
db.users.remove_device(&sender_id, device_id)?;
|
db.users.remove_device(&sender_user, sender_device)?;
|
||||||
|
|
||||||
Ok(logout::Response::new().into())
|
Ok(logout::Response::new().into())
|
||||||
}
|
}
|
||||||
|
@ -142,11 +142,11 @@ pub fn logout_all_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<logout_all::Request>,
|
body: Ruma<logout_all::Request>,
|
||||||
) -> ConduitResult<logout_all::Response> {
|
) -> ConduitResult<logout_all::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
for device_id in db.users.all_device_ids(sender_id) {
|
for device_id in db.users.all_device_ids(sender_user) {
|
||||||
if let Ok(device_id) = device_id {
|
if let Ok(device_id) = device_id {
|
||||||
db.users.remove_device(&sender_id, &device_id)?;
|
db.users.remove_device(&sender_user, &device_id)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ pub async fn send_state_event_for_key_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<send_state_event_for_key::Request<'_>>,
|
body: Ruma<send_state_event_for_key::Request<'_>>,
|
||||||
) -> ConduitResult<send_state_event_for_key::Response> {
|
) -> ConduitResult<send_state_event_for_key::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let content = serde_json::from_str::<serde_json::Value>(
|
let content = serde_json::from_str::<serde_json::Value>(
|
||||||
body.json_body
|
body.json_body
|
||||||
|
@ -40,7 +40,7 @@ pub async fn send_state_event_for_key_route(
|
||||||
Ok(send_state_event_for_key::Response::new(
|
Ok(send_state_event_for_key::Response::new(
|
||||||
send_state_event_for_key_helper(
|
send_state_event_for_key_helper(
|
||||||
&db,
|
&db,
|
||||||
sender_id,
|
sender_user,
|
||||||
&body.content,
|
&body.content,
|
||||||
content,
|
content,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
|
@ -62,8 +62,8 @@ pub async fn send_state_event_for_empty_key_route(
|
||||||
// This just calls send_state_event_for_key_route
|
// This just calls send_state_event_for_key_route
|
||||||
let Ruma {
|
let Ruma {
|
||||||
body,
|
body,
|
||||||
sender_id,
|
sender_user,
|
||||||
device_id: _,
|
sender_device: _,
|
||||||
json_body,
|
json_body,
|
||||||
} = body;
|
} = body;
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ pub async fn send_state_event_for_empty_key_route(
|
||||||
Ok(send_state_event_for_empty_key::Response::new(
|
Ok(send_state_event_for_empty_key::Response::new(
|
||||||
send_state_event_for_key_helper(
|
send_state_event_for_key_helper(
|
||||||
&db,
|
&db,
|
||||||
sender_id
|
sender_user
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("no user for send state empty key rout"),
|
.expect("no user for send state empty key rout"),
|
||||||
&body.content,
|
&body.content,
|
||||||
|
@ -99,11 +99,11 @@ pub fn get_state_events_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_state_events::Request>,
|
body: Ruma<get_state_events::Request>,
|
||||||
) -> ConduitResult<get_state_events::Response> {
|
) -> ConduitResult<get_state_events::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
// Users not in the room should not be able to access the state unless history_visibility is
|
// Users not in the room should not be able to access the state unless history_visibility is
|
||||||
// WorldReadable
|
// WorldReadable
|
||||||
if !db.rooms.is_joined(sender_id, &body.room_id)? {
|
if !db.rooms.is_joined(sender_user, &body.room_id)? {
|
||||||
if !matches!(
|
if !matches!(
|
||||||
db.rooms
|
db.rooms
|
||||||
.room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")?
|
.room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")?
|
||||||
|
@ -144,11 +144,11 @@ 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>,
|
||||||
) -> ConduitResult<get_state_events_for_key::Response> {
|
) -> ConduitResult<get_state_events_for_key::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
// Users not in the room should not be able to access the state unless history_visibility is
|
// Users not in the room should not be able to access the state unless history_visibility is
|
||||||
// WorldReadable
|
// WorldReadable
|
||||||
if !db.rooms.is_joined(sender_id, &body.room_id)? {
|
if !db.rooms.is_joined(sender_user, &body.room_id)? {
|
||||||
if !matches!(
|
if !matches!(
|
||||||
db.rooms
|
db.rooms
|
||||||
.room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")?
|
.room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")?
|
||||||
|
@ -193,11 +193,11 @@ 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>,
|
||||||
) -> ConduitResult<get_state_events_for_empty_key::Response> {
|
) -> ConduitResult<get_state_events_for_empty_key::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
// Users not in the room should not be able to access the state unless history_visibility is
|
// Users not in the room should not be able to access the state unless history_visibility is
|
||||||
// WorldReadable
|
// WorldReadable
|
||||||
if !db.rooms.is_joined(sender_id, &body.room_id)? {
|
if !db.rooms.is_joined(sender_user, &body.room_id)? {
|
||||||
if !matches!(
|
if !matches!(
|
||||||
db.rooms
|
db.rooms
|
||||||
.room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")?
|
.room_state_get(&body.room_id, &EventType::RoomHistoryVisibility, "")?
|
||||||
|
@ -242,7 +242,7 @@ pub async fn send_state_event_for_key_helper(
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
state_key: Option<String>,
|
state_key: Option<String>,
|
||||||
) -> Result<EventId> {
|
) -> Result<EventId> {
|
||||||
let sender_id = sender;
|
let sender_user = sender;
|
||||||
|
|
||||||
if let AnyStateEventContent::RoomCanonicalAlias(canonical_alias) = content {
|
if let AnyStateEventContent::RoomCanonicalAlias(canonical_alias) = content {
|
||||||
let mut aliases = canonical_alias.alt_aliases.clone();
|
let mut aliases = canonical_alias.alt_aliases.clone();
|
||||||
|
@ -276,7 +276,7 @@ pub async fn send_state_event_for_key_helper(
|
||||||
state_key,
|
state_key,
|
||||||
redacts: None,
|
redacts: None,
|
||||||
},
|
},
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
&db.sending,
|
&db.sending,
|
||||||
|
|
|
@ -33,14 +33,14 @@ pub async fn sync_events_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<sync_events::Request<'_>>,
|
body: Ruma<sync_events::Request<'_>>,
|
||||||
) -> ConduitResult<sync_events::Response> {
|
) -> ConduitResult<sync_events::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
// TODO: match body.set_presence {
|
// TODO: match body.set_presence {
|
||||||
db.rooms.edus.ping_presence(&sender_id)?;
|
db.rooms.edus.ping_presence(&sender_user)?;
|
||||||
|
|
||||||
// Setup watchers, so if there's no response, we can wait for them
|
// Setup watchers, so if there's no response, we can wait for them
|
||||||
let watcher = db.watch(sender_id, device_id);
|
let watcher = db.watch(sender_user, sender_device);
|
||||||
|
|
||||||
let next_batch = db.globals.current_count()?.to_string();
|
let next_batch = db.globals.current_count()?.to_string();
|
||||||
|
|
||||||
|
@ -59,16 +59,16 @@ pub async fn sync_events_route(
|
||||||
// Look for device list updates of this account
|
// Look for device list updates of this account
|
||||||
device_list_updates.extend(
|
device_list_updates.extend(
|
||||||
db.users
|
db.users
|
||||||
.keys_changed(&sender_id.to_string(), since, None)
|
.keys_changed(&sender_user.to_string(), since, None)
|
||||||
.filter_map(|r| r.ok()),
|
.filter_map(|r| r.ok()),
|
||||||
);
|
);
|
||||||
|
|
||||||
for room_id in db.rooms.rooms_joined(&sender_id) {
|
for room_id in db.rooms.rooms_joined(&sender_user) {
|
||||||
let room_id = room_id?;
|
let room_id = room_id?;
|
||||||
|
|
||||||
let mut non_timeline_pdus = db
|
let mut non_timeline_pdus = db
|
||||||
.rooms
|
.rooms
|
||||||
.pdus_since(&sender_id, &room_id, since)?
|
.pdus_since(&sender_user, &room_id, since)?
|
||||||
.filter_map(|r| r.ok()); // Filter out buggy events
|
.filter_map(|r| r.ok()); // Filter out buggy events
|
||||||
|
|
||||||
// Take the last 10 events for the timeline
|
// Take the last 10 events for the timeline
|
||||||
|
@ -85,7 +85,7 @@ pub async fn sync_events_route(
|
||||||
|| db
|
|| db
|
||||||
.rooms
|
.rooms
|
||||||
.edus
|
.edus
|
||||||
.last_privateread_update(&sender_id, &room_id)?
|
.last_privateread_update(&sender_user, &room_id)?
|
||||||
> since;
|
> since;
|
||||||
|
|
||||||
// They /sync response doesn't always return all messages, so we say the output is
|
// They /sync response doesn't always return all messages, so we say the output is
|
||||||
|
@ -110,7 +110,7 @@ pub async fn sync_events_route(
|
||||||
// since and the current room state, meaning there should be no updates.
|
// since and the current room state, meaning there should be no updates.
|
||||||
// The inner Option is None when there is an event, but there is no state hash associated
|
// The inner Option is None when there is an event, but there is no state hash associated
|
||||||
// with it. This can happen for the RoomCreate event, so all updates should arrive.
|
// with it. This can happen for the RoomCreate event, so all updates should arrive.
|
||||||
let first_pdu_after_since = db.rooms.pdus_after(sender_id, &room_id, since).next();
|
let first_pdu_after_since = db.rooms.pdus_after(sender_user, &room_id, since).next();
|
||||||
|
|
||||||
let since_state_hash = first_pdu_after_since
|
let since_state_hash = first_pdu_after_since
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -146,7 +146,7 @@ pub async fn sync_events_route(
|
||||||
|
|
||||||
let since_sender_member = since_members.as_ref().map(|since_members| {
|
let since_sender_member = since_members.as_ref().map(|since_members| {
|
||||||
since_members.as_ref().and_then(|members| {
|
since_members.as_ref().and_then(|members| {
|
||||||
members.get(sender_id.as_str()).and_then(|pdu| {
|
members.get(sender_user.as_str()).and_then(|pdu| {
|
||||||
serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
|
serde_json::from_value::<Raw<ruma::events::room::member::MemberEventContent>>(
|
||||||
pdu.content.clone(),
|
pdu.content.clone(),
|
||||||
)
|
)
|
||||||
|
@ -198,7 +198,7 @@ pub async fn sync_events_route(
|
||||||
match (since_membership, current_membership) {
|
match (since_membership, current_membership) {
|
||||||
(MembershipState::Leave, MembershipState::Join) => {
|
(MembershipState::Leave, MembershipState::Join) => {
|
||||||
// A new user joined an encrypted room
|
// A new user joined an encrypted room
|
||||||
if !share_encrypted_room(&db, &sender_id, &user_id, &room_id) {
|
if !share_encrypted_room(&db, &sender_user, &user_id, &room_id) {
|
||||||
device_list_updates.insert(user_id);
|
device_list_updates.insert(user_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,11 +223,11 @@ pub async fn sync_events_route(
|
||||||
.filter_map(|user_id| Some(user_id.ok()?))
|
.filter_map(|user_id| Some(user_id.ok()?))
|
||||||
.filter(|user_id| {
|
.filter(|user_id| {
|
||||||
// Don't send key updates from the sender to the sender
|
// Don't send key updates from the sender to the sender
|
||||||
sender_id != user_id
|
sender_user != user_id
|
||||||
})
|
})
|
||||||
.filter(|user_id| {
|
.filter(|user_id| {
|
||||||
// Only send keys if the sender doesn't share an encrypted room with the target already
|
// Only send keys if the sender doesn't share an encrypted room with the target already
|
||||||
!share_encrypted_room(&db, sender_id, user_id, &room_id)
|
!share_encrypted_room(&db, sender_user, user_id, &room_id)
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ pub async fn sync_events_route(
|
||||||
|
|
||||||
for hero in db
|
for hero in db
|
||||||
.rooms
|
.rooms
|
||||||
.all_pdus(&sender_id, &room_id)?
|
.all_pdus(&sender_user, &room_id)?
|
||||||
.filter_map(|pdu| pdu.ok()) // Ignore all broken pdus
|
.filter_map(|pdu| pdu.ok()) // Ignore all broken pdus
|
||||||
.filter(|(_, pdu)| pdu.kind == EventType::RoomMember)
|
.filter(|(_, pdu)| pdu.kind == EventType::RoomMember)
|
||||||
.map(|(_, pdu)| {
|
.map(|(_, pdu)| {
|
||||||
|
@ -287,7 +287,7 @@ pub async fn sync_events_route(
|
||||||
// Filter for possible heroes
|
// Filter for possible heroes
|
||||||
.filter_map(|u| u)
|
.filter_map(|u| u)
|
||||||
{
|
{
|
||||||
if heroes.contains(&hero) || hero == sender_id.as_str() {
|
if heroes.contains(&hero) || hero == sender_user.as_str() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,10 +305,10 @@ pub async fn sync_events_route(
|
||||||
};
|
};
|
||||||
|
|
||||||
let notification_count = if send_notification_counts {
|
let notification_count = if send_notification_counts {
|
||||||
if let Some(last_read) = db.rooms.edus.private_read_get(&room_id, &sender_id)? {
|
if let Some(last_read) = db.rooms.edus.private_read_get(&room_id, &sender_user)? {
|
||||||
Some(
|
Some(
|
||||||
(db.rooms
|
(db.rooms
|
||||||
.pdus_since(&sender_id, &room_id, last_read)?
|
.pdus_since(&sender_user, &room_id, last_read)?
|
||||||
.filter_map(|pdu| pdu.ok()) // Filter out buggy events
|
.filter_map(|pdu| pdu.ok()) // Filter out buggy events
|
||||||
.filter(|(_, pdu)| {
|
.filter(|(_, pdu)| {
|
||||||
matches!(
|
matches!(
|
||||||
|
@ -360,7 +360,7 @@ pub async fn sync_events_route(
|
||||||
account_data: sync_events::AccountData {
|
account_data: sync_events::AccountData {
|
||||||
events: db
|
events: db
|
||||||
.account_data
|
.account_data
|
||||||
.changes_since(Some(&room_id), &sender_id, since)?
|
.changes_since(Some(&room_id), &sender_user, since)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|(_, v)| {
|
.filter_map(|(_, v)| {
|
||||||
serde_json::from_str(v.json().get())
|
serde_json::from_str(v.json().get())
|
||||||
|
@ -438,9 +438,9 @@ pub async fn sync_events_route(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut left_rooms = BTreeMap::new();
|
let mut left_rooms = BTreeMap::new();
|
||||||
for room_id in db.rooms.rooms_left(&sender_id) {
|
for room_id in db.rooms.rooms_left(&sender_user) {
|
||||||
let room_id = room_id?;
|
let room_id = room_id?;
|
||||||
let pdus = db.rooms.pdus_since(&sender_id, &room_id, since)?;
|
let pdus = db.rooms.pdus_since(&sender_user, &room_id, since)?;
|
||||||
let room_events = pdus
|
let room_events = pdus
|
||||||
.filter_map(|pdu| pdu.ok()) // Filter out buggy events
|
.filter_map(|pdu| pdu.ok()) // Filter out buggy events
|
||||||
.map(|(_, pdu)| pdu.to_sync_room_event())
|
.map(|(_, pdu)| pdu.to_sync_room_event())
|
||||||
|
@ -458,7 +458,7 @@ pub async fn sync_events_route(
|
||||||
|
|
||||||
let since_member = db
|
let since_member = db
|
||||||
.rooms
|
.rooms
|
||||||
.pdus_after(sender_id, &room_id, since)
|
.pdus_after(sender_user, &room_id, since)
|
||||||
.next()
|
.next()
|
||||||
.and_then(|pdu| pdu.ok())
|
.and_then(|pdu| pdu.ok())
|
||||||
.and_then(|pdu| {
|
.and_then(|pdu| {
|
||||||
|
@ -470,7 +470,7 @@ pub async fn sync_events_route(
|
||||||
})
|
})
|
||||||
.and_then(|state_hash| {
|
.and_then(|state_hash| {
|
||||||
db.rooms
|
db.rooms
|
||||||
.state_get(&state_hash, &EventType::RoomMember, sender_id.as_str())
|
.state_get(&state_hash, &EventType::RoomMember, sender_user.as_str())
|
||||||
.ok()?
|
.ok()?
|
||||||
.ok_or_else(|| Error::bad_database("State hash in db doesn't have a state."))
|
.ok_or_else(|| Error::bad_database("State hash in db doesn't have a state."))
|
||||||
.ok()
|
.ok()
|
||||||
|
@ -495,12 +495,12 @@ pub async fn sync_events_route(
|
||||||
.filter_map(|user_id| Some(user_id.ok()?))
|
.filter_map(|user_id| Some(user_id.ok()?))
|
||||||
.filter(|user_id| {
|
.filter(|user_id| {
|
||||||
// Don't send key updates from the sender to the sender
|
// Don't send key updates from the sender to the sender
|
||||||
sender_id != user_id
|
sender_user != user_id
|
||||||
})
|
})
|
||||||
.filter(|user_id| {
|
.filter(|user_id| {
|
||||||
// Only send if the sender doesn't share any encrypted room with the target
|
// Only send if the sender doesn't share any encrypted room with the target
|
||||||
// anymore
|
// anymore
|
||||||
!share_encrypted_room(&db, sender_id, user_id, &room_id)
|
!share_encrypted_room(&db, sender_user, user_id, &room_id)
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -511,12 +511,12 @@ pub async fn sync_events_route(
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut invited_rooms = BTreeMap::new();
|
let mut invited_rooms = BTreeMap::new();
|
||||||
for room_id in db.rooms.rooms_invited(&sender_id) {
|
for room_id in db.rooms.rooms_invited(&sender_user) {
|
||||||
let room_id = room_id?;
|
let room_id = room_id?;
|
||||||
let mut invited_since_last_sync = false;
|
let mut invited_since_last_sync = false;
|
||||||
for pdu in db.rooms.pdus_since(&sender_id, &room_id, since)? {
|
for pdu in db.rooms.pdus_since(&sender_user, &room_id, since)? {
|
||||||
let (_, pdu) = pdu?;
|
let (_, pdu) = pdu?;
|
||||||
if pdu.kind == EventType::RoomMember && pdu.state_key == Some(sender_id.to_string()) {
|
if pdu.kind == EventType::RoomMember && pdu.state_key == Some(sender_user.to_string()) {
|
||||||
let content = serde_json::from_value::<
|
let content = serde_json::from_value::<
|
||||||
Raw<ruma::events::room::member::MemberEventContent>,
|
Raw<ruma::events::room::member::MemberEventContent>,
|
||||||
>(pdu.content.clone())
|
>(pdu.content.clone())
|
||||||
|
@ -554,7 +554,7 @@ pub async fn sync_events_route(
|
||||||
for user_id in left_encrypted_users {
|
for user_id in left_encrypted_users {
|
||||||
let still_share_encrypted_room = db
|
let still_share_encrypted_room = db
|
||||||
.rooms
|
.rooms
|
||||||
.get_shared_rooms(vec![sender_id.clone(), user_id.clone()])
|
.get_shared_rooms(vec![sender_user.clone(), user_id.clone()])
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
.filter_map(|other_room_id| {
|
.filter_map(|other_room_id| {
|
||||||
Some(
|
Some(
|
||||||
|
@ -574,7 +574,7 @@ pub async fn sync_events_route(
|
||||||
|
|
||||||
// Remove all to-device events the device received *last time*
|
// Remove all to-device events the device received *last time*
|
||||||
db.users
|
db.users
|
||||||
.remove_to_device_events(sender_id, device_id, since)?;
|
.remove_to_device_events(sender_user, sender_device, since)?;
|
||||||
|
|
||||||
let response = sync_events::Response {
|
let response = sync_events::Response {
|
||||||
next_batch,
|
next_batch,
|
||||||
|
@ -592,7 +592,7 @@ pub async fn sync_events_route(
|
||||||
account_data: sync_events::AccountData {
|
account_data: sync_events::AccountData {
|
||||||
events: db
|
events: db
|
||||||
.account_data
|
.account_data
|
||||||
.changes_since(None, &sender_id, since)?
|
.changes_since(None, &sender_user, since)?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|(_, v)| {
|
.filter_map(|(_, v)| {
|
||||||
serde_json::from_str(v.json().get())
|
serde_json::from_str(v.json().get())
|
||||||
|
@ -605,15 +605,15 @@ pub async fn sync_events_route(
|
||||||
changed: device_list_updates.into_iter().collect(),
|
changed: device_list_updates.into_iter().collect(),
|
||||||
left: device_list_left.into_iter().collect(),
|
left: device_list_left.into_iter().collect(),
|
||||||
},
|
},
|
||||||
device_one_time_keys_count: if db.users.last_one_time_keys_update(sender_id)? > since
|
device_one_time_keys_count: if db.users.last_one_time_keys_update(sender_user)? > since
|
||||||
|| since == 0
|
|| since == 0
|
||||||
{
|
{
|
||||||
db.users.count_one_time_keys(sender_id, device_id)?
|
db.users.count_one_time_keys(sender_user, sender_device)?
|
||||||
} else {
|
} else {
|
||||||
BTreeMap::new()
|
BTreeMap::new()
|
||||||
},
|
},
|
||||||
to_device: sync_events::ToDevice {
|
to_device: sync_events::ToDevice {
|
||||||
events: db.users.get_to_device_events(sender_id, device_id)?,
|
events: db.users.get_to_device_events(sender_user, sender_device)?,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -644,12 +644,12 @@ pub async fn sync_events_route(
|
||||||
|
|
||||||
fn share_encrypted_room(
|
fn share_encrypted_room(
|
||||||
db: &Database,
|
db: &Database,
|
||||||
sender_id: &UserId,
|
sender_user: &UserId,
|
||||||
user_id: &UserId,
|
user_id: &UserId,
|
||||||
ignore_room: &RoomId,
|
ignore_room: &RoomId,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
db.rooms
|
db.rooms
|
||||||
.get_shared_rooms(vec![sender_id.clone(), user_id.clone()])
|
.get_shared_rooms(vec![sender_user.clone(), user_id.clone()])
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
.filter(|room_id| room_id != ignore_room)
|
.filter(|room_id| room_id != ignore_room)
|
||||||
.filter_map(|other_room_id| {
|
.filter_map(|other_room_id| {
|
||||||
|
|
|
@ -17,11 +17,11 @@ pub fn update_tag_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<create_tag::Request<'_>>,
|
body: Ruma<create_tag::Request<'_>>,
|
||||||
) -> ConduitResult<create_tag::Response> {
|
) -> ConduitResult<create_tag::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut tags_event = db
|
let mut tags_event = db
|
||||||
.account_data
|
.account_data
|
||||||
.get::<ruma::events::tag::TagEvent>(Some(&body.room_id), sender_id, EventType::Tag)?
|
.get::<ruma::events::tag::TagEvent>(Some(&body.room_id), sender_user, EventType::Tag)?
|
||||||
.unwrap_or_else(|| ruma::events::tag::TagEvent {
|
.unwrap_or_else(|| ruma::events::tag::TagEvent {
|
||||||
content: ruma::events::tag::TagEventContent {
|
content: ruma::events::tag::TagEventContent {
|
||||||
tags: BTreeMap::new(),
|
tags: BTreeMap::new(),
|
||||||
|
@ -34,7 +34,7 @@ pub fn update_tag_route(
|
||||||
|
|
||||||
db.account_data.update(
|
db.account_data.update(
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
sender_id,
|
sender_user,
|
||||||
EventType::Tag,
|
EventType::Tag,
|
||||||
&tags_event,
|
&tags_event,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
|
@ -51,11 +51,11 @@ pub fn delete_tag_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<delete_tag::Request<'_>>,
|
body: Ruma<delete_tag::Request<'_>>,
|
||||||
) -> ConduitResult<delete_tag::Response> {
|
) -> ConduitResult<delete_tag::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
let mut tags_event = db
|
let mut tags_event = db
|
||||||
.account_data
|
.account_data
|
||||||
.get::<ruma::events::tag::TagEvent>(Some(&body.room_id), sender_id, EventType::Tag)?
|
.get::<ruma::events::tag::TagEvent>(Some(&body.room_id), sender_user, EventType::Tag)?
|
||||||
.unwrap_or_else(|| ruma::events::tag::TagEvent {
|
.unwrap_or_else(|| ruma::events::tag::TagEvent {
|
||||||
content: ruma::events::tag::TagEventContent {
|
content: ruma::events::tag::TagEventContent {
|
||||||
tags: BTreeMap::new(),
|
tags: BTreeMap::new(),
|
||||||
|
@ -65,7 +65,7 @@ pub fn delete_tag_route(
|
||||||
|
|
||||||
db.account_data.update(
|
db.account_data.update(
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
sender_id,
|
sender_user,
|
||||||
EventType::Tag,
|
EventType::Tag,
|
||||||
&tags_event,
|
&tags_event,
|
||||||
&db.globals,
|
&db.globals,
|
||||||
|
@ -82,12 +82,12 @@ pub fn get_tags_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<get_tags::Request<'_>>,
|
body: Ruma<get_tags::Request<'_>>,
|
||||||
) -> ConduitResult<get_tags::Response> {
|
) -> ConduitResult<get_tags::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
Ok(get_tags::Response {
|
Ok(get_tags::Response {
|
||||||
tags: db
|
tags: db
|
||||||
.account_data
|
.account_data
|
||||||
.get::<ruma::events::tag::TagEvent>(Some(&body.room_id), sender_id, EventType::Tag)?
|
.get::<ruma::events::tag::TagEvent>(Some(&body.room_id), sender_user, EventType::Tag)?
|
||||||
.unwrap_or_else(|| ruma::events::tag::TagEvent {
|
.unwrap_or_else(|| ruma::events::tag::TagEvent {
|
||||||
content: ruma::events::tag::TagEventContent {
|
content: ruma::events::tag::TagEventContent {
|
||||||
tags: BTreeMap::new(),
|
tags: BTreeMap::new(),
|
||||||
|
|
|
@ -16,13 +16,13 @@ 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<'_>>,
|
||||||
) -> ConduitResult<send_event_to_device::Response> {
|
) -> ConduitResult<send_event_to_device::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
let device_id = body.device_id.as_ref().expect("user is authenticated");
|
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
// Check if this is a new transaction id
|
// Check if this is a new transaction id
|
||||||
if db
|
if db
|
||||||
.transaction_ids
|
.transaction_ids
|
||||||
.existing_txnid(sender_id, device_id, &body.txn_id)?
|
.existing_txnid(sender_user, sender_device, &body.txn_id)?
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
return Ok(send_event_to_device::Response.into());
|
return Ok(send_event_to_device::Response.into());
|
||||||
|
@ -33,7 +33,7 @@ pub fn send_event_to_device_route(
|
||||||
match target_device_id_maybe {
|
match target_device_id_maybe {
|
||||||
to_device::DeviceIdOrAllDevices::DeviceId(target_device_id) => {
|
to_device::DeviceIdOrAllDevices::DeviceId(target_device_id) => {
|
||||||
db.users.add_to_device_event(
|
db.users.add_to_device_event(
|
||||||
sender_id,
|
sender_user,
|
||||||
&target_user_id,
|
&target_user_id,
|
||||||
&target_device_id,
|
&target_device_id,
|
||||||
&body.event_type,
|
&body.event_type,
|
||||||
|
@ -47,7 +47,7 @@ pub fn send_event_to_device_route(
|
||||||
to_device::DeviceIdOrAllDevices::AllDevices => {
|
to_device::DeviceIdOrAllDevices::AllDevices => {
|
||||||
for target_device_id in db.users.all_device_ids(&target_user_id) {
|
for target_device_id in db.users.all_device_ids(&target_user_id) {
|
||||||
db.users.add_to_device_event(
|
db.users.add_to_device_event(
|
||||||
sender_id,
|
sender_user,
|
||||||
&target_user_id,
|
&target_user_id,
|
||||||
&target_device_id?,
|
&target_device_id?,
|
||||||
&body.event_type,
|
&body.event_type,
|
||||||
|
@ -64,7 +64,7 @@ pub fn send_event_to_device_route(
|
||||||
|
|
||||||
// Save transaction id with empty data
|
// Save transaction id with empty data
|
||||||
db.transaction_ids
|
db.transaction_ids
|
||||||
.add_txnid(sender_id, device_id, &body.txn_id, &[])?;
|
.add_txnid(sender_user, sender_device, &body.txn_id, &[])?;
|
||||||
|
|
||||||
Ok(send_event_to_device::Response.into())
|
Ok(send_event_to_device::Response.into())
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,11 @@ pub fn create_typing_event_route(
|
||||||
db: State<'_, Database>,
|
db: State<'_, Database>,
|
||||||
body: Ruma<create_typing_event::Request<'_>>,
|
body: Ruma<create_typing_event::Request<'_>>,
|
||||||
) -> ConduitResult<create_typing_event::Response> {
|
) -> ConduitResult<create_typing_event::Response> {
|
||||||
let sender_id = body.sender_id.as_ref().expect("user is authenticated");
|
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||||
|
|
||||||
if let Typing::Yes(duration) = body.state {
|
if let Typing::Yes(duration) = body.state {
|
||||||
db.rooms.edus.typing_add(
|
db.rooms.edus.typing_add(
|
||||||
&sender_id,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
duration.as_millis() as u64 + utils::millis_since_unix_epoch(),
|
duration.as_millis() as u64 + utils::millis_since_unix_epoch(),
|
||||||
&db.globals,
|
&db.globals,
|
||||||
|
@ -26,7 +26,7 @@ pub fn create_typing_event_route(
|
||||||
} else {
|
} else {
|
||||||
db.rooms
|
db.rooms
|
||||||
.edus
|
.edus
|
||||||
.typing_remove(&sender_id, &body.room_id, &db.globals)?;
|
.typing_remove(&sender_user, &body.room_id, &db.globals)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(create_typing_event::Response.into())
|
Ok(create_typing_event::Response.into())
|
||||||
|
|
|
@ -26,8 +26,8 @@ use {
|
||||||
/// first.
|
/// first.
|
||||||
pub struct Ruma<T: Outgoing> {
|
pub struct Ruma<T: Outgoing> {
|
||||||
pub body: T::Incoming,
|
pub body: T::Incoming,
|
||||||
pub sender_id: Option<UserId>,
|
pub sender_user: Option<UserId>,
|
||||||
pub device_id: Option<Box<DeviceId>>,
|
pub sender_device: Option<Box<DeviceId>>,
|
||||||
pub json_body: Option<Box<serde_json::value::RawValue>>, // This is None when body is not a valid string
|
pub json_body: Option<Box<serde_json::value::RawValue>>, // This is None when body is not a valid string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ where
|
||||||
.await
|
.await
|
||||||
.expect("database was loaded");
|
.expect("database was loaded");
|
||||||
|
|
||||||
let (user_id, device_id) = if T::METADATA.requires_authentication {
|
let (sender_user, sender_device) = if T::METADATA.requires_authentication {
|
||||||
// Get token from header or query value
|
// Get token from header or query value
|
||||||
let token = match request
|
let token = match request
|
||||||
.headers()
|
.headers()
|
||||||
|
@ -102,8 +102,8 @@ where
|
||||||
match <T as Outgoing>::Incoming::try_from(http_request) {
|
match <T as Outgoing>::Incoming::try_from(http_request) {
|
||||||
Ok(t) => Success(Ruma {
|
Ok(t) => Success(Ruma {
|
||||||
body: t,
|
body: t,
|
||||||
sender_id: user_id,
|
sender_user,
|
||||||
device_id,
|
sender_device,
|
||||||
// TODO: Can we avoid parsing it again? (We only need this for append_pdu)
|
// TODO: Can we avoid parsing it again? (We only need this for append_pdu)
|
||||||
json_body: utils::string_from_bytes(&body)
|
json_body: utils::string_from_bytes(&body)
|
||||||
.ok()
|
.ok()
|
||||||
|
|
|
@ -83,6 +83,7 @@ POST /register rejects registration of usernames with '|'
|
||||||
POST /register rejects registration of usernames with '}'
|
POST /register rejects registration of usernames with '}'
|
||||||
POST /register rejects registration of usernames with '£'
|
POST /register rejects registration of usernames with '£'
|
||||||
POST /register rejects registration of usernames with 'é'
|
POST /register rejects registration of usernames with 'é'
|
||||||
|
POST /register returns the same device_id as that in the request
|
||||||
POST /rooms/:room_id/ban can ban a user
|
POST /rooms/:room_id/ban can ban a user
|
||||||
POST /rooms/:room_id/invite can send an invite
|
POST /rooms/:room_id/invite can send an invite
|
||||||
POST /rooms/:room_id/join can join a room
|
POST /rooms/:room_id/join can join a room
|
||||||
|
@ -116,6 +117,7 @@ Typing events appear in incremental sync
|
||||||
Typing events appear in initial sync
|
Typing events appear in initial sync
|
||||||
Uninvited users cannot join the room
|
Uninvited users cannot join the room
|
||||||
User appears in user directory
|
User appears in user directory
|
||||||
|
User directory correctly update on display name change
|
||||||
User in dir while user still shares private rooms
|
User in dir while user still shares private rooms
|
||||||
User in shared private room does appear in user directory
|
User in shared private room does appear in user directory
|
||||||
User is offline if they set_presence=offline in their sync
|
User is offline if they set_presence=offline in their sync
|
||||||
|
|
Loading…
Add table
Reference in a new issue