-
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.
- Loading branch information
Showing
57 changed files
with
687 additions
and
101 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
//! This library deals with personal messages, enabling `m.direct` on all rooms created through | ||
//! this endpoint. The name `direct` was chosen to avoid confusion with regular Matrix rooms. | ||
|
||
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,37 @@ | ||
use matrix::{ | ||
client::create_room::{Request, Response, RoomCreationContent, RoomVisibility}, | ||
ruma_common::{OwnedUserId, RoomVersionId}, | ||
}; | ||
|
||
use crate::{commune, error::Result}; | ||
|
||
pub async fn service( | ||
access_token: impl AsRef<str>, | ||
name: Option<String>, | ||
topic: Option<String>, | ||
invite: Vec<OwnedUserId>, | ||
) -> 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(), | ||
invite, | ||
true, | ||
name, | ||
None, | ||
None, | ||
topic, | ||
RoomVisibility::Private, | ||
); | ||
|
||
commune() | ||
.send_matrix_request(req, Some(access_token.as_ref())) | ||
.await | ||
.map_err(Into::into) | ||
} |
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,22 @@ | ||
use matrix::{ | ||
client::directory::room::Request, | ||
ruma_common::{OwnedRoomId, OwnedRoomOrAliasId}, | ||
}; | ||
|
||
use crate::{commune, error::Error}; | ||
|
||
pub async fn get_room_id( | ||
room_or_alias_id: impl Into<OwnedRoomOrAliasId>, | ||
) -> Result<OwnedRoomId, Error> { | ||
// this cannot error, `Result<T>` is just provided in place of an enum | ||
// https://github.com/ruma/ruma/issues/1761 | ||
|
||
match room_or_alias_id.into().try_into() { | ||
Ok(room_id) => Ok(room_id), | ||
Err(room_alias) => commune() | ||
.send_matrix_request(Request::new(room_alias), None) | ||
.await | ||
.map(|resp| resp.room_id) | ||
.map_err(Into::into), | ||
} | ||
} |
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,2 @@ | ||
pub mod join; | ||
pub mod leave; |
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,19 @@ | ||
use matrix::{ | ||
client::membership::join::{Request, Response}, | ||
ruma_common::OwnedRoomOrAliasId, | ||
}; | ||
|
||
use crate::{commune, error::Result}; | ||
|
||
pub async fn service( | ||
access_token: impl AsRef<str>, | ||
room_id: impl Into<OwnedRoomOrAliasId>, | ||
reason: Option<String>, | ||
) -> Result<Response> { | ||
let req = Request::new(room_id.into(), reason); | ||
|
||
commune() | ||
.send_matrix_request(req, Some(access_token.as_ref())) | ||
.await | ||
.map_err(Into::into) | ||
} |
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,38 @@ | ||
use matrix::{ | ||
client::{ | ||
self, | ||
membership::leave::{Request, Response}, | ||
}, | ||
ruma_common::OwnedRoomOrAliasId, | ||
}; | ||
|
||
use crate::{commune, error::Result}; | ||
|
||
pub async fn service( | ||
access_token: impl AsRef<str>, | ||
room_or_alias_id: impl Into<OwnedRoomOrAliasId>, | ||
reason: Option<String>, | ||
) -> Result<Response> { | ||
let room_or_alias_id: OwnedRoomOrAliasId = room_or_alias_id.into(); | ||
|
||
// this cannot error, `Result<T>` is just provided in place of an enum | ||
// https://github.com/ruma/ruma/issues/1761 | ||
let room_id = match room_or_alias_id.try_into() { | ||
Ok(room_id) => room_id, | ||
Err(room_alias) => { | ||
let req = client::directory::room::Request::new(room_alias); | ||
|
||
commune() | ||
.send_matrix_request(req, None) | ||
.await | ||
.map(|resp| resp.room_id)? | ||
} | ||
}; | ||
|
||
let req = Request::new(room_id, reason); | ||
|
||
commune() | ||
.send_matrix_request(req, Some(access_token.as_ref())) | ||
.await | ||
.map_err(Into::into) | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod create; | ||
pub mod channels; |
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,76 @@ | ||
use matrix::{ | ||
client::{ | ||
create_room::{Request, Response, RoomCreationContent, RoomVisibility}, | ||
rooms, | ||
}, | ||
ruma_common::{OwnedRoomId, RoomVersionId}, | ||
ruma_events::{ | ||
space::{child::SpaceChildEventContent, parent::SpaceParentEventContent}, | ||
EventContent, | ||
}, | ||
}; | ||
|
||
use crate::{commune, error::Result, util::opaque_id::OpaqueId}; | ||
|
||
pub async fn service( | ||
access_token: impl AsRef<str>, | ||
space_id: OpaqueId, | ||
name: Option<String>, | ||
topic: Option<String>, | ||
) -> Result<Response> { | ||
let server_name = &commune().config.matrix.server_name; | ||
// this should never panic | ||
let space_id = OwnedRoomId::try_from(format!("!{space_id}:{server_name}")) | ||
.expect("failed to parse room ID"); | ||
|
||
let req = Request::new( | ||
Some(RoomCreationContent { | ||
kind: None, | ||
federate: true, | ||
room_version: RoomVersionId::V11, | ||
predecessor: None, | ||
}), | ||
Vec::new(), | ||
Vec::new(), | ||
false, | ||
name, | ||
None, | ||
None, | ||
topic, | ||
RoomVisibility::Public, | ||
); | ||
|
||
let resp = commune() | ||
.send_matrix_request(req, Some(access_token.as_ref())) | ||
.await?; | ||
|
||
let mut parent_content = SpaceParentEventContent::new(vec![server_name.to_owned()]); | ||
parent_content.canonical = true; | ||
|
||
let req = rooms::state::create::Request::new( | ||
parent_content.event_type(), | ||
resp.room_id.clone(), | ||
Some(resp.room_id.to_string()), | ||
parent_content, | ||
)?; | ||
|
||
commune() | ||
.send_matrix_request(req, Some(access_token.as_ref())) | ||
.await?; | ||
|
||
let mut child_content = SpaceChildEventContent::new(vec![server_name.to_owned()]); | ||
child_content.suggested = true; | ||
|
||
let req = rooms::state::create::Request::new( | ||
child_content.event_type(), | ||
space_id.clone(), | ||
Some(space_id.to_string()), | ||
child_content, | ||
)?; | ||
|
||
commune() | ||
.send_matrix_request(req, Some(access_token.as_ref())) | ||
.await?; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod secret; | ||
pub mod opaque_id; |
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,34 @@ | ||
use std::{fmt::Display, str::FromStr}; | ||
|
||
use matrix::ruma_identifiers_validation::Error; | ||
use serde::{de, Deserialize, Deserializer}; | ||
|
||
// helper type to validate the opaque part of a room ID separately. | ||
pub struct OpaqueId(String); | ||
|
||
impl Display for OpaqueId { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.write_str(self.0.as_str()) | ||
} | ||
} | ||
|
||
impl FromStr for OpaqueId { | ||
type Err = Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
match s.chars().all(char::is_alphanumeric) { | ||
true => Ok(OpaqueId(s.to_owned())), | ||
false => Err(Error::InvalidCharacters), | ||
} | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for OpaqueId { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let s = String::deserialize(deserializer)?; | ||
s.parse().map_err(de::Error::custom) | ||
} | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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 get; |
File renamed without changes.
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 get; |
File renamed without changes.
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
Oops, something went wrong.