mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-08-04 11:43:58 +00:00
feat(space-upgrades): Update parent spaces in upgrade
This relies on the room being upgraded referencing the space itself, but there isn't an easy way to do it otherwise.
This commit is contained in:
parent
62bdfe1ce8
commit
b2883c3d6e
3 changed files with 124 additions and 5 deletions
|
@ -91,3 +91,22 @@ pub async fn room_state_get(
|
|||
.and_then(|shortstatehash| self.state_get(shortstatehash, event_type, state_key))
|
||||
.await
|
||||
}
|
||||
|
||||
/// Returns all state keys for the given `room_id` and `event_type`.
|
||||
#[implement(super::Service)]
|
||||
#[tracing::instrument(skip(self), level = "debug")]
|
||||
pub async fn room_state_keys(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
event_type: &StateEventType,
|
||||
) -> Result<Vec<String>> {
|
||||
let shortstatehash = self.services.state.get_room_shortstatehash(room_id).await?;
|
||||
|
||||
let state_keys: Vec<String> = self
|
||||
.state_keys(shortstatehash, event_type)
|
||||
.map(|state_key| state_key.to_string())
|
||||
.collect()
|
||||
.await;
|
||||
|
||||
Ok(state_keys)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use conduwuit::{Err, Result, implement, matrix::Event, pdu::PduBuilder};
|
||||
use ruma::{
|
||||
EventId, RoomId, UserId,
|
||||
EventId, Int, RoomId, UserId,
|
||||
events::{
|
||||
StateEventType, TimelineEventType,
|
||||
room::{
|
||||
|
@ -167,3 +167,33 @@ pub async fn user_can_invite(
|
|||
.await
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
#[implement(super::Service)]
|
||||
pub async fn current_power_levels(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
) -> Result<RoomPowerLevelsEventContent> {
|
||||
// fetches the current power levels event content for a room, returning the
|
||||
// default power levels if no power levels event is found
|
||||
let pl_event_content = self
|
||||
.room_state_get_content::<RoomPowerLevelsEventContent>(
|
||||
room_id,
|
||||
&StateEventType::RoomPowerLevels,
|
||||
"",
|
||||
)
|
||||
.await;
|
||||
if let Ok(pl_event_content) = pl_event_content {
|
||||
Ok(pl_event_content)
|
||||
} else {
|
||||
let mut default_power_levels = RoomPowerLevelsEventContent::default();
|
||||
|
||||
// set the creator as PL100
|
||||
let create_event = self
|
||||
.room_state_get(room_id, &StateEventType::RoomCreate, "")
|
||||
.await?;
|
||||
default_power_levels
|
||||
.users
|
||||
.insert(create_event.sender().to_owned(), Int::from(100));
|
||||
Ok(default_power_levels)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue