From e3a0ab221467e5cea1a459655449b44d74758a53 Mon Sep 17 00:00:00 2001 From: ember33 Date: Wed, 18 Mar 2026 09:48:20 +0100 Subject: [PATCH] feat(spaces): hook state event changes for role cache invalidation Updates the space roles cache when m.space.roles, m.space.role.member, or m.space.role.room state events are appended. Adds roles service as a dependency of the timeline service. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/service/rooms/timeline/append.rs | 17 +++++++++++++++-- src/service/rooms/timeline/mod.rs | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/service/rooms/timeline/append.rs b/src/service/rooms/timeline/append.rs index 40139a98..89eedfd9 100644 --- a/src/service/rooms/timeline/append.rs +++ b/src/service/rooms/timeline/append.rs @@ -3,7 +3,7 @@ use std::{ sync::Arc, }; -use conduwuit::trace; +use conduwuit::{debug_warn, trace}; use conduwuit_core::{ Result, err, error, implement, matrix::{ @@ -14,7 +14,7 @@ use conduwuit_core::{ }; use futures::StreamExt; use ruma::{ - CanonicalJsonObject, CanonicalJsonValue, EventId, RoomVersionId, UserId, + CanonicalJsonObject, CanonicalJsonValue, EventId, OwnedUserId, RoomId, RoomVersionId, UserId, events::{ GlobalAccountDataEventType, StateEventType, TimelineEventType, push_rules::PushRulesEvent, @@ -359,6 +359,19 @@ where | _ => {}, } + // Space permission cascading: react to role-related state events + if self.services.roles.is_enabled() { + if let Some(state_key) = pdu.state_key() { + let event_type_str = pdu.event_type().to_string(); + match event_type_str.as_str() { + | "m.space.roles" | "m.space.role.member" | "m.space.role.room" => { + self.services.roles.populate_space(room_id).await; + }, + | _ => {}, + } + } + } + // CONCERN: If we receive events with a relation out-of-order, we never write // their relation / thread. We need some kind of way to trigger when we receive // this event, and potentially a way to rebuild the table entirely. diff --git a/src/service/rooms/timeline/mod.rs b/src/service/rooms/timeline/mod.rs index a35b502c..8930e5c6 100644 --- a/src/service/rooms/timeline/mod.rs +++ b/src/service/rooms/timeline/mod.rs @@ -80,6 +80,7 @@ struct Services { threads: Dep, search: Dep, spaces: Dep, + roles: Dep, event_handler: Dep, } @@ -112,6 +113,7 @@ impl crate::Service for Service { threads: args.depend::("rooms::threads"), search: args.depend::("rooms::search"), spaces: args.depend::("rooms::spaces"), + roles: args.depend::("rooms::roles"), event_handler: args .depend::("rooms::event_handler"), },