Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4710a974c4 |
870
Cargo.lock
generated
870
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -172,7 +172,7 @@ features = [
|
|||||||
"ring-compat",
|
"ring-compat",
|
||||||
"state-res",
|
"state-res",
|
||||||
"unstable-msc2448",
|
"unstable-msc2448",
|
||||||
#[cfg(feature = "msc3266")]
|
#[cfg(feature = "unstable-msc3266")]
|
||||||
"unstable-msc3266",
|
"unstable-msc3266",
|
||||||
"unstable-msc4186",
|
"unstable-msc4186",
|
||||||
]
|
]
|
||||||
@@ -191,11 +191,12 @@ nix = { version = "0.30", features = ["resource"] }
|
|||||||
backend_rocksdb = ["rocksdb"]
|
backend_rocksdb = ["rocksdb"]
|
||||||
backend_sqlite = ["sqlite"]
|
backend_sqlite = ["sqlite"]
|
||||||
conduit_bin = ["axum"]
|
conduit_bin = ["axum"]
|
||||||
default = ["backend_rocksdb", "backend_sqlite", "conduit_bin", "proposal_msc3266", "systemd"]
|
default = ["backend_rocksdb", "backend_sqlite", "conduit_bin", "systemd", "unstable-msc3266"]
|
||||||
jemalloc = ["tikv-jemallocator"]
|
jemalloc = ["tikv-jemallocator"]
|
||||||
sqlite = ["parking_lot", "rusqlite", "tokio/signal"]
|
sqlite = ["parking_lot", "rusqlite", "tokio/signal"]
|
||||||
systemd = ["sd-notify"]
|
systemd = ["sd-notify"]
|
||||||
proposal_msc3266 = ["msc3266"]
|
#unstable-features = ["unstable-msc3266"]
|
||||||
|
unstable-msc3266 = []
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "conduit"
|
name = "conduit"
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ mod search;
|
|||||||
mod session;
|
mod session;
|
||||||
mod space;
|
mod space;
|
||||||
mod state;
|
mod state;
|
||||||
#[cfg(feature = "msc3266")]
|
#[cfg(feature = "unstable-msc3266")]
|
||||||
mod summary;
|
mod summary;
|
||||||
mod sync;
|
mod sync;
|
||||||
mod tag;
|
mod tag;
|
||||||
@@ -64,7 +64,7 @@ pub use room::*;
|
|||||||
pub use search::*;
|
pub use search::*;
|
||||||
pub use session::*;
|
pub use session::*;
|
||||||
pub use space::*;
|
pub use space::*;
|
||||||
#[cfg(feature = "msc3266")]
|
#[cfg(feature = "unstable-msc3266")]
|
||||||
pub use summary::*;
|
pub use summary::*;
|
||||||
pub use state::*;
|
pub use state::*;
|
||||||
pub use sync::*;
|
pub use sync::*;
|
||||||
|
|||||||
@@ -4,10 +4,9 @@
|
|||||||
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
//use crate::{service::rooms::spaces::PagnationToken, services, Error, Result, Ruma};
|
use crate::{service::rooms::summary::SummaryRequest, services, Error, Result, Ruma};
|
||||||
use crate::{service::rooms::::PagnationToken, services, Error, Result, Ruma};
|
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::client::{error::ErrorKind, summary::get_summary, space::get_hierarchy},
|
api::client::{error::ErrorKind, room::get_summary},
|
||||||
UInt,
|
UInt,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -39,47 +38,21 @@ use ruma::{
|
|||||||
/// since the server may not have access to the current state of the room.
|
/// since the server may not have access to the current state of the room.
|
||||||
|
|
||||||
pub async fn get_room_summary_route(
|
pub async fn get_room_summary_route(
|
||||||
body: Ruma<get_summary::v1::Request>,
|
body: Ruma<get_summary::msc3266::Request>,
|
||||||
) -> Result<get_summary::v1::Response> {
|
) -> Result<get_summary::msc3266::Response> {
|
||||||
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
|
let room_id_or_alias = <OwnedRoomOrAliasId as AsRef<T>>(&body
|
||||||
|
.room_id_or_alias)
|
||||||
|
|
||||||
let limit = body
|
|
||||||
.limit
|
|
||||||
.unwrap_or(UInt::from(10_u32))
|
|
||||||
.min(UInt::from(100_u32));
|
|
||||||
let via = body
|
let via = body
|
||||||
.via
|
.via
|
||||||
.unwrap_or(UInt::from(3_u32))
|
|
||||||
.min(UInt::from(10_u32));
|
|
||||||
|
|
||||||
let key = body
|
//services()
|
||||||
.from
|
// .rooms
|
||||||
.as_ref()
|
// .summary
|
||||||
.and_then(|s| PagnationToken::from_str(s).ok());
|
// .get_room_summary(
|
||||||
|
// &body.room_id_or_alias,
|
||||||
|
// &body.via,
|
||||||
|
// )
|
||||||
|
|
||||||
// Should prevent unexpected behaviour in (bad) clients
|
|
||||||
if let Some(token) = &key {
|
|
||||||
if token.suggested_only != body.suggested_only || token.max_depth != max_depth {
|
|
||||||
return Err(Error::BadRequest(
|
|
||||||
ErrorKind::InvalidParam,
|
|
||||||
"suggested_only and max_depth cannot change on paginated requests",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
services()
|
|
||||||
.rooms
|
|
||||||
.spaces
|
|
||||||
.get_client_hierarchy(
|
|
||||||
sender_user,
|
|
||||||
&body.room_id,
|
|
||||||
usize::try_from(limit)
|
|
||||||
.map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Limit is too great"))?,
|
|
||||||
key.map_or(vec![], |token| token.short_room_ids),
|
|
||||||
usize::try_from(max_depth).map_err(|_| {
|
|
||||||
Error::BadRequest(ErrorKind::InvalidParam, "Max depth is too great")
|
|
||||||
})?,
|
|
||||||
body.suggested_only,
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -456,7 +456,7 @@ fn routes(config: &Config) -> Router {
|
|||||||
.ruma_route(client_server::get_relating_events_with_rel_type_and_event_type_route)
|
.ruma_route(client_server::get_relating_events_with_rel_type_and_event_type_route)
|
||||||
.ruma_route(client_server::get_relating_events_with_rel_type_route)
|
.ruma_route(client_server::get_relating_events_with_rel_type_route)
|
||||||
.ruma_route(client_server::get_relating_events_route)
|
.ruma_route(client_server::get_relating_events_route)
|
||||||
#cfg[(feature = "msc3266")]
|
#[cfg(feature = "unstable-msc3266")]
|
||||||
.ruma_route(client_server::get_room_summary_route)
|
.ruma_route(client_server::get_room_summary_route)
|
||||||
.ruma_route(client_server::get_hierarchy_route)
|
.ruma_route(client_server::get_hierarchy_route)
|
||||||
.ruma_route(client_server::well_known_client)
|
.ruma_route(client_server::well_known_client)
|
||||||
@@ -507,7 +507,7 @@ fn routes(config: &Config) -> Router {
|
|||||||
.ruma_route(server_server::get_keys_route)
|
.ruma_route(server_server::get_keys_route)
|
||||||
.ruma_route(server_server::claim_keys_route)
|
.ruma_route(server_server::claim_keys_route)
|
||||||
.ruma_route(server_server::get_openid_userinfo_route)
|
.ruma_route(server_server::get_openid_userinfo_route)
|
||||||
#cfg[(feature = "msc3266")]
|
#[cfg(feature = "unstable-msc3266")]
|
||||||
.ruma_route(client_server::get_room_summary_route)
|
.ruma_route(client_server::get_room_summary_route)
|
||||||
.ruma_route(server_server::get_hierarchy_route)
|
.ruma_route(server_server::get_hierarchy_route)
|
||||||
.ruma_route(server_server::well_known_server)
|
.ruma_route(server_server::well_known_server)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ pub mod pdu_metadata;
|
|||||||
pub mod search;
|
pub mod search;
|
||||||
pub mod short;
|
pub mod short;
|
||||||
pub mod spaces;
|
pub mod spaces;
|
||||||
#cfg[(feature = "msc3266")]
|
#[cfg(feature = "unstable-msc3266")]
|
||||||
pub mod summary;
|
pub mod summary;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
pub mod state_accessor;
|
pub mod state_accessor;
|
||||||
|
|||||||
@@ -14,9 +14,10 @@ use ruma::{
|
|||||||
client::{
|
client::{
|
||||||
self,
|
self,
|
||||||
error::ErrorKind,
|
error::ErrorKind,
|
||||||
room::summary::get_summary
|
room::get_summary,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
directory::PublicRoomJoinRule,
|
||||||
events::{
|
events::{
|
||||||
room::{
|
room::{
|
||||||
avatar::RoomAvatarEventContent,
|
avatar::RoomAvatarEventContent,
|
||||||
@@ -39,13 +40,10 @@ use crate::{services, Error, Result};
|
|||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub struct SummaryRequest {
|
pub struct SummaryRequest {
|
||||||
/// The Alias or ID of the room to be summarized.
|
/// The Alias or ID of the room to be summarized.
|
||||||
#[ruma_api(path)]
|
|
||||||
pub room_id_or_alias: Vec<OwnedRoomOrAliasId>,
|
pub room_id_or_alias: Vec<OwnedRoomOrAliasId>,
|
||||||
/// A list of servers the homeserver should attempt to use to peek at the room.
|
/// A list of servers the homeserver should attempt to use to peek at the room.
|
||||||
///
|
///
|
||||||
/// Defaults to an empty `Vec`.
|
/// Defaults to an empty `Vec`.
|
||||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
|
||||||
#[ruma_api(query)]
|
|
||||||
pub via: Vec<OwnedServerName>,
|
pub via: Vec<OwnedServerName>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,23 +52,38 @@ impl Display for SummaryRequest {
|
|||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{}_{}",
|
"{}_{}",
|
||||||
self.room_id_or_alias
|
self.room_id_or_alias,
|
||||||
|
self.via
|
||||||
.iter()
|
.iter()
|
||||||
.map(|b| b.to_string())
|
.map(|b| b.to_string())
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(","),
|
.join(","),
|
||||||
self.via
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//impl Service {
|
/// Identifier used to check if rooms are accessible
|
||||||
//}
|
///
|
||||||
|
/// None is used if you want to return the room, no matter if accessible or not
|
||||||
|
pub enum Identifier<'a> {
|
||||||
|
UserId(&'a UserId),
|
||||||
|
ServerName(&'a ServerName),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Service {
|
||||||
|
///Gets the response for the room summary request
|
||||||
|
pub async fn get_room_summary_route(
|
||||||
|
&self,
|
||||||
|
room_id_or_alias: &OwnedRoomOrAliasId,
|
||||||
|
via: &Vec<OwnedServerName>,
|
||||||
|
) -> Result<client::room::get_summary::msc3266::Response> {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// With the given identifier, checks if a room is accessible
|
/// With the given identifier, checks if a room is accessible
|
||||||
fn is_accessible(
|
fn is_accessible(
|
||||||
current_room: &OwnedRoomId,
|
current_room: &OwnedRoomId,
|
||||||
join_rule: &RoomJoinRule,
|
join_rule: &JoinRule,
|
||||||
identifier: &Identifier<'_>,
|
identifier: &Identifier<'_>,
|
||||||
allowed_room_ids: &Vec<OwnedRoomId>,
|
allowed_room_ids: &Vec<OwnedRoomId>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
@@ -106,38 +119,8 @@ fn is_accessible(
|
|||||||
}
|
}
|
||||||
} // Takes care of join rules
|
} // Takes care of join rules
|
||||||
match join_rule {
|
match join_rule {
|
||||||
PublicRoomJoinRule::Restricted => {
|
PublicRoomJoinRule::Public
|
||||||
SpaceRoomJoinRule::Restricted => {
|
| PublicRoomJoinRule::Knock => true,
|
||||||
for room in allowed_room_ids {
|
|
||||||
match identifier {
|
|
||||||
Identifier::UserId(user) => {
|
|
||||||
if services()
|
|
||||||
.rooms
|
|
||||||
.state_cache
|
|
||||||
.is_joined(user, room)
|
|
||||||
.unwrap_or_default()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Identifier::ServerName(server) => {
|
|
||||||
if services()
|
|
||||||
.rooms
|
|
||||||
.state_cache
|
|
||||||
.server_in_room(server, room)
|
|
||||||
.unwrap_or_default()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
SpaceRoomJoinRule::Public
|
|
||||||
| SpaceRoomJoinRule::Knock
|
|
||||||
| SpaceRoomJoinRule::KnockRestricted => true,
|
|
||||||
SpaceRoomJoinRule::Invite | SpaceRoomJoinRule::Private => false,
|
|
||||||
// Custom join rule
|
// Custom join rule
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
@@ -158,7 +141,6 @@ mod tests {
|
|||||||
.as_str(),
|
.as_str(),
|
||||||
"#conduit:example.com"
|
"#conduit:example.com"
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -169,7 +151,6 @@ mod tests {
|
|||||||
.as_str(),
|
.as_str(),
|
||||||
"!29fhd83h92h0:example.com"
|
"!29fhd83h92h0:example.com"
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -190,6 +171,7 @@ mod tests {
|
|||||||
SummaryRequest.try_from(),
|
SummaryRequest.try_from(),
|
||||||
"!29fhd83h92h0:example.com_matrix.org,my_homeserver.org"
|
"!29fhd83h92h0:example.com_matrix.org,my_homeserver.org"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
fn valid_room_summary_for_room_alias() {
|
fn valid_room_summary_for_room_alias() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|||||||
Reference in New Issue
Block a user