fix: Fix panic when creating rooms

This commit is contained in:
Ginger
2026-04-29 09:26:13 -04:00
parent 049babc7ca
commit 9491be928d
+81 -77
View File
@@ -201,92 +201,96 @@ where
drop(insert_lock); drop(insert_lock);
// See if the event matches any known pushers via power level // See if the event matches any known pushers via power level
let power_levels = self if *pdu.kind() != TimelineEventType::RoomCreate {
.services let power_levels = self
.state_accessor
.get_room_power_levels(room_id)
.await;
let mut push_target: HashSet<_> = self
.services .services
.state_cache .state_accessor
.active_local_users_in_room(room_id) .get_room_power_levels(room_id)
// Don't notify the sender of their own events, and dont send from ignored users
.ready_filter(|user| *user != pdu.sender())
.filter_map(|recipient_user| async move { (!self.services.users.user_is_ignored(pdu.sender(), &recipient_user).await).then_some(recipient_user) })
.collect()
.await; .await;
let mut push_target: HashSet<_> = self
.services
.state_cache
.active_local_users_in_room(room_id)
// Don't notify the sender of their own events, and dont send from ignored users
.ready_filter(|user| *user != pdu.sender())
.filter_map(|recipient_user| async move { (!self.services.users.user_is_ignored(pdu.sender(), &recipient_user).await).then_some(recipient_user) })
.collect()
.await;
let mut notifies = Vec::with_capacity(push_target.len().saturating_add(1)); let mut notifies = Vec::with_capacity(push_target.len().saturating_add(1));
let mut highlights = Vec::with_capacity(push_target.len().saturating_add(1)); let mut highlights = Vec::with_capacity(push_target.len().saturating_add(1));
if *pdu.kind() == TimelineEventType::RoomMember { if *pdu.kind() == TimelineEventType::RoomMember {
if let Some(state_key) = pdu.state_key() { if let Some(state_key) = pdu.state_key() {
let target_user_id = UserId::parse(state_key)?; let target_user_id = UserId::parse(state_key)?;
if self.services.users.is_active_local(&target_user_id).await { if self.services.users.is_active_local(&target_user_id).await {
push_target.insert(target_user_id.clone()); push_target.insert(target_user_id.clone());
}
} }
} }
let serialized = pdu.to_format();
for user in &push_target {
let rules_for_user = self
.services
.account_data
.get_global(user, GlobalAccountDataEventType::PushRules)
.await
.map_or_else(
|_| Ruleset::server_default(user),
|ev: PushRulesEvent| ev.content.global,
);
let mut highlight = false;
let mut notify = false;
for action in self
.services
.pusher
.get_actions(user, &rules_for_user, power_levels.clone(), &serialized, room_id)
.await
{
match action {
| Action::Notify => notify = true,
| Action::SetTweak(Tweak::Highlight(
ruma::push::HighlightTweakValue::Yes,
)) => {
highlight = true;
},
| _ => {},
}
// Break early if both conditions are true
if notify && highlight {
break;
}
}
if notify {
notifies.push(user.clone());
}
if highlight {
highlights.push(user.clone());
}
self.services
.pusher
.get_pushkeys(user)
.ready_for_each(|push_key| {
self.services
.sending
.send_pdu_push(&pdu_id, user, push_key.to_owned())
.expect("TODO: replace with future");
})
.await;
}
self.db
.increment_notification_counts(room_id, notifies, highlights);
} }
let serialized = pdu.to_format();
for user in &push_target {
let rules_for_user = self
.services
.account_data
.get_global(user, GlobalAccountDataEventType::PushRules)
.await
.map_or_else(
|_| Ruleset::server_default(user),
|ev: PushRulesEvent| ev.content.global,
);
let mut highlight = false;
let mut notify = false;
for action in self
.services
.pusher
.get_actions(user, &rules_for_user, power_levels.clone(), &serialized, room_id)
.await
{
match action {
| Action::Notify => notify = true,
| Action::SetTweak(Tweak::Highlight(ruma::push::HighlightTweakValue::Yes)) => {
highlight = true;
},
| _ => {},
}
// Break early if both conditions are true
if notify && highlight {
break;
}
}
if notify {
notifies.push(user.clone());
}
if highlight {
highlights.push(user.clone());
}
self.services
.pusher
.get_pushkeys(user)
.ready_for_each(|push_key| {
self.services
.sending
.send_pdu_push(&pdu_id, user, push_key.to_owned())
.expect("TODO: replace with future");
})
.await;
}
self.db
.increment_notification_counts(room_id, notifies, highlights);
match *pdu.kind() { match *pdu.kind() {
| TimelineEventType::RoomRedaction => { | TimelineEventType::RoomRedaction => {
use RoomVersionId::*; use RoomVersionId::*;