diff --git a/src/client_server/read_marker.rs b/src/client_server/read_marker.rs
index 0c4ec1a4..f7d3712d 100644
--- a/src/client_server/read_marker.rs
+++ b/src/client_server/read_marker.rs
@@ -2,7 +2,8 @@ use super::State;
use crate::{ConduitResult, Database, Error, Ruma};
use ruma::{
api::client::{
- error::ErrorKind, r0::capabilities::get_capabilities, r0::read_marker::set_read_marker,
+ error::ErrorKind,
+ r0::{read_marker::set_read_marker, receipt::create_receipt},
},
events::{AnyEphemeralRoomEvent, AnyEvent, EventType},
};
@@ -83,13 +84,52 @@ pub async fn set_read_marker_route(
feature = "conduit_bin",
post("/_matrix/client/r0/rooms/<_>/receipt/<_>/<_>", data = "
")
)]
-pub async fn set_receipt_route(
+pub async fn create_receipt_route(
db: State<'_, Database>,
- body: Ruma,
-) -> ConduitResult {
- let _sender_user = body.sender_user.as_ref().expect("user is authenticated");
+ body: Ruma>,
+) -> ConduitResult {
+ let sender_user = body.sender_user.as_ref().expect("user is authenticated");
+
+ db.rooms.edus.private_read_set(
+ &body.room_id,
+ &sender_user,
+ db.rooms
+ .get_pdu_count(&body.event_id)?
+ .ok_or(Error::BadRequest(
+ ErrorKind::InvalidParam,
+ "Event does not exist.",
+ ))?,
+ &db.globals,
+ )?;
+
+ let mut user_receipts = BTreeMap::new();
+ user_receipts.insert(
+ sender_user.clone(),
+ ruma::events::receipt::Receipt {
+ ts: Some(SystemTime::now()),
+ },
+ );
+ let mut receipt_content = BTreeMap::new();
+ receipt_content.insert(
+ body.event_id.to_owned(),
+ ruma::events::receipt::Receipts {
+ read: Some(user_receipts),
+ },
+ );
+
+ db.rooms.edus.readreceipt_update(
+ &sender_user,
+ &body.room_id,
+ AnyEvent::Ephemeral(AnyEphemeralRoomEvent::Receipt(
+ ruma::events::receipt::ReceiptEvent {
+ content: ruma::events::receipt::ReceiptEventContent(receipt_content),
+ room_id: body.room_id.clone(),
+ },
+ )),
+ &db.globals,
+ )?;
db.flush().await?;
- Ok(set_read_marker::Response.into())
+ Ok(create_receipt::Response.into())
}
diff --git a/src/main.rs b/src/main.rs
index 65434a5d..d5f1f4e3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -90,7 +90,7 @@ fn setup_rocket() -> rocket::Rocket {
client_server::get_backup_key_sessions_route,
client_server::get_backup_keys_route,
client_server::set_read_marker_route,
- client_server::set_receipt_route,
+ client_server::create_receipt_route,
client_server::create_typing_event_route,
client_server::create_room_route,
client_server::redact_event_route,