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)_:
139 139
140 /save 140 /save
141 141
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
143filter for Matrix smart-filter tags: 143filter for Matrix smart-filter tags:
144 144
145 /filter add matrix_smart * matrix_smart_filter * 145 /filter add matrix_smart * matrix_smart_filter *
146 146
147The inactivity delay defaults to five minutes and can be changed with:
148
149 /set matrix-rust.look.smart_filter_delay 300000
150
147 151
148# Helpful Commands 152# Helpful Commands
149 153
src/config.rs +10
@@ -126,6 +126,16 @@ config!(
126 "The style that should be used when a message needs to be redacted", 126 "The style that should be used when a message needs to be redacted",
127 RedactionStyle, 127 RedactionStyle,
128 }, 128 },
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 },
129 }, 139 },
130 140
131 Section network { 141 Section network {
src/room/members.rs +10 −2
@@ -267,12 +267,15 @@ impl Members {
267 &self, 267 &self,
268 user_id: &UserId, 268 user_id: &UserId,
269 timestamp: MilliSecondsSinceUnixEpoch, 269 timestamp: MilliSecondsSinceUnixEpoch,
270 smart_filter_delay_ms: i64,
270 ) -> bool { 271 ) -> bool {
271 let Some(last_active) = self.last_active.get(user_id) else { 272 let Some(last_active) = self.last_active.get(user_id) else {
272 return true; 273 return true;
273 }; 274 };
274 275
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
276 } 279 }
277 280
278 pub async fn handle_membership_event( 281 pub async fn handle_membership_event(
@@ -280,6 +283,7 @@ impl Members {
280 event: &SyncStateEvent<RoomMemberEventContent>, 283 event: &SyncStateEvent<RoomMemberEventContent>,
281 state_event: bool, 284 state_event: bool,
282 ambiguity_change: Option<&AmbiguityChange>, 285 ambiguity_change: Option<&AmbiguityChange>,
286 smart_filter_delay_ms: i64,
283 ) { 287 ) {
284 let buffer = self.buffer.buffer_handle(); 288 let buffer = self.buffer.buffer_handle();
285 let buffer = if let Ok(b) = buffer.upgrade() { 289 let buffer = if let Ok(b) = buffer.upgrade() {
@@ -371,7 +375,11 @@ impl Members {
371 (event.origin_server_ts.0 / uint!(1000)).into(); 375 (event.origin_server_ts.0 / uint!(1000)).into();
372 let mut tags = line.tags; 376 let mut tags = line.tags;
373 377
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 ) {
375 tags.push("matrix_smart_filter".to_owned()); 383 tags.push("matrix_smart_filter".to_owned());
376 } 384 }
377 385
src/room/mod.rs +15 −1
@@ -909,6 +909,9 @@ impl MatrixRoom {
909 // If the event has a transaction id it's an event that we sent out 909 // If the event has a transaction id it's an event that we sent out
910 // ourselves, the content will be in the outgoing message queue and it 910 // ourselves, the content will be in the outgoing message queue and it
911 // may have been printed out as a local echo. 911 // may have been printed out as a local echo.
912 self.members
913 .mark_active(event.sender(), event.origin_server_ts());
914
912 if let Some(id) = event.transaction_id() { 915 if let Some(id) = event.transaction_id() {
913 self.handle_outgoing_message(id, event.event_id()).await; 916 self.handle_outgoing_message(id, event.event_id()).await;
914 return; 917 return;
@@ -959,8 +962,16 @@ impl MatrixRoom {
959 state_event: bool, 962 state_event: bool,
960 ambiguity_change: Option<&AmbiguityChange>, 963 ambiguity_change: Option<&AmbiguityChange>,
961 ) { 964 ) {
965 let smart_filter_delay_ms =
966 self.config.borrow().look().smart_filter_delay();
967
962 self.members 968 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 )
964 .await 975 .await
965 } 976 }
966 977
@@ -1034,6 +1045,9 @@ impl MatrixRoom {
1034 event: &AnySyncStateEvent, 1045 event: &AnySyncStateEvent,
1035 _state_event: bool, 1046 _state_event: bool,
1036 ) { 1047 ) {
1048 self.members
1049 .mark_active(event.sender(), event.origin_server_ts());
1050
1037 match event { 1051 match event {
1038 AnySyncStateEvent::RoomName(_) => self.buffer.update_buffer_name(), 1052 AnySyncStateEvent::RoomName(_) => self.buffer.update_buffer_name(),
1039 AnySyncStateEvent::RoomTopic(_) => self.buffer.set_topic(), 1053 AnySyncStateEvent::RoomTopic(_) => self.buffer.set_topic(),