From c420c9dd65b9e95dd9163ffe1fc214c95fb04762 Mon Sep 17 00:00:00 2001 From: Ulyssa Date: Wed, 4 Jun 2025 19:36:21 -0700 Subject: [PATCH] Add configuration option for hiding state events (#447) --- src/config.rs | 4 ++++ src/tests.rs | 1 + src/worker.rs | 26 +++++++++++++++----------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/config.rs b/src/config.rs index b1352cb..4a11252 100644 --- a/src/config.rs +++ b/src/config.rs @@ -561,6 +561,7 @@ pub struct TunableValues { pub read_receipt_display: bool, pub request_timeout: u64, pub sort: SortValues, + pub state_event_display: bool, pub typing_notice_send: bool, pub typing_notice_display: bool, pub users: UserOverrides, @@ -586,6 +587,7 @@ pub struct Tunables { pub request_timeout: Option, #[serde(default)] pub sort: SortOverrides, + pub state_event_display: Option, pub typing_notice_send: Option, pub typing_notice_display: Option, pub users: Option, @@ -615,6 +617,7 @@ impl Tunables { read_receipt_display: self.read_receipt_display.or(other.read_receipt_display), request_timeout: self.request_timeout.or(other.request_timeout), sort: merge_sorts(self.sort, other.sort), + state_event_display: self.state_event_display.or(other.state_event_display), typing_notice_send: self.typing_notice_send.or(other.typing_notice_send), typing_notice_display: self.typing_notice_display.or(other.typing_notice_display), users: merge_maps(self.users, other.users), @@ -642,6 +645,7 @@ impl Tunables { read_receipt_display: self.read_receipt_display.unwrap_or(true), request_timeout: self.request_timeout.unwrap_or(DEFAULT_REQ_TIMEOUT), sort: self.sort.values(), + state_event_display: self.state_event_display.unwrap_or(true), typing_notice_send: self.typing_notice_send.unwrap_or(true), typing_notice_display: self.typing_notice_display.unwrap_or(true), users: self.users.unwrap_or_default(), diff --git a/src/tests.rs b/src/tests.rs index f8a3713..38a745c 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -177,6 +177,7 @@ pub fn mock_tunables() -> TunableValues { read_receipt_display: true, request_timeout: 120, sort: SortOverrides::default().values(), + state_event_display: true, typing_notice_send: true, typing_notice_display: true, users: vec![(TEST_USER5.clone(), UserDisplayTunables { diff --git a/src/worker.rs b/src/worker.rs index 3e136cc..3d08584 100644 --- a/src/worker.rs +++ b/src/worker.rs @@ -362,7 +362,9 @@ fn load_insert( continue; }, AnyTimelineEvent::State(msg) => { - info.insert_any_state(msg.into()); + if settings.tunables.state_event_display { + info.insert_any_state(msg.into()); + } }, } } @@ -1059,17 +1061,19 @@ impl ClientWorker { }, ); - let _ = self.client.add_event_handler( - |ev: AnySyncStateEvent, room: MatrixRoom, store: Ctx| { - async move { - let room_id = room.room_id(); - let mut locked = store.lock().await; + if self.settings.tunables.state_event_display { + let _ = self.client.add_event_handler( + |ev: AnySyncStateEvent, room: MatrixRoom, store: Ctx| { + async move { + let room_id = room.room_id(); + let mut locked = store.lock().await; - let info = locked.application.get_room_info(room_id.to_owned()); - info.insert_any_state(ev); - } - }, - ); + let info = locked.application.get_room_info(room_id.to_owned()); + info.insert_any_state(ev); + } + }, + ); + } let _ = self.client.add_event_handler( |ev: OriginalSyncRoomRedactionEvent,