Add configuration option for hiding state events (#447)

This commit is contained in:
Ulyssa 2025-06-04 19:36:21 -07:00 committed by GitHub
parent ba7d0392d8
commit c420c9dd65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 11 deletions

View file

@ -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<u64>,
#[serde(default)]
pub sort: SortOverrides,
pub state_event_display: Option<bool>,
pub typing_notice_send: Option<bool>,
pub typing_notice_display: Option<bool>,
pub users: Option<UserOverrides>,
@ -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(),

View file

@ -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 {

View file

@ -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<AsyncProgramStore>| {
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<AsyncProgramStore>| {
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,