Skip to main content

tuwunel_api/client/account_data/
set_room_account_data.rs

1use axum::extract::State;
2use ruma::api::client::config::set_room_account_data;
3use tuwunel_core::Result;
4
5use super::{assert_account_data_owner, set_account_data};
6use crate::Ruma;
7
8/// # `PUT /_matrix/client/r0/user/{userId}/rooms/{roomId}/account_data/{type}`
9///
10/// Sets some room account data for the sender user.
11pub(crate) async fn set_room_account_data_route(
12	State(services): State<crate::State>,
13	body: Ruma<set_room_account_data::v3::Request>,
14) -> Result<set_room_account_data::v3::Response> {
15	let sender_user = body.sender_user();
16
17	assert_account_data_owner(
18		sender_user,
19		&body.user_id,
20		body.appservice_info.as_ref(),
21		"You cannot set account data for other users.",
22	)?;
23
24	set_account_data(
25		&services,
26		Some(&body.room_id),
27		&body.user_id,
28		&body.event_type.to_string(),
29		body.data.json(),
30	)
31	.await?;
32
33	Ok(set_room_account_data::v3::Response {})
34}