diff --git a/src/api/client/message.rs b/src/api/client/message.rs index 800dce9d..58f4f916 100644 --- a/src/api/client/message.rs +++ b/src/api/client/message.rs @@ -27,23 +27,24 @@ use crate::Ruma; pub(crate) type LazySet = HashSet; /// list of safe and common non-state events to ignore if the user is ignored -const IGNORED_MESSAGE_TYPES: &[TimelineEventType; 16] = &[ +const IGNORED_MESSAGE_TYPES: &[TimelineEventType; 17] = &[ + Audio, + CallInvite, + Emote, + File, + Image, + KeyVerificationStart, + Location, + PollStart, + UnstablePollStart, + Beacon, + Reaction, + RoomEncrypted, RoomMessage, Sticker, - CallInvite, - CallNotify, - RoomEncrypted, - Image, - File, - Audio, - Voice, Video, - UnstablePollStart, - PollStart, - KeyVerificationStart, - Reaction, - Emote, - Location, + Voice, + CallNotify, ]; const LIMIT_MAX: usize = 100; @@ -59,6 +60,7 @@ pub(crate) async fn get_message_events_route( State(services): State, body: Ruma, ) -> Result { + debug_assert!(IGNORED_MESSAGE_TYPES.is_sorted(), "IGNORED_MESSAGE_TYPES is not sorted"); let sender = body.sender(); let (sender_user, sender_device) = sender; let room_id = &body.room_id; @@ -193,7 +195,7 @@ pub(crate) async fn update_lazy( let (_, event) = &item; let (sender_user, sender_device) = sender; - /* TODO: Remove the not "element_hacks" check when these are resolved: + /* TODO: Remove the "element_hacks" check when these are resolved: * https://github.com/vector-im/element-android/issues/3417 * https://github.com/vector-im/element-web/issues/21034 */ @@ -231,19 +233,14 @@ pub(crate) async fn ignored_filter( return None; } - if IGNORED_MESSAGE_TYPES.iter().any(is_equal_to!(&pdu.kind)) - && services.users.user_is_ignored(&pdu.sender, user_id).await - { - return None; - } - - if IGNORED_MESSAGE_TYPES.iter().any(is_equal_to!(&pdu.kind)) - && services - .server - .config - .forbidden_remote_server_names - .iter() - .any(is_equal_to!(pdu.sender().server_name())) + if IGNORED_MESSAGE_TYPES.binary_search(&pdu.kind).is_ok() + && (services.users.user_is_ignored(&pdu.sender, user_id).await + || services + .server + .config + .forbidden_remote_server_names + .iter() + .any(is_equal_to!(pdu.sender().server_name()))) { return None; } diff --git a/src/api/client/room/upgrade.rs b/src/api/client/room/upgrade.rs index cc6cca5e..2f9706f4 100644 --- a/src/api/client/room/upgrade.rs +++ b/src/api/client/room/upgrade.rs @@ -21,15 +21,15 @@ use crate::Ruma; /// Recommended transferable state events list from the spec const TRANSFERABLE_STATE_EVENTS: &[StateEventType; 9] = &[ - StateEventType::RoomServerAcl, - StateEventType::RoomEncryption, - StateEventType::RoomName, StateEventType::RoomAvatar, - StateEventType::RoomTopic, + StateEventType::RoomEncryption, StateEventType::RoomGuestAccess, StateEventType::RoomHistoryVisibility, StateEventType::RoomJoinRules, + StateEventType::RoomName, StateEventType::RoomPowerLevels, + StateEventType::RoomServerAcl, + StateEventType::RoomTopic, ]; /// # `POST /_matrix/client/r0/rooms/{roomId}/upgrade` @@ -46,6 +46,10 @@ pub(crate) async fn upgrade_room_route( State(services): State, body: Ruma, ) -> Result { + debug_assert!( + TRANSFERABLE_STATE_EVENTS.is_sorted(), + "TRANSFERABLE_STATE_EVENTS is not sorted" + ); let sender_user = body.sender_user.as_ref().expect("user is authenticated"); if !services.server.supported_room_version(&body.new_version) { diff --git a/src/api/client/sync/v4.rs b/src/api/client/sync/v4.rs index 7e24adff..0c6ea650 100644 --- a/src/api/client/sync/v4.rs +++ b/src/api/client/sync/v4.rs @@ -30,7 +30,6 @@ use ruma::{ TimelineEventType::{self, *}, }, serde::Raw, - state_res::Event, uint, MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedRoomId, UInt, UserId, }; use service::{rooms::read_receipt::pack_receipts, Services}; @@ -39,8 +38,9 @@ use super::{load_timeline, share_encrypted_room}; use crate::{client::ignored_filter, Ruma}; const SINGLE_CONNECTION_SYNC: &str = "single_connection_sync"; + const DEFAULT_BUMP_TYPES: &[TimelineEventType; 6] = - &[RoomMessage, RoomEncrypted, Sticker, CallInvite, PollStart, Beacon]; + &[CallInvite, PollStart, Beacon, RoomEncrypted, RoomMessage, Sticker]; /// POST `/_matrix/client/unstable/org.matrix.msc3575/sync` /// @@ -49,6 +49,7 @@ pub(crate) async fn sync_events_v4_route( State(services): State, body: Ruma, ) -> Result { + debug_assert!(DEFAULT_BUMP_TYPES.is_sorted(), "DEFAULT_BUMP_TYPES is not sorted"); let sender_user = body.sender_user.as_ref().expect("user is authenticated"); let sender_device = body.sender_device.expect("user is authenticated"); let mut body = body.body; @@ -595,7 +596,7 @@ pub(crate) async fn sync_events_v4_route( for (_, pdu) in timeline_pdus { let ts = MilliSecondsSinceUnixEpoch(pdu.origin_server_ts); - if DEFAULT_BUMP_TYPES.contains(pdu.event_type()) + if DEFAULT_BUMP_TYPES.binary_search(&pdu.kind).is_ok() && timestamp.is_none_or(|time| time <= ts) { timestamp = Some(ts); diff --git a/src/service/rooms/state_accessor/mod.rs b/src/service/rooms/state_accessor/mod.rs index d8093dd7..6ddf198d 100644 --- a/src/service/rooms/state_accessor/mod.rs +++ b/src/service/rooms/state_accessor/mod.rs @@ -11,7 +11,7 @@ use conduwuit::{ err, error, pdu::PduBuilder, utils::{math::usize_from_f64, ReadyExt}, - Err, Error, Event, PduEvent, Result, + Err, Error, PduEvent, Result, }; use futures::StreamExt; use lru_cache::LruCache; @@ -507,7 +507,7 @@ impl Service { if redacting_event .as_ref() - .is_ok_and(|event| event.event_type() == &TimelineEventType::RoomCreate) + .is_ok_and(|pdu| pdu.kind == TimelineEventType::RoomCreate) { return Err!(Request(Forbidden("Redacting m.room.create is not safe, forbidding."))); } diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index 2ae66546..028b270f 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -1262,7 +1262,7 @@ impl Service { #[implement(Service)] #[tracing::instrument(skip_all, level = "debug")] async fn check_pdu_for_admin_room(&self, pdu: &PduEvent, sender: &UserId) -> Result<()> { - match pdu.event_type() { + match &pdu.kind { | TimelineEventType::RoomEncryption => { return Err!(Request(Forbidden(error!("Encryption not supported in admins room.")))); }, diff --git a/src/service/updates/mod.rs b/src/service/updates/mod.rs index 1f499692..7fd93b6c 100644 --- a/src/service/updates/mod.rs +++ b/src/service/updates/mod.rs @@ -40,7 +40,7 @@ struct CheckForUpdatesResponseEntry { const CHECK_FOR_UPDATES_URL: &str = "https://pupbrain.dev/check-for-updates/stable"; const CHECK_FOR_UPDATES_INTERVAL: u64 = 7200; // 2 hours -const LAST_CHECK_FOR_UPDATES_COUNT: &[u8] = b"u"; +const LAST_CHECK_FOR_UPDATES_COUNT: &[u8; 1] = b"u"; #[async_trait] impl crate::Service for Service {