misc cleanup
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
57e0a5f65d
commit
f503ed918c
7 changed files with 49 additions and 71 deletions
|
@ -1333,10 +1333,8 @@ pub async fn validate_and_add_event_id(
|
|||
services: &Services, pdu: &RawJsonValue, room_version: &RoomVersionId,
|
||||
pub_key_map: &RwLock<BTreeMap<String, BTreeMap<String, Base64>>>,
|
||||
) -> Result<(OwnedEventId, CanonicalJsonObject)> {
|
||||
let mut value: CanonicalJsonObject = serde_json::from_str(pdu.get()).map_err(|e| {
|
||||
debug_error!("Invalid PDU in server response: {pdu:#?}");
|
||||
err!(BadServerResponse("Invalid PDU in server response: {e:?}"))
|
||||
})?;
|
||||
let mut value: CanonicalJsonObject = serde_json::from_str(pdu.get())
|
||||
.map_err(|e| err!(BadServerResponse(debug_error!("Invalid PDU in server response: {e:?}"))))?;
|
||||
let event_id = EventId::parse(format!(
|
||||
"${}",
|
||||
ruma::signatures::reference_hash(&value, room_version).expect("ruma can calculate reference hashes")
|
||||
|
@ -1478,10 +1476,8 @@ pub(crate) async fn invite_helper(
|
|||
|
||||
if *pdu.event_id != *event_id {
|
||||
warn!(
|
||||
"Server {} changed invite event, that's not allowed in the spec: ours: {:?}, theirs: {:?}",
|
||||
"Server {} changed invite event, that's not allowed in the spec: ours: {pdu_json:?}, theirs: {value:?}",
|
||||
user_id.server_name(),
|
||||
pdu_json,
|
||||
value
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1564,20 +1560,19 @@ pub(crate) async fn invite_helper(
|
|||
// Make a user leave all their joined rooms, forgets all rooms, and ignores
|
||||
// errors
|
||||
pub async fn leave_all_rooms(services: &Services, user_id: &UserId) {
|
||||
let all_rooms: Vec<_> = services
|
||||
let rooms_joined = services
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_joined(user_id)
|
||||
.map(ToOwned::to_owned)
|
||||
.chain(
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_invited(user_id)
|
||||
.map(|(r, _)| r),
|
||||
)
|
||||
.collect()
|
||||
.await;
|
||||
.map(ToOwned::to_owned);
|
||||
|
||||
let rooms_invited = services
|
||||
.rooms
|
||||
.state_cache
|
||||
.rooms_invited(user_id)
|
||||
.map(|(r, _)| r);
|
||||
|
||||
let all_rooms: Vec<_> = rooms_joined.chain(rooms_invited).collect().await;
|
||||
|
||||
for room_id in all_rooms {
|
||||
// ignore errors
|
||||
|
@ -1601,7 +1596,7 @@ pub async fn leave_room(services: &Services, user_id: &UserId, room_id: &RoomId,
|
|||
.await
|
||||
{
|
||||
if let Err(e) = remote_leave_room(services, user_id, room_id).await {
|
||||
warn!("Failed to leave room {} remotely: {}", user_id, e);
|
||||
warn!("Failed to leave room {user_id} remotely: {e}");
|
||||
// Don't tell the client about this error
|
||||
}
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ async fn send_state_event_for_key_helper(
|
|||
.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: event_type.to_string().into(),
|
||||
content: serde_json::from_str(json.json().get()).expect("content is valid json"),
|
||||
content: serde_json::from_str(json.json().get())?,
|
||||
unsigned: None,
|
||||
state_key: Some(state_key),
|
||||
redacts: None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue