fix ignored_filter check, exclude dummy events over sync
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
2592f83b69
commit
8611cc0ee9
3 changed files with 15 additions and 53 deletions
|
@ -25,8 +25,8 @@ use crate::Ruma;
|
|||
|
||||
pub(crate) type LazySet = HashSet<OwnedUserId>;
|
||||
|
||||
/// list of safe and common non-state events to ignore
|
||||
const IGNORED_MESSAGE_TYPES: &[TimelineEventType] = &[
|
||||
/// list of safe and common non-state events to ignore if the user is ignored
|
||||
const IGNORED_MESSAGE_TYPES: &[TimelineEventType; 16] = &[
|
||||
RoomMessage,
|
||||
Sticker,
|
||||
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> {
|
||||
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" {
|
||||
return None;
|
||||
}
|
||||
|
||||
if !IGNORED_MESSAGE_TYPES.iter().any(is_equal_to!(&pdu.kind)) {
|
||||
return Some(item);
|
||||
if IGNORED_MESSAGE_TYPES.iter().any(is_equal_to!(&pdu.kind))
|
||||
&& services.users.user_is_ignored(&pdu.sender, user_id).await
|
||||
{
|
||||
return None;
|
||||
}
|
||||
|
||||
if !services.users.user_is_ignored(&pdu.sender, user_id).await {
|
||||
return Some(item);
|
||||
}
|
||||
|
||||
None
|
||||
Some(item)
|
||||
}
|
||||
|
||||
pub(crate) async fn visibility_filter(
|
||||
|
|
|
@ -38,6 +38,7 @@ use tracing::{Instrument as _, Span};
|
|||
|
||||
use super::{load_timeline, share_encrypted_room};
|
||||
use crate::{
|
||||
client::ignored_filter,
|
||||
service::{pdu::EventHash, Services},
|
||||
utils, Error, PduEvent, Result, Ruma, RumaResponse,
|
||||
};
|
||||
|
@ -949,28 +950,8 @@ async fn load_joined_room(
|
|||
let room_events: Vec<_> = timeline_pdus
|
||||
.iter()
|
||||
.stream()
|
||||
.filter_map(|(_, pdu)| async move {
|
||||
// list of safe and common non-state events to ignore
|
||||
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())
|
||||
})
|
||||
.filter_map(|item| ignored_filter(services, item.clone(), sender_user))
|
||||
.map(|(_, pdu)| pdu.to_sync_room_event())
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ use ruma::{
|
|||
use service::{rooms::read_receipt::pack_receipts, Services};
|
||||
|
||||
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 DEFAULT_BUMP_TYPES: &[TimelineEventType; 6] =
|
||||
|
@ -539,27 +539,8 @@ pub(crate) async fn sync_events_v4_route(
|
|||
let room_events: Vec<_> = timeline_pdus
|
||||
.iter()
|
||||
.stream()
|
||||
.filter_map(|(_, pdu)| async move {
|
||||
// list of safe and common non-state events to ignore
|
||||
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())
|
||||
})
|
||||
.filter_map(|item| ignored_filter(&services, item.clone(), sender_user))
|
||||
.map(|(_, pdu)| pdu.to_sync_room_event())
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue