-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feate: implemented space child creation
- Loading branch information
Showing
13 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ pub mod util; | |
pub mod account; | ||
pub mod profile; | ||
pub mod spaces; | ||
pub mod rooms; | ||
|
||
use std::sync::RwLock; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod create; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use matrix::{ | ||
client::create_room::{Request, Response, RoomCreationContent, RoomVisibility}, | ||
ruma_common::{room::RoomType, OwnedRoomOrAliasId, RoomVersionId}, | ||
ruma_events::{ | ||
room::power_levels::RoomPowerLevelsEventContent, | ||
space::parent::{InitialSpaceParentEvent, SpaceParentEventContent}, | ||
}, | ||
}; | ||
|
||
use crate::{commune, error::Result}; | ||
|
||
pub async fn service( | ||
access_token: impl AsRef<str>, | ||
parent: OwnedRoomOrAliasId, | ||
alias: Option<String>, | ||
name: Option<String>, | ||
topic: Option<String>, | ||
) -> Result<Response> { | ||
let creation_content = Some(RoomCreationContent { | ||
kind: None, | ||
federate: true, | ||
room_version: RoomVersionId::V11, | ||
predecessor: None, | ||
}); | ||
|
||
let req = Request::new( | ||
creation_content, | ||
Vec::new(), | ||
Vec::new(), | ||
false, | ||
name, | ||
None, | ||
alias, | ||
topic, | ||
RoomVisibility::Public, | ||
); | ||
|
||
let resp = commune() | ||
.send_matrix_request(req, Some(access_token.as_ref())) | ||
.await?; | ||
|
||
let mut content = | ||
SpaceParentEventContent::new(vec![commune().config.matrix.server_name.clone()]); | ||
content.canonical = true; | ||
|
||
let state_event = InitialSpaceParentEvent { | ||
content, | ||
state_key: resp.room_id.clone(), | ||
}; | ||
|
||
Ok(resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod state; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use ruma_common::{ | ||
api::{request, response, Metadata}, | ||
metadata, | ||
}; | ||
|
||
#[allow(dead_code)] | ||
const METADATA: Metadata = metadata! { | ||
method: POST, | ||
rate_limited: false, | ||
authentication: AccessToken, | ||
history: { | ||
unstable => "/_matrix/client/v3/logout", | ||
} | ||
}; | ||
|
||
#[request(error = crate::Error)] | ||
pub struct Request {} | ||
|
||
#[allow(clippy::new_without_default)] | ||
impl Request { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
#[response(error = crate::Error)] | ||
pub struct Response {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ pub mod account; | |
pub mod relative; | ||
pub mod register; | ||
pub mod spaces; | ||
pub mod rooms; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod root; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use axum::{ | ||
response::{IntoResponse, Response}, | ||
Json, | ||
}; | ||
use axum_extra::{ | ||
headers::{authorization::Bearer, Authorization}, | ||
TypedHeader, | ||
}; | ||
use matrix::ruma_common::OwnedRoomOrAliasId; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Payload { | ||
pub alias: Option<String>, | ||
pub name: Option<String>, | ||
pub topic: Option<String>, | ||
pub parent: OwnedRoomOrAliasId, | ||
} | ||
|
||
pub async fn handler( | ||
TypedHeader(access_token): TypedHeader<Authorization<Bearer>>, | ||
Json(payload): Json<Payload>, | ||
) -> Response { | ||
use commune::rooms::create::service; | ||
|
||
match service( | ||
access_token.token(), | ||
payload.alias, | ||
payload.name, | ||
payload.topic, | ||
) | ||
.await | ||
{ | ||
Ok(resp) => Json(resp).into_response(), | ||
Err(e) => { | ||
tracing::warn!(?e, "failed to create space"); | ||
|
||
e.into_response() | ||
} | ||
} | ||
} |
Empty file.