fix ignored_filter check, exclude dummy events over sync

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-11-24 22:30:14 -05:00
parent 2592f83b69
commit 8611cc0ee9
3 changed files with 15 additions and 53 deletions

View file

@ -25,8 +25,8 @@ use crate::Ruma;
pub(crate) type LazySet = HashSet<OwnedUserId>; pub(crate) type LazySet = HashSet<OwnedUserId>;
/// list of safe and common non-state events to ignore /// list of safe and common non-state events to ignore if the user is ignored
const IGNORED_MESSAGE_TYPES: &[TimelineEventType] = &[ const IGNORED_MESSAGE_TYPES: &[TimelineEventType; 16] = &[
RoomMessage, RoomMessage,
Sticker, Sticker,
CallInvite, CallInvite,
@ -206,19 +206,19 @@ pub(crate) async fn update_lazy(
pub(crate) async fn ignored_filter(services: &Services, item: PdusIterItem, user_id: &UserId) -> Option<PdusIterItem> { pub(crate) async fn ignored_filter(services: &Services, item: PdusIterItem, user_id: &UserId) -> Option<PdusIterItem> {
let (_, pdu) = &item; let (_, pdu) = &item;
// exclude Synapse's dummy events from bloating up response bodies. clients
// don't need to see this.
if pdu.kind.to_cow_str() == "org.matrix.dummy_event" { if pdu.kind.to_cow_str() == "org.matrix.dummy_event" {
return None; return None;
} }
if !IGNORED_MESSAGE_TYPES.iter().any(is_equal_to!(&pdu.kind)) { if IGNORED_MESSAGE_TYPES.iter().any(is_equal_to!(&pdu.kind))
return Some(item); && services.users.user_is_ignored(&pdu.sender, user_id).await
{
return None;
} }
if !services.users.user_is_ignored(&pdu.sender, user_id).await { Some(item)
return Some(item);
}
None
} }
pub(crate) async fn visibility_filter( pub(crate) async fn visibility_filter(

View file

@ -38,6 +38,7 @@ use tracing::{Instrument as _, Span};
use super::{load_timeline, share_encrypted_room}; use super::{load_timeline, share_encrypted_room};
use crate::{ use crate::{
client::ignored_filter,
service::{pdu::EventHash, Services}, service::{pdu::EventHash, Services},
utils, Error, PduEvent, Result, Ruma, RumaResponse, utils, Error, PduEvent, Result, Ruma, RumaResponse,
}; };
@ -949,28 +950,8 @@ async fn load_joined_room(
let room_events: Vec<_> = timeline_pdus let room_events: Vec<_> = timeline_pdus
.iter() .iter()
.stream() .stream()
.filter_map(|(_, pdu)| async move { .filter_map(|item| ignored_filter(services, item.clone(), sender_user))
// list of safe and common non-state events to ignore .map(|(_, pdu)| pdu.to_sync_room_event())
if matches!(
&pdu.kind,
RoomMessage
| Sticker | CallInvite
| CallNotify | RoomEncrypted
| Image | File | Audio
| Voice | Video | UnstablePollStart
| PollStart | KeyVerificationStart
| Reaction | Emote
| Location
) && services
.users
.user_is_ignored(&pdu.sender, sender_user)
.await
{
return None;
}
Some(pdu.to_sync_room_event())
})
.collect() .collect()
.await; .await;

View file

@ -35,7 +35,7 @@ use ruma::{
use service::{rooms::read_receipt::pack_receipts, Services}; use service::{rooms::read_receipt::pack_receipts, Services};
use super::{load_timeline, share_encrypted_room}; use super::{load_timeline, share_encrypted_room};
use crate::Ruma; use crate::{client::ignored_filter, Ruma};
const SINGLE_CONNECTION_SYNC: &str = "single_connection_sync"; const SINGLE_CONNECTION_SYNC: &str = "single_connection_sync";
const DEFAULT_BUMP_TYPES: &[TimelineEventType; 6] = const DEFAULT_BUMP_TYPES: &[TimelineEventType; 6] =
@ -539,27 +539,8 @@ pub(crate) async fn sync_events_v4_route(
let room_events: Vec<_> = timeline_pdus let room_events: Vec<_> = timeline_pdus
.iter() .iter()
.stream() .stream()
.filter_map(|(_, pdu)| async move { .filter_map(|item| ignored_filter(&services, item.clone(), sender_user))
// list of safe and common non-state events to ignore .map(|(_, pdu)| pdu.to_sync_room_event())
if matches!(
&pdu.kind,
RoomMessage
| Sticker | CallInvite
| CallNotify | RoomEncrypted
| Image | File | Audio
| Voice | Video | UnstablePollStart
| PollStart | KeyVerificationStart
| Reaction | Emote | Location
) && services
.users
.user_is_ignored(&pdu.sender, sender_user)
.await
{
return None;
}
Some(pdu.to_sync_room_event())
})
.collect() .collect()
.await; .await;