refactor: Fix errors in api/client/read_marker.rs

This commit is contained in:
Ginger
2026-04-11 14:21:10 -04:00
parent 154cda35f3
commit 256f8f679d
+21 -31
View File
@@ -8,7 +8,8 @@ use ruma::{
api::client::{read_marker::set_read_marker, receipt::create_receipt}, api::client::{read_marker::set_read_marker, receipt::create_receipt},
events::{ events::{
RoomAccountDataEventType, RoomAccountDataEventType,
receipt::{ReceiptThread, ReceiptType}, fully_read::{FullyReadEvent, FullyReadEventContent},
receipt::{Receipt, ReceiptEvent, ReceiptEventContent, ReceiptType},
}, },
}; };
@@ -28,9 +29,7 @@ pub(crate) async fn set_read_marker_route(
let sender_user = body.sender_user(); let sender_user = body.sender_user();
if let Some(event) = &body.fully_read { if let Some(event) = &body.fully_read {
let fully_read_event = ruma::events::fully_read::FullyReadEvent { let fully_read_event = FullyReadEvent::new(FullyReadEventContent::new(event.to_owned()));
content: ruma::events::fully_read::FullyReadEventContent { event_id: event.clone() },
};
services services
.account_data .account_data
@@ -62,19 +61,16 @@ pub(crate) async fn set_read_marker_route(
if services.config.allow_local_read_receipts if services.config.allow_local_read_receipts
&& !services.users.is_suspended(sender_user).await? && !services.users.is_suspended(sender_user).await?
{ {
let receipt_content = BTreeMap::from_iter([( let receipt_content = [(
event.to_owned(), event.to_owned(),
BTreeMap::from_iter([( BTreeMap::from_iter([(
ReceiptType::Read, ReceiptType::Read,
BTreeMap::from_iter([( BTreeMap::from_iter([(
sender_user.to_owned(), sender_user.to_owned(),
ruma::events::receipt::Receipt { Receipt::new(MilliSecondsSinceUnixEpoch::now()),
ts: Some(MilliSecondsSinceUnixEpoch::now()),
thread: ReceiptThread::Unthreaded,
},
)]), )]),
)]), )]),
)]); )];
services services
.rooms .rooms
@@ -82,10 +78,10 @@ pub(crate) async fn set_read_marker_route(
.readreceipt_update( .readreceipt_update(
sender_user, sender_user,
&body.room_id, &body.room_id,
&ruma::events::receipt::ReceiptEvent { &ReceiptEvent::new(
content: ruma::events::receipt::ReceiptEventContent(receipt_content), body.room_id.clone(),
room_id: body.room_id.clone(), ReceiptEventContent::from_iter(receipt_content),
}, ),
) )
.await; .await;
} }
@@ -111,7 +107,7 @@ pub(crate) async fn set_read_marker_route(
.private_read_set(&body.room_id, sender_user, count); .private_read_set(&body.room_id, sender_user, count);
} }
Ok(set_read_marker::v3::Response {}) Ok(set_read_marker::v3::Response::new())
} }
/// # `POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}` /// # `POST /_matrix/client/r0/rooms/{roomId}/receipt/{receiptType}/{eventId}`
@@ -148,11 +144,8 @@ pub(crate) async fn create_receipt_route(
match body.receipt_type { match body.receipt_type {
| create_receipt::v3::ReceiptType::FullyRead => { | create_receipt::v3::ReceiptType::FullyRead => {
let fully_read_event = ruma::events::fully_read::FullyReadEvent { let fully_read_event =
content: ruma::events::fully_read::FullyReadEventContent { FullyReadEvent::new(FullyReadEventContent::new(body.event_id.clone()));
event_id: body.event_id.clone(),
},
};
services services
.account_data .account_data
.update( .update(
@@ -164,19 +157,16 @@ pub(crate) async fn create_receipt_route(
.await?; .await?;
}, },
| create_receipt::v3::ReceiptType::Read => { | create_receipt::v3::ReceiptType::Read => {
let receipt_content = BTreeMap::from_iter([( let receipt_content = [(
body.event_id.clone(), body.event_id.clone(),
BTreeMap::from_iter([( BTreeMap::from_iter([(
ReceiptType::Read, ReceiptType::Read,
BTreeMap::from_iter([( BTreeMap::from_iter([(
sender_user.to_owned(), sender_user.to_owned(),
ruma::events::receipt::Receipt { Receipt::new(MilliSecondsSinceUnixEpoch::now()),
ts: Some(MilliSecondsSinceUnixEpoch::now()),
thread: ReceiptThread::Unthreaded,
},
)]), )]),
)]), )]),
)]); )];
services services
.rooms .rooms
@@ -184,10 +174,10 @@ pub(crate) async fn create_receipt_route(
.readreceipt_update( .readreceipt_update(
sender_user, sender_user,
&body.room_id, &body.room_id,
&ruma::events::receipt::ReceiptEvent { &ReceiptEvent::new(
content: ruma::events::receipt::ReceiptEventContent(receipt_content), body.room_id.clone(),
room_id: body.room_id.clone(), ReceiptEventContent::from_iter(receipt_content),
}, ),
) )
.await; .await;
}, },
@@ -218,5 +208,5 @@ pub(crate) async fn create_receipt_route(
}, },
} }
Ok(create_receipt::v3::Response {}) Ok(create_receipt::v3::Response::new())
} }