|
|
@ -53,8 +53,7 @@ pub async fn create_room_route(
|
|
|
|
content.room_version = RoomVersionId::Version6;
|
|
|
|
content.room_version = RoomVersionId::Version6;
|
|
|
|
|
|
|
|
|
|
|
|
// 1. The room create event
|
|
|
|
// 1. The room create event
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomCreate,
|
|
|
|
event_type: EventType::RoomCreate,
|
|
|
|
content: serde_json::to_value(content).expect("event is valid, we just created it"),
|
|
|
|
content: serde_json::to_value(content).expect("event is valid, we just created it"),
|
|
|
@ -67,12 +66,10 @@ pub async fn create_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2. Let the room creator join
|
|
|
|
// 2. Let the room creator join
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomMember,
|
|
|
|
event_type: EventType::RoomMember,
|
|
|
|
content: serde_json::to_value(member::MemberEventContent {
|
|
|
|
content: serde_json::to_value(member::MemberEventContent {
|
|
|
@ -92,8 +89,7 @@ pub async fn create_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3. Power levels
|
|
|
|
// 3. Power levels
|
|
|
|
let mut users = BTreeMap::new();
|
|
|
|
let mut users = BTreeMap::new();
|
|
|
@ -123,8 +119,7 @@ pub async fn create_room_route(
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.expect("event is valid, we just created it")
|
|
|
|
.expect("event is valid, we just created it")
|
|
|
|
};
|
|
|
|
};
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomPowerLevels,
|
|
|
|
event_type: EventType::RoomPowerLevels,
|
|
|
|
content: power_levels_content,
|
|
|
|
content: power_levels_content,
|
|
|
@ -137,8 +132,7 @@ pub async fn create_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4. Events set by preset
|
|
|
|
// 4. Events set by preset
|
|
|
|
|
|
|
|
|
|
|
@ -149,8 +143,7 @@ pub async fn create_room_route(
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 4.1 Join Rules
|
|
|
|
// 4.1 Join Rules
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomJoinRules,
|
|
|
|
event_type: EventType::RoomJoinRules,
|
|
|
|
content: match preset {
|
|
|
|
content: match preset {
|
|
|
@ -173,19 +166,15 @@ pub async fn create_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4.2 History Visibility
|
|
|
|
// 4.2 History Visibility
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomHistoryVisibility,
|
|
|
|
event_type: EventType::RoomHistoryVisibility,
|
|
|
|
content: serde_json::to_value(
|
|
|
|
content: serde_json::to_value(history_visibility::HistoryVisibilityEventContent::new(
|
|
|
|
history_visibility::HistoryVisibilityEventContent::new(
|
|
|
|
|
|
|
|
history_visibility::HistoryVisibility::Shared,
|
|
|
|
history_visibility::HistoryVisibility::Shared,
|
|
|
|
),
|
|
|
|
))
|
|
|
|
)
|
|
|
|
|
|
|
|
.expect("event is valid, we just created it"),
|
|
|
|
.expect("event is valid, we just created it"),
|
|
|
|
unsigned: None,
|
|
|
|
unsigned: None,
|
|
|
|
state_key: Some("".to_owned()),
|
|
|
|
state_key: Some("".to_owned()),
|
|
|
@ -196,12 +185,10 @@ pub async fn create_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4.3 Guest Access
|
|
|
|
// 4.3 Guest Access
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomGuestAccess,
|
|
|
|
event_type: EventType::RoomGuestAccess,
|
|
|
|
content: match preset {
|
|
|
|
content: match preset {
|
|
|
@ -225,8 +212,7 @@ pub async fn create_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 5. Events listed in initial_state
|
|
|
|
// 5. Events listed in initial_state
|
|
|
|
for event in &body.initial_state {
|
|
|
|
for event in &body.initial_state {
|
|
|
@ -240,22 +226,19 @@ pub async fn create_room_route(
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
pdu_builder,
|
|
|
|
pdu_builder,
|
|
|
|
&sender_id,
|
|
|
|
&sender_id,
|
|
|
|
&room_id,
|
|
|
|
&room_id,
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 6. Events implied by name and topic
|
|
|
|
// 6. Events implied by name and topic
|
|
|
|
if let Some(name) = &body.name {
|
|
|
|
if let Some(name) = &body.name {
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomName,
|
|
|
|
event_type: EventType::RoomName,
|
|
|
|
content: serde_json::to_value(
|
|
|
|
content: serde_json::to_value(
|
|
|
@ -273,13 +256,11 @@ pub async fn create_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(topic) = &body.topic {
|
|
|
|
if let Some(topic) = &body.topic {
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomTopic,
|
|
|
|
event_type: EventType::RoomTopic,
|
|
|
|
content: serde_json::to_value(topic::TopicEventContent {
|
|
|
|
content: serde_json::to_value(topic::TopicEventContent {
|
|
|
@ -295,14 +276,12 @@ pub async fn create_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 7. Events implied by invite (and TODO: invite_3pid)
|
|
|
|
// 7. Events implied by invite (and TODO: invite_3pid)
|
|
|
|
for user in &body.invite {
|
|
|
|
for user in &body.invite {
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomMember,
|
|
|
|
event_type: EventType::RoomMember,
|
|
|
|
content: serde_json::to_value(member::MemberEventContent {
|
|
|
|
content: serde_json::to_value(member::MemberEventContent {
|
|
|
@ -322,8 +301,7 @@ pub async fn create_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Homeserver specific stuff
|
|
|
|
// Homeserver specific stuff
|
|
|
@ -395,17 +373,13 @@ pub async fn upgrade_room_route(
|
|
|
|
|
|
|
|
|
|
|
|
// Send a m.room.tombstone event to the old room to indicate that it is not intended to be used any further
|
|
|
|
// Send a m.room.tombstone event to the old room to indicate that it is not intended to be used any further
|
|
|
|
// Fail if the sender does not have the required permissions
|
|
|
|
// Fail if the sender does not have the required permissions
|
|
|
|
let tombstone_event_id = db
|
|
|
|
let tombstone_event_id = db.rooms.build_and_append_pdu(
|
|
|
|
.rooms
|
|
|
|
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomTombstone,
|
|
|
|
event_type: EventType::RoomTombstone,
|
|
|
|
content: serde_json::to_value(
|
|
|
|
content: serde_json::to_value(ruma::events::room::tombstone::TombstoneEventContent {
|
|
|
|
ruma::events::room::tombstone::TombstoneEventContent {
|
|
|
|
|
|
|
|
body: "This room has been replaced".to_string(),
|
|
|
|
body: "This room has been replaced".to_string(),
|
|
|
|
replacement_room: replacement_room.clone(),
|
|
|
|
replacement_room: replacement_room.clone(),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
.expect("event is valid, we just created it"),
|
|
|
|
.expect("event is valid, we just created it"),
|
|
|
|
unsigned: None,
|
|
|
|
unsigned: None,
|
|
|
|
state_key: Some("".to_owned()),
|
|
|
|
state_key: Some("".to_owned()),
|
|
|
@ -416,8 +390,7 @@ pub async fn upgrade_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get the old room federations status
|
|
|
|
// Get the old room federations status
|
|
|
|
let federate = serde_json::from_value::<Raw<ruma::events::room::create::CreateEventContent>>(
|
|
|
|
let federate = serde_json::from_value::<Raw<ruma::events::room::create::CreateEventContent>>(
|
|
|
@ -444,8 +417,7 @@ pub async fn upgrade_room_route(
|
|
|
|
create_event_content.room_version = new_version;
|
|
|
|
create_event_content.room_version = new_version;
|
|
|
|
create_event_content.predecessor = predecessor;
|
|
|
|
create_event_content.predecessor = predecessor;
|
|
|
|
|
|
|
|
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomCreate,
|
|
|
|
event_type: EventType::RoomCreate,
|
|
|
|
content: serde_json::to_value(create_event_content)
|
|
|
|
content: serde_json::to_value(create_event_content)
|
|
|
@ -459,12 +431,10 @@ pub async fn upgrade_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Join the new room
|
|
|
|
// Join the new room
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomMember,
|
|
|
|
event_type: EventType::RoomMember,
|
|
|
|
content: serde_json::to_value(member::MemberEventContent {
|
|
|
|
content: serde_json::to_value(member::MemberEventContent {
|
|
|
@ -484,8 +454,7 @@ pub async fn upgrade_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Recommended transferable state events list from the specs
|
|
|
|
// Recommended transferable state events list from the specs
|
|
|
|
let transferable_state_events = vec![
|
|
|
|
let transferable_state_events = vec![
|
|
|
@ -507,8 +476,7 @@ pub async fn upgrade_room_route(
|
|
|
|
None => continue, // Skipping missing events.
|
|
|
|
None => continue, // Skipping missing events.
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
db.rooms
|
|
|
|
db.rooms.build_and_append_pdu(
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type,
|
|
|
|
event_type,
|
|
|
|
content: event_content,
|
|
|
|
content: event_content,
|
|
|
@ -521,8 +489,7 @@ pub async fn upgrade_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Moves any local aliases to the new room
|
|
|
|
// Moves any local aliases to the new room
|
|
|
@ -552,9 +519,7 @@ pub async fn upgrade_room_route(
|
|
|
|
power_levels_event_content.invite = new_level;
|
|
|
|
power_levels_event_content.invite = new_level;
|
|
|
|
|
|
|
|
|
|
|
|
// Modify the power levels in the old room to prevent sending of events and inviting new users
|
|
|
|
// Modify the power levels in the old room to prevent sending of events and inviting new users
|
|
|
|
let _ = db
|
|
|
|
let _ = db.rooms.build_and_append_pdu(
|
|
|
|
.rooms
|
|
|
|
|
|
|
|
.build_and_append_pdu(
|
|
|
|
|
|
|
|
PduBuilder {
|
|
|
|
PduBuilder {
|
|
|
|
event_type: EventType::RoomPowerLevels,
|
|
|
|
event_type: EventType::RoomPowerLevels,
|
|
|
|
content: serde_json::to_value(power_levels_event_content)
|
|
|
|
content: serde_json::to_value(power_levels_event_content)
|
|
|
@ -568,8 +533,7 @@ pub async fn upgrade_room_route(
|
|
|
|
&db.globals,
|
|
|
|
&db.globals,
|
|
|
|
&db.sending,
|
|
|
|
&db.sending,
|
|
|
|
&db.account_data,
|
|
|
|
&db.account_data,
|
|
|
|
)
|
|
|
|
)?;
|
|
|
|
.await;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Return the replacement room id
|
|
|
|
// Return the replacement room id
|
|
|
|
Ok(upgrade_room::Response { replacement_room }.into())
|
|
|
|
Ok(upgrade_room::Response { replacement_room }.into())
|
|
|
|