feat: Add config option for disabling sending public read receipts

Treats requests like private receipts
This commit is contained in:
Nyaaori 2022-11-26 14:53:57 +01:00
parent 04e5927e46
commit 96c2cb9469
No known key found for this signature in database
GPG key ID: E7819C3ED4D1F82E
3 changed files with 50 additions and 42 deletions

View file

@ -61,30 +61,31 @@ pub async fn set_read_marker_route(
"Event does not exist.", "Event does not exist.",
))?; ))?;
let mut user_receipts = BTreeMap::new(); if services().globals.allow_public_read_receipts() {
user_receipts.insert( let mut user_receipts = BTreeMap::new();
sender_user.clone(), user_receipts.insert(
ruma::events::receipt::Receipt { sender_user.clone(),
ts: Some(MilliSecondsSinceUnixEpoch::now()), ruma::events::receipt::Receipt {
thread: ReceiptThread::Unthreaded, ts: Some(MilliSecondsSinceUnixEpoch::now()),
}, thread: ReceiptThread::Unthreaded,
); },
);
let mut receipts = BTreeMap::new(); let mut receipts = BTreeMap::new();
receipts.insert(ReceiptType::Read, user_receipts); receipts.insert(ReceiptType::Read, user_receipts);
let mut receipt_content = BTreeMap::new(); let mut receipt_content = BTreeMap::new();
receipt_content.insert(event.to_owned(), receipts); 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.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( services().rooms.edus.read_receipt.private_read_set(
&body.room_id, &body.room_id,
sender_user, sender_user,
@ -128,29 +129,30 @@ pub async fn create_receipt_route(
"Event does not exist.", "Event does not exist.",
))?; ))?;
let mut user_receipts = BTreeMap::new(); if services().globals.allow_public_read_receipts() {
user_receipts.insert( let mut user_receipts = BTreeMap::new();
sender_user.clone(), user_receipts.insert(
ruma::events::receipt::Receipt { sender_user.clone(),
ts: Some(MilliSecondsSinceUnixEpoch::now()), ruma::events::receipt::Receipt {
thread: ReceiptThread::Unthreaded, 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(); let mut receipt_content = BTreeMap::new();
receipt_content.insert(body.event_id.to_owned(), receipts); 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.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( services().rooms.edus.read_receipt.private_read_set(
&body.room_id, &body.room_id,
sender_user, sender_user,

View file

@ -47,6 +47,8 @@ pub struct Config {
#[serde(default = "false_fn")] #[serde(default = "false_fn")]
pub allow_federation: bool, pub allow_federation: bool,
#[serde(default = "true_fn")] #[serde(default = "true_fn")]
pub allow_public_read_receipts: bool,
#[serde(default = "true_fn")]
pub allow_room_creation: bool, pub allow_room_creation: bool,
#[serde(default = "true_fn")] #[serde(default = "true_fn")]
pub allow_unstable_room_versions: bool, pub allow_unstable_room_versions: bool,

View file

@ -234,6 +234,10 @@ impl Service {
self.config.allow_federation 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 { pub fn allow_room_creation(&self) -> bool {
self.config.allow_room_creation self.config.allow_room_creation
} }