diff --git a/src/api/server_server.rs b/src/api/server_server.rs index b7f88078..e39a6d2d 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -748,43 +748,45 @@ pub async fn send_transaction_message_route( match edu { Edu::Presence(_) => {} Edu::Receipt(receipt) => { - for (room_id, room_updates) in receipt.receipts { - for (user_id, user_updates) in room_updates.read { - if let Some((event_id, _)) = user_updates - .event_ids - .iter() - .filter_map(|id| { + if services().globals.allow_receiving_read_receipts() { + for (room_id, room_updates) in receipt.receipts { + for (user_id, user_updates) in room_updates.read { + if let Some((event_id, _)) = user_updates + .event_ids + .iter() + .filter_map(|id| { + services() + .rooms + .timeline + .get_pdu_count(id) + .ok() + .flatten() + .map(|r| (id, r)) + }) + .max_by_key(|(_, count)| *count) + { + let mut user_receipts = BTreeMap::new(); + user_receipts.insert(user_id.clone(), user_updates.data); + + let mut receipts = BTreeMap::new(); + receipts.insert(ReceiptType::Read, user_receipts); + + let mut receipt_content = BTreeMap::new(); + receipt_content.insert(event_id.to_owned(), receipts); + + let event = ReceiptEvent { + content: ReceiptEventContent(receipt_content), + room_id: room_id.clone(), + }; services() .rooms - .timeline - .get_pdu_count(id) - .ok() - .flatten() - .map(|r| (id, r)) - }) - .max_by_key(|(_, count)| *count) - { - let mut user_receipts = BTreeMap::new(); - user_receipts.insert(user_id.clone(), user_updates.data); - - let mut receipts = BTreeMap::new(); - receipts.insert(ReceiptType::Read, user_receipts); - - let mut receipt_content = BTreeMap::new(); - receipt_content.insert(event_id.to_owned(), receipts); - - let event = ReceiptEvent { - content: ReceiptEventContent(receipt_content), - room_id: room_id.clone(), - }; - services() - .rooms - .edus - .read_receipt - .readreceipt_update(&user_id, &room_id, event)?; - } else { - // TODO fetch missing events - info!("No known event ids in read receipt: {:?}", user_updates); + .edus + .read_receipt + .readreceipt_update(&user_id, &room_id, event)?; + } else { + // TODO fetch missing events + info!("No known event ids in read receipt: {:?}", user_updates); + } } } } diff --git a/src/config/mod.rs b/src/config/mod.rs index 10018451..64744428 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -49,6 +49,8 @@ pub struct Config { #[serde(default = "true_fn")] pub allow_public_read_receipts: bool, #[serde(default = "true_fn")] + pub allow_receiving_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 b9087626..d1f95ded 100644 --- a/src/service/globals/mod.rs +++ b/src/service/globals/mod.rs @@ -238,6 +238,10 @@ impl Service { self.config.allow_public_read_receipts } + pub fn allow_receiving_read_receipts(&self) -> bool { + self.config.allow_receiving_read_receipts + } + pub fn allow_room_creation(&self) -> bool { self.config.allow_room_creation }