feat: implement appservices
this also reverts some stateres changes
This commit is contained in:
parent
d62f17a91a
commit
6e5b35ea92
26 changed files with 696 additions and 584 deletions
|
@ -139,18 +139,20 @@ pub async fn register_route(
|
|||
auth_error: None,
|
||||
};
|
||||
|
||||
if let Some(auth) = &body.auth {
|
||||
let (worked, uiaainfo) =
|
||||
db.uiaa
|
||||
.try_auth(&user_id, "".into(), auth, &uiaainfo, &db.users, &db.globals)?;
|
||||
if !worked {
|
||||
if !body.from_appservice {
|
||||
if let Some(auth) = &body.auth {
|
||||
let (worked, uiaainfo) =
|
||||
db.uiaa
|
||||
.try_auth(&user_id, "".into(), auth, &uiaainfo, &db.users, &db.globals)?;
|
||||
if !worked {
|
||||
return Err(Error::Uiaa(uiaainfo));
|
||||
}
|
||||
// Success!
|
||||
} else {
|
||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||
db.uiaa.create(&user_id, "".into(), &uiaainfo)?;
|
||||
return Err(Error::Uiaa(uiaainfo));
|
||||
}
|
||||
// Success!
|
||||
} else {
|
||||
uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH));
|
||||
db.uiaa.create(&user_id, "".into(), &uiaainfo)?;
|
||||
return Err(Error::Uiaa(uiaainfo));
|
||||
}
|
||||
|
||||
if missing_username {
|
||||
|
@ -241,6 +243,7 @@ pub async fn register_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// 2. Make conduit bot join
|
||||
|
@ -265,6 +268,7 @@ pub async fn register_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// 3. Power levels
|
||||
|
@ -302,6 +306,7 @@ pub async fn register_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// 4.1 Join Rules
|
||||
|
@ -322,6 +327,7 @@ pub async fn register_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// 4.2 History Visibility
|
||||
|
@ -344,6 +350,7 @@ pub async fn register_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// 4.3 Guest Access
|
||||
|
@ -364,6 +371,7 @@ pub async fn register_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// 6. Events implied by name and topic
|
||||
|
@ -386,6 +394,7 @@ pub async fn register_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
db.rooms.build_and_append_pdu(
|
||||
|
@ -405,6 +414,7 @@ pub async fn register_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// Room alias
|
||||
|
@ -430,6 +440,7 @@ pub async fn register_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
db.rooms.set_alias(&alias, Some(&room_id), &db.globals)?;
|
||||
|
@ -456,6 +467,7 @@ pub async fn register_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
|
@ -478,6 +490,7 @@ pub async fn register_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// Send welcome message
|
||||
|
@ -506,6 +519,7 @@ pub async fn register_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
@ -681,6 +695,7 @@ pub async fn deactivate_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
use super::State;
|
||||
use crate::{server_server, ConduitResult, Database, Error, Ruma};
|
||||
use crate::{appservice_server, server_server, ConduitResult, Database, Error, Ruma};
|
||||
use ruma::{
|
||||
api::{
|
||||
appservice,
|
||||
client::{
|
||||
error::ErrorKind,
|
||||
r0::alias::{create_alias, delete_alias, get_alias},
|
||||
|
@ -75,13 +76,37 @@ pub async fn get_alias_helper(
|
|||
return Ok(get_alias::Response::new(response.room_id, response.servers).into());
|
||||
}
|
||||
|
||||
let room_id = db
|
||||
.rooms
|
||||
.id_from_alias(&room_alias)?
|
||||
.ok_or(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"Room with alias not found.",
|
||||
))?;
|
||||
let mut room_id = None;
|
||||
match db.rooms.id_from_alias(&room_alias)? {
|
||||
Some(r) => room_id = Some(r),
|
||||
None => {
|
||||
for (_id, registration) in db.appservice.iter_all().filter_map(|r| r.ok()) {
|
||||
if appservice_server::send_request(
|
||||
&db.globals,
|
||||
registration,
|
||||
appservice::query::query_room_alias::v1::Request { room_alias },
|
||||
)
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
room_id = Some(db.rooms.id_from_alias(&room_alias)?.ok_or_else(|| {
|
||||
Error::bad_config("Appservice lied to us. Room does not exist.")
|
||||
})?);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let room_id = match room_id {
|
||||
Some(room_id) => room_id,
|
||||
None => {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::NotFound,
|
||||
"Room with alias not found.",
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
Ok(get_alias::Response::new(room_id, vec![db.globals.server_name().to_owned()]).into())
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ pub async fn create_content_route(
|
|||
|
||||
db.flush().await?;
|
||||
|
||||
Ok(create_content::Response { content_uri: mxc }.into())
|
||||
Ok(create_content::Response { content_uri: mxc, blurhash: None }.into())
|
||||
}
|
||||
|
||||
#[cfg_attr(
|
||||
|
|
|
@ -128,6 +128,7 @@ pub async fn leave_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
db.flush().await?;
|
||||
|
@ -167,6 +168,7 @@ pub async fn invite_user_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
db.flush().await?;
|
||||
|
@ -222,6 +224,7 @@ pub async fn kick_user_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
db.flush().await?;
|
||||
|
@ -281,6 +284,7 @@ pub async fn ban_user_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
db.flush().await?;
|
||||
|
@ -332,6 +336,7 @@ pub async fn unban_user_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
db.flush().await?;
|
||||
|
@ -713,6 +718,7 @@ async fn join_room_by_id_helper(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ pub async fn send_message_event_route(
|
|||
body: Ruma<send_message_event::Request<'_>>,
|
||||
) -> ConduitResult<send_message_event::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||
let sender_device = body.sender_device.as_deref();
|
||||
|
||||
// Check if this is a new transaction id
|
||||
if let Some(response) =
|
||||
|
@ -69,6 +69,7 @@ pub async fn send_message_event_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
db.transaction_ids.add_txnid(
|
||||
|
|
|
@ -67,6 +67,7 @@ pub async fn set_displayname_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// Presence update
|
||||
|
@ -163,6 +164,7 @@ pub async fn set_avatar_url_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// Presence update
|
||||
|
|
|
@ -35,6 +35,7 @@ pub async fn redact_event_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
db.flush().await?;
|
||||
|
|
|
@ -69,6 +69,7 @@ pub async fn create_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// 2. Let the room creator join
|
||||
|
@ -93,6 +94,7 @@ pub async fn create_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// 3. Power levels
|
||||
|
@ -137,6 +139,7 @@ pub async fn create_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// 4. Events set by preset
|
||||
|
@ -176,6 +179,7 @@ pub async fn create_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// 4.2 History Visibility
|
||||
|
@ -196,6 +200,7 @@ pub async fn create_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// 4.3 Guest Access
|
||||
|
@ -224,6 +229,7 @@ pub async fn create_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// 5. Events listed in initial_state
|
||||
|
@ -246,6 +252,7 @@ pub async fn create_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
@ -270,6 +277,7 @@ pub async fn create_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
@ -291,6 +299,7 @@ pub async fn create_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
@ -317,6 +326,7 @@ pub async fn create_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
@ -407,6 +417,7 @@ pub async fn upgrade_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// Get the old room federations status
|
||||
|
@ -450,6 +461,7 @@ pub async fn upgrade_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// Join the new room
|
||||
|
@ -474,6 +486,7 @@ pub async fn upgrade_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
// Recommended transferable state events list from the specs
|
||||
|
@ -510,6 +523,7 @@ pub async fn upgrade_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
}
|
||||
|
||||
|
@ -556,6 +570,7 @@ pub async fn upgrade_room_route(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
db.flush().await?;
|
||||
|
|
|
@ -63,8 +63,8 @@ pub async fn send_state_event_for_empty_key_route(
|
|||
let Ruma {
|
||||
body,
|
||||
sender_user,
|
||||
sender_device: _,
|
||||
json_body,
|
||||
..
|
||||
} = body;
|
||||
|
||||
let json = serde_json::from_str::<serde_json::Value>(
|
||||
|
@ -288,6 +288,7 @@ pub async fn send_state_event_for_key_helper(
|
|||
&db.sending,
|
||||
&db.admin,
|
||||
&db.account_data,
|
||||
&db.appservice,
|
||||
)?;
|
||||
|
||||
Ok(event_id)
|
||||
|
|
|
@ -17,7 +17,7 @@ pub async fn send_event_to_device_route(
|
|||
body: Ruma<send_event_to_device::Request<'_>>,
|
||||
) -> ConduitResult<send_event_to_device::Response> {
|
||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
||||
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
|
||||
let sender_device = body.sender_device.as_deref();
|
||||
|
||||
// Check if this is a new transaction id
|
||||
if db
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue