From ccc50308964b4f96ad411a0bab22d2bd9790ff79 Mon Sep 17 00:00:00 2001 From: Nyaaori <+@nyaaori.cat> Date: Sat, 26 Nov 2022 14:53:57 +0100 Subject: [PATCH] feat: Add config option for disabling sending public read receipts Treats requests like private receipts --- src/api/client_server/read_marker.rs | 86 ++++++++++++++-------------- src/config/mod.rs | 2 + src/service/globals/mod.rs | 4 ++ 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/src/api/client_server/read_marker.rs b/src/api/client_server/read_marker.rs index dc6dfe9a..2744f6ac 100644 --- a/src/api/client_server/read_marker.rs +++ b/src/api/client_server/read_marker.rs @@ -61,30 +61,31 @@ pub async fn set_read_marker_route( "Event does not exist.", ))?; - let mut user_receipts = BTreeMap::new(); - user_receipts.insert( - sender_user.clone(), - ruma::events::receipt::Receipt { - ts: Some(MilliSecondsSinceUnixEpoch::now()), - thread: ReceiptThread::Unthreaded, - }, - ); + if services().globals.allow_public_read_receipts() { + let mut user_receipts = BTreeMap::new(); + user_receipts.insert( + sender_user.clone(), + ruma::events::receipt::Receipt { + ts: Some(MilliSecondsSinceUnixEpoch::now()), + thread: ReceiptThread::Unthreaded, + }, + ); - let mut receipts = BTreeMap::new(); - receipts.insert(ReceiptType::Read, user_receipts); + let mut receipts = BTreeMap::new(); + receipts.insert(ReceiptType::Read, user_receipts); - let mut receipt_content = BTreeMap::new(); - receipt_content.insert(event.to_owned(), receipts); - - services().rooms.edus.read_receipt.readreceipt_update( - sender_user, - &body.room_id, - ruma::events::receipt::ReceiptEvent { - content: ruma::events::receipt::ReceiptEventContent(receipt_content), - room_id: body.room_id.clone(), - }, - )?; + let mut receipt_content = BTreeMap::new(); + receipt_content.insert(event.to_owned(), receipts); + services().rooms.edus.read_receipt.readreceipt_update( + sender_user, + &body.room_id, + ruma::events::receipt::ReceiptEvent { + content: ruma::events::receipt::ReceiptEventContent(receipt_content), + room_id: body.room_id.clone(), + }, + )?; + }; services().rooms.edus.read_receipt.private_read_set( &body.room_id, sender_user, @@ -128,29 +129,30 @@ pub async fn create_receipt_route( "Event does not exist.", ))?; - let mut user_receipts = BTreeMap::new(); - user_receipts.insert( - sender_user.clone(), - ruma::events::receipt::Receipt { - ts: Some(MilliSecondsSinceUnixEpoch::now()), - thread: ReceiptThread::Unthreaded, - }, - ); - let mut receipts = BTreeMap::new(); - receipts.insert(ReceiptType::Read, user_receipts); + if services().globals.allow_public_read_receipts() { + let mut user_receipts = BTreeMap::new(); + user_receipts.insert( + sender_user.clone(), + ruma::events::receipt::Receipt { + ts: Some(MilliSecondsSinceUnixEpoch::now()), + thread: ReceiptThread::Unthreaded, + }, + ); + let mut receipts = BTreeMap::new(); + receipts.insert(ReceiptType::Read, user_receipts); - let mut receipt_content = BTreeMap::new(); - receipt_content.insert(body.event_id.to_owned(), receipts); - - services().rooms.edus.read_receipt.readreceipt_update( - sender_user, - &body.room_id, - ruma::events::receipt::ReceiptEvent { - content: ruma::events::receipt::ReceiptEventContent(receipt_content), - room_id: body.room_id.clone(), - }, - )?; + let mut receipt_content = BTreeMap::new(); + receipt_content.insert(body.event_id.to_owned(), receipts); + services().rooms.edus.read_receipt.readreceipt_update( + sender_user, + &body.room_id, + ruma::events::receipt::ReceiptEvent { + content: ruma::events::receipt::ReceiptEventContent(receipt_content), + room_id: body.room_id.clone(), + }, + )?; + }; services().rooms.edus.read_receipt.private_read_set( &body.room_id, sender_user, diff --git a/src/config/mod.rs b/src/config/mod.rs index 8a4b54ea..437513c3 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -47,6 +47,8 @@ pub struct Config { #[serde(default = "false_fn")] pub allow_federation: bool, #[serde(default = "true_fn")] + pub allow_public_read_receipts: bool, + #[serde(default = "true_fn")] pub allow_room_creation: bool, #[serde(default = "true_fn")] pub allow_unstable_room_versions: bool, diff --git a/src/service/globals/mod.rs b/src/service/globals/mod.rs index c0fcb4bd..2d8eb6e0 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -234,6 +234,10 @@ impl Service { self.config.allow_federation } + pub fn allow_public_read_receipts(&self) -> bool { + self.config.allow_public_read_receipts + } + pub fn allow_room_creation(&self) -> bool { self.config.allow_room_creation }