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) <noreply@anthropic.com>
This commit is contained in:
parent
0a52a928dc
commit
e3a0ab2214
2 changed files with 17 additions and 2 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ struct Services {
|
|||
threads: Dep<rooms::threads::Service>,
|
||||
search: Dep<rooms::search::Service>,
|
||||
spaces: Dep<rooms::spaces::Service>,
|
||||
roles: Dep<rooms::roles::Service>,
|
||||
event_handler: Dep<rooms::event_handler::Service>,
|
||||
}
|
||||
|
||||
|
|
@ -112,6 +113,7 @@ impl crate::Service for Service {
|
|||
threads: args.depend::<rooms::threads::Service>("rooms::threads"),
|
||||
search: args.depend::<rooms::search::Service>("rooms::search"),
|
||||
spaces: args.depend::<rooms::spaces::Service>("rooms::spaces"),
|
||||
roles: args.depend::<rooms::roles::Service>("rooms::roles"),
|
||||
event_handler: args
|
||||
.depend::<rooms::event_handler::Service>("rooms::event_handler"),
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue