apply new rustfmt.toml changes, fix some clippy lints
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
0317cc8cc5
commit
77e0b76408
296 changed files with 7147 additions and 4300 deletions
|
@ -2,11 +2,12 @@ use axum::extract::State;
|
|||
use conduwuit::{err, Err};
|
||||
use ruma::{
|
||||
api::client::config::{
|
||||
get_global_account_data, get_room_account_data, set_global_account_data, set_room_account_data,
|
||||
get_global_account_data, get_room_account_data, set_global_account_data,
|
||||
set_room_account_data,
|
||||
},
|
||||
events::{
|
||||
AnyGlobalAccountDataEventContent, AnyRoomAccountDataEventContent, GlobalAccountDataEventType,
|
||||
RoomAccountDataEventType,
|
||||
AnyGlobalAccountDataEventContent, AnyRoomAccountDataEventContent,
|
||||
GlobalAccountDataEventType, RoomAccountDataEventType,
|
||||
},
|
||||
serde::Raw,
|
||||
RoomId, UserId,
|
||||
|
@ -20,7 +21,8 @@ use crate::{service::Services, Result, Ruma};
|
|||
///
|
||||
/// Sets some account data for the sender user.
|
||||
pub(crate) async fn set_global_account_data_route(
|
||||
State(services): State<crate::State>, body: Ruma<set_global_account_data::v3::Request>,
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<set_global_account_data::v3::Request>,
|
||||
) -> Result<set_global_account_data::v3::Response> {
|
||||
let sender_user = body.sender_user();
|
||||
|
||||
|
@ -28,7 +30,14 @@ pub(crate) async fn set_global_account_data_route(
|
|||
return Err!(Request(Forbidden("You cannot set account data for other users.")));
|
||||
}
|
||||
|
||||
set_account_data(&services, None, &body.user_id, &body.event_type.to_string(), body.data.json()).await?;
|
||||
set_account_data(
|
||||
&services,
|
||||
None,
|
||||
&body.user_id,
|
||||
&body.event_type.to_string(),
|
||||
body.data.json(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(set_global_account_data::v3::Response {})
|
||||
}
|
||||
|
@ -37,7 +46,8 @@ pub(crate) async fn set_global_account_data_route(
|
|||
///
|
||||
/// Sets some room account data for the sender user.
|
||||
pub(crate) async fn set_room_account_data_route(
|
||||
State(services): State<crate::State>, body: Ruma<set_room_account_data::v3::Request>,
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<set_room_account_data::v3::Request>,
|
||||
) -> Result<set_room_account_data::v3::Response> {
|
||||
let sender_user = body.sender_user();
|
||||
|
||||
|
@ -61,7 +71,8 @@ pub(crate) async fn set_room_account_data_route(
|
|||
///
|
||||
/// Gets some account data for the sender user.
|
||||
pub(crate) async fn get_global_account_data_route(
|
||||
State(services): State<crate::State>, body: Ruma<get_global_account_data::v3::Request>,
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_global_account_data::v3::Request>,
|
||||
) -> Result<get_global_account_data::v3::Response> {
|
||||
let sender_user = body.sender_user();
|
||||
|
||||
|
@ -75,16 +86,15 @@ pub(crate) async fn get_global_account_data_route(
|
|||
.await
|
||||
.map_err(|_| err!(Request(NotFound("Data not found."))))?;
|
||||
|
||||
Ok(get_global_account_data::v3::Response {
|
||||
account_data: account_data.content,
|
||||
})
|
||||
Ok(get_global_account_data::v3::Response { account_data: account_data.content })
|
||||
}
|
||||
|
||||
/// # `GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
|
||||
///
|
||||
/// Gets some room account data for the sender user.
|
||||
pub(crate) async fn get_room_account_data_route(
|
||||
State(services): State<crate::State>, body: Ruma<get_room_account_data::v3::Request>,
|
||||
State(services): State<crate::State>,
|
||||
body: Ruma<get_room_account_data::v3::Request>,
|
||||
) -> Result<get_room_account_data::v3::Response> {
|
||||
let sender_user = body.sender_user();
|
||||
|
||||
|
@ -98,17 +108,20 @@ pub(crate) async fn get_room_account_data_route(
|
|||
.await
|
||||
.map_err(|_| err!(Request(NotFound("Data not found."))))?;
|
||||
|
||||
Ok(get_room_account_data::v3::Response {
|
||||
account_data: account_data.content,
|
||||
})
|
||||
Ok(get_room_account_data::v3::Response { account_data: account_data.content })
|
||||
}
|
||||
|
||||
async fn set_account_data(
|
||||
services: &Services, room_id: Option<&RoomId>, sender_user: &UserId, event_type_s: &str, data: &RawJsonValue,
|
||||
services: &Services,
|
||||
room_id: Option<&RoomId>,
|
||||
sender_user: &UserId,
|
||||
event_type_s: &str,
|
||||
data: &RawJsonValue,
|
||||
) -> Result {
|
||||
if event_type_s == RoomAccountDataEventType::FullyRead.to_cow_str() {
|
||||
return Err!(Request(BadJson(
|
||||
"This endpoint cannot be used for marking a room as fully read (setting m.fully_read)"
|
||||
"This endpoint cannot be used for marking a room as fully read (setting \
|
||||
m.fully_read)"
|
||||
)));
|
||||
}
|
||||
|
||||
|
@ -118,8 +131,8 @@ async fn set_account_data(
|
|||
)));
|
||||
}
|
||||
|
||||
let data: serde_json::Value =
|
||||
serde_json::from_str(data.get()).map_err(|e| err!(Request(BadJson(warn!("Invalid JSON provided: {e}")))))?;
|
||||
let data: serde_json::Value = serde_json::from_str(data.get())
|
||||
.map_err(|e| err!(Request(BadJson(warn!("Invalid JSON provided: {e}")))))?;
|
||||
|
||||
services
|
||||
.account_data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue