mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-07-05 14:45:48 +02:00
Use integrated error instead of panic on some legacy codepaths
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
f3dd90df39
commit
732a77f3a8
6 changed files with 49 additions and 89 deletions
|
@ -351,8 +351,7 @@ pub(crate) async fn register_route(
|
||||||
if !services.globals.new_user_displayname_suffix().is_empty()
|
if !services.globals.new_user_displayname_suffix().is_empty()
|
||||||
&& body.appservice_info.is_none()
|
&& body.appservice_info.is_none()
|
||||||
{
|
{
|
||||||
write!(displayname, " {}", services.server.config.new_user_displayname_suffix)
|
write!(displayname, " {}", services.server.config.new_user_displayname_suffix)?;
|
||||||
.expect("should be able to write to string buffer");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
services
|
services
|
||||||
|
@ -370,8 +369,7 @@ pub(crate) async fn register_route(
|
||||||
content: ruma::events::push_rules::PushRulesEventContent {
|
content: ruma::events::push_rules::PushRulesEventContent {
|
||||||
global: push::Ruleset::server_default(&user_id),
|
global: push::Ruleset::server_default(&user_id),
|
||||||
},
|
},
|
||||||
})
|
})?,
|
||||||
.expect("to json always works"),
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,8 @@ pub(crate) async fn get_capabilities_route(
|
||||||
|
|
||||||
let mut capabilities = Capabilities::default();
|
let mut capabilities = Capabilities::default();
|
||||||
capabilities.room_versions = RoomVersionsCapability {
|
capabilities.room_versions = RoomVersionsCapability {
|
||||||
default: services.server.config.default_room_version.clone(),
|
|
||||||
available,
|
available,
|
||||||
|
default: services.server.config.default_room_version.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// we do not implement 3PID stuff
|
// we do not implement 3PID stuff
|
||||||
|
@ -38,16 +38,12 @@ pub(crate) async fn get_capabilities_route(
|
||||||
};
|
};
|
||||||
|
|
||||||
// MSC4133 capability
|
// MSC4133 capability
|
||||||
capabilities
|
capabilities.set("uk.tcpip.msc4133.profile_fields", json!({"enabled": true}))?;
|
||||||
.set("uk.tcpip.msc4133.profile_fields", json!({"enabled": true}))
|
|
||||||
.expect("this is valid JSON we created");
|
|
||||||
|
|
||||||
capabilities
|
capabilities.set(
|
||||||
.set(
|
"org.matrix.msc4267.forget_forced_upon_leave",
|
||||||
"org.matrix.msc4267.forget_forced_upon_leave",
|
json!({"enabled": services.config.forget_forced_upon_leave}),
|
||||||
json!({"enabled": services.config.forget_forced_upon_leave}),
|
)?;
|
||||||
)
|
|
||||||
.expect("valid JSON we created");
|
|
||||||
|
|
||||||
Ok(get_capabilities::v3::Response { capabilities })
|
Ok(get_capabilities::v3::Response { capabilities })
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,17 +79,14 @@ pub(crate) async fn get_pushrules_all_route(
|
||||||
|
|
||||||
global_ruleset.update_with_server_default(Ruleset::server_default(sender_user));
|
global_ruleset.update_with_server_default(Ruleset::server_default(sender_user));
|
||||||
|
|
||||||
|
let ty = GlobalAccountDataEventType::PushRules;
|
||||||
|
let event = PushRulesEvent {
|
||||||
|
content: PushRulesEventContent { global: global_ruleset.clone() },
|
||||||
|
};
|
||||||
|
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
.update(
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(event)?)
|
||||||
None,
|
|
||||||
sender_user,
|
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
|
||||||
&serde_json::to_value(PushRulesEvent {
|
|
||||||
content: PushRulesEventContent { global: global_ruleset.clone() },
|
|
||||||
})
|
|
||||||
.expect("to json always works"),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -118,19 +115,17 @@ pub(crate) async fn get_pushrules_global_route(
|
||||||
else {
|
else {
|
||||||
// user somehow has non-existent push rule event. recreate it and return server
|
// user somehow has non-existent push rule event. recreate it and return server
|
||||||
// default silently
|
// default silently
|
||||||
|
|
||||||
|
let ty = GlobalAccountDataEventType::PushRules;
|
||||||
|
let event = PushRulesEvent {
|
||||||
|
content: PushRulesEventContent {
|
||||||
|
global: Ruleset::server_default(sender_user),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
.update(
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(event)?)
|
||||||
None,
|
|
||||||
sender_user,
|
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
|
||||||
&serde_json::to_value(PushRulesEvent {
|
|
||||||
content: PushRulesEventContent {
|
|
||||||
global: Ruleset::server_default(sender_user),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.expect("to json always works"),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
return Ok(get_pushrules_global_scope::v3::Response {
|
return Ok(get_pushrules_global_scope::v3::Response {
|
||||||
|
@ -274,14 +269,10 @@ pub(crate) async fn set_pushrule_route(
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ty = GlobalAccountDataEventType::PushRules;
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
.update(
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?)
|
||||||
None,
|
|
||||||
sender_user,
|
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
|
||||||
&serde_json::to_value(account_data).expect("to json value always works"),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(set_pushrule::v3::Response {})
|
Ok(set_pushrule::v3::Response {})
|
||||||
|
@ -345,14 +336,10 @@ pub(crate) async fn set_pushrule_actions_route(
|
||||||
return Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found."));
|
return Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ty = GlobalAccountDataEventType::PushRules;
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
.update(
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?)
|
||||||
None,
|
|
||||||
sender_user,
|
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
|
||||||
&serde_json::to_value(account_data).expect("to json value always works"),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(set_pushrule_actions::v3::Response {})
|
Ok(set_pushrule_actions::v3::Response {})
|
||||||
|
@ -416,14 +403,10 @@ pub(crate) async fn set_pushrule_enabled_route(
|
||||||
return Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found."));
|
return Err(Error::BadRequest(ErrorKind::NotFound, "Push rule not found."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ty = GlobalAccountDataEventType::PushRules;
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
.update(
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?)
|
||||||
None,
|
|
||||||
sender_user,
|
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
|
||||||
&serde_json::to_value(account_data).expect("to json value always works"),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(set_pushrule_enabled::v3::Response {})
|
Ok(set_pushrule_enabled::v3::Response {})
|
||||||
|
@ -462,14 +445,10 @@ pub(crate) async fn delete_pushrule_route(
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let ty = GlobalAccountDataEventType::PushRules;
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
.update(
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(account_data)?)
|
||||||
None,
|
|
||||||
sender_user,
|
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
|
||||||
&serde_json::to_value(account_data).expect("to json value always works"),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(delete_pushrule::v3::Response {})
|
Ok(delete_pushrule::v3::Response {})
|
||||||
|
@ -514,19 +493,16 @@ async fn recreate_push_rules_and_return(
|
||||||
services: &Services,
|
services: &Services,
|
||||||
sender_user: &ruma::UserId,
|
sender_user: &ruma::UserId,
|
||||||
) -> Result<get_pushrules_all::v3::Response> {
|
) -> Result<get_pushrules_all::v3::Response> {
|
||||||
|
let ty = GlobalAccountDataEventType::PushRules;
|
||||||
|
let event = PushRulesEvent {
|
||||||
|
content: PushRulesEventContent {
|
||||||
|
global: Ruleset::server_default(sender_user),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
services
|
services
|
||||||
.account_data
|
.account_data
|
||||||
.update(
|
.update(None, sender_user, ty.to_string().into(), &serde_json::to_value(event)?)
|
||||||
None,
|
|
||||||
sender_user,
|
|
||||||
GlobalAccountDataEventType::PushRules.to_string().into(),
|
|
||||||
&serde_json::to_value(PushRulesEvent {
|
|
||||||
content: PushRulesEventContent {
|
|
||||||
global: Ruleset::server_default(sender_user),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.expect("to json always works"),
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(get_pushrules_all::v3::Response {
|
Ok(get_pushrules_all::v3::Response {
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub(crate) async fn set_read_marker_route(
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
sender_user,
|
sender_user,
|
||||||
RoomAccountDataEventType::FullyRead,
|
RoomAccountDataEventType::FullyRead,
|
||||||
&serde_json::to_value(fully_read_event).expect("to json value always works"),
|
&serde_json::to_value(fully_read_event)?,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ pub(crate) async fn create_receipt_route(
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
sender_user,
|
sender_user,
|
||||||
RoomAccountDataEventType::FullyRead,
|
RoomAccountDataEventType::FullyRead,
|
||||||
&serde_json::to_value(fully_read_event).expect("to json value always works"),
|
&serde_json::to_value(fully_read_event)?,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
},
|
},
|
||||||
|
|
|
@ -177,18 +177,10 @@ pub(crate) async fn create_room_route(
|
||||||
RoomCreateEventContent::new_v1(sender_user.to_owned()),
|
RoomCreateEventContent::new_v1(sender_user.to_owned()),
|
||||||
| _ => RoomCreateEventContent::new_v11(),
|
| _ => RoomCreateEventContent::new_v11(),
|
||||||
};
|
};
|
||||||
let mut content = serde_json::from_str::<CanonicalJsonObject>(
|
let mut content =
|
||||||
to_raw_value(&content)
|
serde_json::from_str::<CanonicalJsonObject>(to_raw_value(&content)?.get())
|
||||||
.expect("we just created this as content was None")
|
.unwrap();
|
||||||
.get(),
|
content.insert("room_version".into(), json!(room_version.as_str()).try_into()?);
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
content.insert(
|
|
||||||
"room_version".into(),
|
|
||||||
json!(room_version.as_str())
|
|
||||||
.try_into()
|
|
||||||
.expect("we just created this as content was None"),
|
|
||||||
);
|
|
||||||
content
|
content
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -200,8 +192,7 @@ pub(crate) async fn create_room_route(
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PduBuilder {
|
PduBuilder {
|
||||||
event_type: TimelineEventType::RoomCreate,
|
event_type: TimelineEventType::RoomCreate,
|
||||||
content: to_raw_value(&create_content)
|
content: to_raw_value(&create_content)?,
|
||||||
.expect("create event content serialization"),
|
|
||||||
state_key: Some(StateKey::new()),
|
state_key: Some(StateKey::new()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
@ -267,8 +258,7 @@ pub(crate) async fn create_room_route(
|
||||||
.build_and_append_pdu(
|
.build_and_append_pdu(
|
||||||
PduBuilder {
|
PduBuilder {
|
||||||
event_type: TimelineEventType::RoomPowerLevels,
|
event_type: TimelineEventType::RoomPowerLevels,
|
||||||
content: to_raw_value(&power_levels_content)
|
content: to_raw_value(&power_levels_content)?,
|
||||||
.expect("serialized power_levels event content"),
|
|
||||||
state_key: Some(StateKey::new()),
|
state_key: Some(StateKey::new()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub(crate) async fn update_tag_route(
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
sender_user,
|
sender_user,
|
||||||
RoomAccountDataEventType::Tag,
|
RoomAccountDataEventType::Tag,
|
||||||
&serde_json::to_value(tags_event).expect("to json value always works"),
|
&serde_json::to_value(tags_event)?,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ pub(crate) async fn delete_tag_route(
|
||||||
Some(&body.room_id),
|
Some(&body.room_id),
|
||||||
sender_user,
|
sender_user,
|
||||||
RoomAccountDataEventType::Tag,
|
RoomAccountDataEventType::Tag,
|
||||||
&serde_json::to_value(tags_event).expect("to json value always works"),
|
&serde_json::to_value(tags_event)?,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue