Commit 2ec691eff4

2ec691eff495525d3c51aad2153d08666206e62b

parent: 918df7d6aa

Unsigned

Darafei Praliaskouski <me@komzpa.net> · 2026-06-29 21:01 UTC
committer: <strk@kbt.io>

fix: refine smart membership filtering

Layout: unified · split

README.md +5 −1
@@ -139,11 +139,15 @@ _(replace the placeholders in brackets [] with your own details)_:
139139
140140 /save
141141
142To hide join/leave noise from users who have not spoken recently, add a WeeChat
142To hide join/leave noise from users who have not been active recently, add a WeeChat
143143filter for Matrix smart-filter tags:
144144
145145 /filter add matrix_smart * matrix_smart_filter *
146146
147The inactivity delay defaults to five minutes and can be changed with:
148
149 /set matrix-rust.look.smart_filter_delay 300000
150
147151
148152# Helpful Commands
149153
src/config.rs +10
@@ -126,6 +126,16 @@ config!(
126126 "The style that should be used when a message needs to be redacted",
127127 RedactionStyle,
128128 },
129
130 smart_filter_delay: Integer {
131 // Description
132 "How long a room member can be inactive, in milliseconds, before \
133 membership events from them get the matrix_smart_filter tag",
134 // Default value.
135 300000,
136 // Range: 0 ms to one day.
137 0..86400000,
138 },
129139 },
130140
131141 Section network {
src/room/members.rs +10 −2
@@ -267,12 +267,15 @@ impl Members {
267267 &self,
268268 user_id: &UserId,
269269 timestamp: MilliSecondsSinceUnixEpoch,
270 smart_filter_delay_ms: i64,
270271 ) -> bool {
271272 let Some(last_active) = self.last_active.get(user_id) else {
272273 return true;
273274 };
274275
275 timestamp.0.saturating_sub(last_active.0) > uint!(300000)
276 let inactive_ms: i64 = timestamp.0.saturating_sub(last_active.0).into();
277
278 inactive_ms > smart_filter_delay_ms
276279 }
277280
278281 pub async fn handle_membership_event(
@@ -280,6 +283,7 @@ impl Members {
280283 event: &SyncStateEvent<RoomMemberEventContent>,
281284 state_event: bool,
282285 ambiguity_change: Option<&AmbiguityChange>,
286 smart_filter_delay_ms: i64,
283287 ) {
284288 let buffer = self.buffer.buffer_handle();
285289 let buffer = if let Ok(b) = buffer.upgrade() {
@@ -371,7 +375,11 @@ impl Members {
371375 (event.origin_server_ts.0 / uint!(1000)).into();
372376 let mut tags = line.tags;
373377
374 if self.should_smart_filter(&target_id, event.origin_server_ts) {
378 if self.should_smart_filter(
379 &target_id,
380 event.origin_server_ts,
381 smart_filter_delay_ms,
382 ) {
375383 tags.push("matrix_smart_filter".to_owned());
376384 }
377385
src/room/mod.rs +15 −1
@@ -909,6 +909,9 @@ impl MatrixRoom {
909909 // If the event has a transaction id it's an event that we sent out
910910 // ourselves, the content will be in the outgoing message queue and it
911911 // may have been printed out as a local echo.
912 self.members
913 .mark_active(event.sender(), event.origin_server_ts());
914
912915 if let Some(id) = event.transaction_id() {
913916 self.handle_outgoing_message(id, event.event_id()).await;
914917 return;
@@ -959,8 +962,16 @@ impl MatrixRoom {
959962 state_event: bool,
960963 ambiguity_change: Option<&AmbiguityChange>,
961964 ) {
965 let smart_filter_delay_ms =
966 self.config.borrow().look().smart_filter_delay();
967
962968 self.members
963 .handle_membership_event(event, state_event, ambiguity_change)
969 .handle_membership_event(
970 event,
971 state_event,
972 ambiguity_change,
973 smart_filter_delay_ms,
974 )
964975 .await
965976 }
966977
@@ -1034,6 +1045,9 @@ impl MatrixRoom {
10341045 event: &AnySyncStateEvent,
10351046 _state_event: bool,
10361047 ) {
1048 self.members
1049 .mark_active(event.sender(), event.origin_server_ts());
1050
10371051 match event {
10381052 AnySyncStateEvent::RoomName(_) => self.buffer.update_buffer_name(),
10391053 AnySyncStateEvent::RoomTopic(_) => self.buffer.set_topic(),