syncv3: use RoomTypeFilter struct instead of Option<RoomType>

Signed-off-by: morguldir <morguldir@protonmail.com>
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
morguldir 2024-09-07 18:09:21 +02:00
parent 593d3bb321
commit 3e0d404fb4
No known key found for this signature in database
GPG key ID: 5A6025D4F6E7A8A3
3 changed files with 31 additions and 39 deletions

27
Cargo.lock generated
View file

@ -2975,7 +2975,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma" name = "ruma"
version = "0.10.1" version = "0.10.1"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"assign", "assign",
"js_int", "js_int",
@ -2997,7 +2997,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-appservice-api" name = "ruma-appservice-api"
version = "0.10.0" version = "0.10.0"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -3009,7 +3009,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-client-api" name = "ruma-client-api"
version = "0.18.0" version = "0.18.0"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"as_variant", "as_variant",
"assign", "assign",
@ -3032,7 +3032,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-common" name = "ruma-common"
version = "0.13.0" version = "0.13.0"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"as_variant", "as_variant",
"base64 0.22.1", "base64 0.22.1",
@ -3062,7 +3062,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-events" name = "ruma-events"
version = "0.28.1" version = "0.28.1"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"as_variant", "as_variant",
"indexmap 2.4.0", "indexmap 2.4.0",
@ -3086,7 +3086,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-federation-api" name = "ruma-federation-api"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"bytes", "bytes",
"http", "http",
@ -3104,7 +3104,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identifiers-validation" name = "ruma-identifiers-validation"
version = "0.9.5" version = "0.9.5"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"js_int", "js_int",
"thiserror", "thiserror",
@ -3113,7 +3113,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-identity-service-api" name = "ruma-identity-service-api"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -3123,8 +3123,9 @@ dependencies = [
[[package]] [[package]]
name = "ruma-macros" name = "ruma-macros"
version = "0.13.0" version = "0.13.0"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"cfg-if",
"once_cell", "once_cell",
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -3138,7 +3139,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-push-gateway-api" name = "ruma-push-gateway-api"
version = "0.9.0" version = "0.9.0"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"js_int", "js_int",
"ruma-common", "ruma-common",
@ -3150,7 +3151,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-server-util" name = "ruma-server-util"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"headers", "headers",
"http", "http",
@ -3163,7 +3164,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-signatures" name = "ruma-signatures"
version = "0.15.0" version = "0.15.0"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"base64 0.22.1", "base64 0.22.1",
"ed25519-dalek", "ed25519-dalek",
@ -3179,7 +3180,7 @@ dependencies = [
[[package]] [[package]]
name = "ruma-state-res" name = "ruma-state-res"
version = "0.11.0" version = "0.11.0"
source = "git+https://github.com/girlbossceo/ruwuma?rev=83a9bf73668aa459ffcf5ca6f95639835c0bac79#83a9bf73668aa459ffcf5ca6f95639835c0bac79" source = "git+https://github.com/girlbossceo/ruwuma?rev=11155e576a1382783c0bcf5ad4458708777ec36e#11155e576a1382783c0bcf5ad4458708777ec36e"
dependencies = [ dependencies = [
"itertools 0.12.1", "itertools 0.12.1",
"js_int", "js_int",

View file

@ -314,7 +314,7 @@ version = "0.1.2"
[workspace.dependencies.ruma] [workspace.dependencies.ruma]
git = "https://github.com/girlbossceo/ruwuma" git = "https://github.com/girlbossceo/ruwuma"
#branch = "conduwuit-changes" #branch = "conduwuit-changes"
rev = "83a9bf73668aa459ffcf5ca6f95639835c0bac79" rev = "11155e576a1382783c0bcf5ad4458708777ec36e"
features = [ features = [
"compat", "compat",
"rand", "rand",
@ -608,7 +608,7 @@ inherits = "release"
# and can be raised if build times are tolerable. # and can be raised if build times are tolerable.
[profile.dev] [profile.dev]
debug = 1 debug = "full"
opt-level = 0 opt-level = 0
panic = "unwind" panic = "unwind"
debug-assertions = true debug-assertions = true

View file

@ -25,12 +25,12 @@ use ruma::{
}, },
uiaa::UiaaResponse, uiaa::UiaaResponse,
}, },
directory::RoomTypeFilter,
events::{ events::{
presence::PresenceEvent, presence::PresenceEvent,
room::member::{MembershipState, RoomMemberEventContent}, room::member::{MembershipState, RoomMemberEventContent},
AnyRawAccountDataEvent, StateEventType, TimelineEventType, AnyRawAccountDataEvent, StateEventType, TimelineEventType,
}, },
room::RoomType,
serde::Raw, serde::Raw,
state_res::Event, state_res::Event,
uint, DeviceId, EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, OwnedUserId, RoomId, UInt, UserId, uint, DeviceId, EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, OwnedUserId, RoomId, UInt, UserId,
@ -1760,32 +1760,23 @@ pub(crate) async fn sync_events_v4_route(
} }
fn filter_rooms( fn filter_rooms(
rooms: &[OwnedRoomId], State(services): State<crate::State>, filter: &[Option<RoomType>], negate: bool, rooms: &[OwnedRoomId], State(services): State<crate::State>, filter: &[RoomTypeFilter], negate: bool,
) -> Vec<OwnedRoomId> { ) -> Vec<OwnedRoomId> {
return rooms return rooms
.iter() .iter()
.filter(|r| { .filter(|r| match services.rooms.state_accessor.get_room_type(r) {
match services.rooms.state_accessor.get_room_type(r) {
Err(e) => { Err(e) => {
warn!("Requested room type for {}, but could not retrieve with error {}", r, e); warn!("Requested room type for {}, but could not retrieve with error {}", r, e);
false false
}, },
Ok(None) => { Ok(result) => {
// For rooms which do not have a room type, use 'null' to include them let result = RoomTypeFilter::from(result);
if negate { if negate {
!filter.contains(&None) !filter.contains(&result)
} else { } else {
filter.contains(&None) filter.is_empty() || filter.contains(&result)
} }
}, },
Ok(Some(room_type)) => {
if negate {
!filter.contains(&Some(room_type))
} else {
filter.is_empty() || filter.contains(&Some(room_type))
}
},
}
}) })
.cloned() .cloned()
.collect(); .collect();