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 | 140 | /save |
| 141 | 141 | |
| 142 | | To hide join/leave noise from users who have not spoken recently, add a WeeChat |
| 142 | To hide join/leave noise from users who have not been active recently, add a WeeChat |
| 143 | 143 | filter for Matrix smart-filter tags: |
| 144 | 144 | |
| 145 | 145 | /filter add matrix_smart * matrix_smart_filter * |
| 146 | 146 | |
| 147 | The 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 | 152 | # Helpful Commands |
| 149 | 153 | |
src/config.rs
+10
| @@ -126,6 +126,16 @@ config!( |
| 126 | 126 | "The style that should be used when a message needs to be redacted", |
| 127 | 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 | 141 | Section network { |
src/room/members.rs
+10 −2
| @@ -267,12 +267,15 @@ impl Members { |
| 267 | 267 | &self, |
| 268 | 268 | user_id: &UserId, |
| 269 | 269 | timestamp: MilliSecondsSinceUnixEpoch, |
| 270 | smart_filter_delay_ms: i64, |
| 270 | 271 | ) -> bool { |
| 271 | 272 | let Some(last_active) = self.last_active.get(user_id) else { |
| 272 | 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 | 281 | pub async fn handle_membership_event( |
| @@ -280,6 +283,7 @@ impl Members { |
| 280 | 283 | event: &SyncStateEvent<RoomMemberEventContent>, |
| 281 | 284 | state_event: bool, |
| 282 | 285 | ambiguity_change: Option<&AmbiguityChange>, |
| 286 | smart_filter_delay_ms: i64, |
| 283 | 287 | ) { |
| 284 | 288 | let buffer = self.buffer.buffer_handle(); |
| 285 | 289 | let buffer = if let Ok(b) = buffer.upgrade() { |
| @@ -371,7 +375,11 @@ impl Members { |
| 371 | 375 | (event.origin_server_ts.0 / uint!(1000)).into(); |
| 372 | 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 | 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 | 909 | // If the event has a transaction id it's an event that we sent out |
| 910 | 910 | // ourselves, the content will be in the outgoing message queue and it |
| 911 | 911 | // may have been printed out as a local echo. |
| 912 | self.members |
| 913 | .mark_active(event.sender(), event.origin_server_ts()); |
| 914 | |
| 912 | 915 | if let Some(id) = event.transaction_id() { |
| 913 | 916 | self.handle_outgoing_message(id, event.event_id()).await; |
| 914 | 917 | return; |
| @@ -959,8 +962,16 @@ impl MatrixRoom { |
| 959 | 962 | state_event: bool, |
| 960 | 963 | ambiguity_change: Option<&AmbiguityChange>, |
| 961 | 964 | ) { |
| 965 | let smart_filter_delay_ms = |
| 966 | self.config.borrow().look().smart_filter_delay(); |
| 967 | |
| 962 | 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 | 975 | .await |
| 965 | 976 | } |
| 966 | 977 | |
| @@ -1034,6 +1045,9 @@ impl MatrixRoom { |
| 1034 | 1045 | event: &AnySyncStateEvent, |
| 1035 | 1046 | _state_event: bool, |
| 1036 | 1047 | ) { |
| 1048 | self.members |
| 1049 | .mark_active(event.sender(), event.origin_server_ts()); |
| 1050 | |
| 1037 | 1051 | match event { |
| 1038 | 1052 | AnySyncStateEvent::RoomName(_) => self.buffer.update_buffer_name(), |
| 1039 | 1053 | AnySyncStateEvent::RoomTopic(_) => self.buffer.set_topic(), |