Skip to content

Commit

Permalink
feat: retrieving profiles and updating profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
avdb13 committed Apr 16, 2024
1 parent 32b7de2 commit 535055b
Show file tree
Hide file tree
Showing 43 changed files with 411 additions and 1,503 deletions.
Empty file.
12 changes: 9 additions & 3 deletions crates/core/src/membership/join.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
use matrix::{
client::membership::join::{Request, Response},
ruma_common::OwnedRoomOrAliasId,
ruma_common::OwnedRoomId,
};

use crate::{commune, error::Error};
use crate::{commune, error::Error, util::opaque_id::OpaqueId};

pub async fn service(
access_token: impl AsRef<str>,
room_id: impl Into<OwnedRoomOrAliasId>,
space_id: impl Into<OpaqueId>,
reason: Option<String>,
) -> Result<Response, Error> {
let server_name = &commune().config.matrix.server_name;

let space_id = space_id.into();
let room_id = OwnedRoomId::try_from(format!("!{space_id}:{server_name}"))
.expect("Parsing space identifier should never panic");

let req = Request::new(room_id.into(), reason);

commune()
Expand Down
Empty file.
20 changes: 18 additions & 2 deletions crates/core/src/profile.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
pub mod avatar;
pub mod display_name;
pub mod avatar_url;
pub mod displayname;

use matrix::{
client::profile::{Request, Response},
ruma_common::OwnedUserId,
};

use crate::{commune, error::Error};

pub async fn service(user_id: impl Into<OwnedUserId>) -> Result<Response, Error> {
let req = Request::new(user_id.into());

commune()
.send_matrix_request(req, None)
.await
.map_err(Into::into)
}
41 changes: 0 additions & 41 deletions crates/core/src/profile/avatar.rs

This file was deleted.

27 changes: 27 additions & 0 deletions crates/core/src/profile/avatar_url.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use matrix::{
client::{
account::whoami,
profile::avatar_url::{Request, Response},
},
ruma_common::OwnedMxcUri,
};

use crate::{commune, error::Error};

pub async fn service(
access_token: impl AsRef<str>,
avatar_url: impl Into<OwnedMxcUri>,
) -> Result<Response, Error> {
let req = whoami::Request::new();

let whoami::Response { user_id, .. } = commune()
.send_matrix_request(req, Some(access_token.as_ref()))
.await?;

let req = Request::new(user_id, avatar_url.into());

commune()
.send_matrix_request(req, Some(access_token.as_ref()))
.await
.map_err(Into::into)
}
38 changes: 0 additions & 38 deletions crates/core/src/profile/display_name.rs

This file was deleted.

24 changes: 24 additions & 0 deletions crates/core/src/profile/displayname.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use matrix::client::{
account::whoami,
profile::displayname::{Request, Response},
};

use crate::{commune, error::Error};

pub async fn service(
access_token: impl AsRef<str>,
displayname: impl Into<String>,
) -> Result<Response, Error> {
let req = whoami::Request::new();

let whoami::Response { user_id, .. } = commune()
.send_matrix_request(req, Some(access_token.as_ref()))
.await?;

let req = Request::new(user_id, displayname.into());

commune()
.send_matrix_request(req, Some(access_token.as_ref()))
.await
.map_err(Into::into)
}
3 changes: 1 addition & 2 deletions crates/core/src/spaces/channels/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ pub async fn service(
topic: Option<String>,
) -> Result<Response, Error> {
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");
.expect("Parsing space identifier should never panic");

let req = Request::new(
Some(RoomCreationContent {
Expand Down
3 changes: 0 additions & 3 deletions crates/matrix/src/client-backup/account.rs.bk.bk

This file was deleted.

Loading

0 comments on commit 535055b

Please sign in to comment.