mirror of
https://gitlab.com/famedly/conduit.git
synced 2024-11-04 16:38:52 +01:00
Fix ALL clippy warnings
This commit is contained in:
parent
851eb555b6
commit
5a8041969d
12 changed files with 106 additions and 278 deletions
|
@ -239,11 +239,7 @@ pub async fn register_route(
|
||||||
},
|
},
|
||||||
&conduit_user,
|
&conduit_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 2. Make conduit bot join
|
// 2. Make conduit bot join
|
||||||
|
@ -264,11 +260,7 @@ pub async fn register_route(
|
||||||
},
|
},
|
||||||
&conduit_user,
|
&conduit_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 3. Power levels
|
// 3. Power levels
|
||||||
|
@ -302,11 +294,7 @@ pub async fn register_route(
|
||||||
},
|
},
|
||||||
&conduit_user,
|
&conduit_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 4.1 Join Rules
|
// 4.1 Join Rules
|
||||||
|
@ -323,11 +311,7 @@ pub async fn register_route(
|
||||||
},
|
},
|
||||||
&conduit_user,
|
&conduit_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 4.2 History Visibility
|
// 4.2 History Visibility
|
||||||
|
@ -346,11 +330,7 @@ pub async fn register_route(
|
||||||
},
|
},
|
||||||
&conduit_user,
|
&conduit_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 4.3 Guest Access
|
// 4.3 Guest Access
|
||||||
|
@ -367,11 +347,7 @@ pub async fn register_route(
|
||||||
},
|
},
|
||||||
&conduit_user,
|
&conduit_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 6. Events implied by name and topic
|
// 6. Events implied by name and topic
|
||||||
|
@ -390,11 +366,7 @@ pub async fn register_route(
|
||||||
},
|
},
|
||||||
&conduit_user,
|
&conduit_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
db.rooms.build_and_append_pdu(
|
db.rooms.build_and_append_pdu(
|
||||||
|
@ -410,11 +382,7 @@ pub async fn register_route(
|
||||||
},
|
},
|
||||||
&conduit_user,
|
&conduit_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Room alias
|
// Room alias
|
||||||
|
@ -436,11 +404,7 @@ pub async fn register_route(
|
||||||
},
|
},
|
||||||
&conduit_user,
|
&conduit_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
db.rooms.set_alias(&alias, Some(&room_id), &db.globals)?;
|
db.rooms.set_alias(&alias, Some(&room_id), &db.globals)?;
|
||||||
|
@ -463,11 +427,7 @@ pub async fn register_route(
|
||||||
},
|
},
|
||||||
&conduit_user,
|
&conduit_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
db.rooms.build_and_append_pdu(
|
db.rooms.build_and_append_pdu(
|
||||||
PduBuilder {
|
PduBuilder {
|
||||||
|
@ -486,11 +446,7 @@ pub async fn register_route(
|
||||||
},
|
},
|
||||||
&user_id,
|
&user_id,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Send welcome message
|
// Send welcome message
|
||||||
|
@ -515,11 +471,7 @@ pub async fn register_route(
|
||||||
},
|
},
|
||||||
&conduit_user,
|
&conduit_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -691,11 +643,7 @@ pub async fn deactivate_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,11 +124,7 @@ pub async fn leave_room_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
db.flush().await?;
|
db.flush().await?;
|
||||||
|
@ -164,11 +160,7 @@ pub async fn invite_user_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
db.flush().await?;
|
db.flush().await?;
|
||||||
|
@ -220,11 +212,7 @@ pub async fn kick_user_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
db.flush().await?;
|
db.flush().await?;
|
||||||
|
@ -280,11 +268,7 @@ pub async fn ban_user_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
db.flush().await?;
|
db.flush().await?;
|
||||||
|
@ -332,11 +316,7 @@ pub async fn unban_user_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
db.flush().await?;
|
db.flush().await?;
|
||||||
|
@ -685,9 +665,7 @@ async fn join_room_by_id_helper(
|
||||||
utils::to_canonical_object(&**pdu).expect("Pdu is valid canonical object"),
|
utils::to_canonical_object(&**pdu).expect("Pdu is valid canonical object"),
|
||||||
count,
|
count,
|
||||||
pdu_id.clone().into(),
|
pdu_id.clone().into(),
|
||||||
&db.globals,
|
&db,
|
||||||
&db.account_data,
|
|
||||||
&db.admin,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if state_events.contains(ev_id) {
|
if state_events.contains(ev_id) {
|
||||||
|
@ -717,11 +695,7 @@ async fn join_room_by_id_helper(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,11 +68,7 @@ pub async fn send_message_event_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
db.transaction_ids.add_txnid(
|
db.transaction_ids.add_txnid(
|
||||||
|
|
|
@ -63,11 +63,7 @@ pub async fn set_displayname_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Presence update
|
// Presence update
|
||||||
|
@ -160,11 +156,7 @@ pub async fn set_avatar_url_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Presence update
|
// Presence update
|
||||||
|
|
|
@ -31,11 +31,7 @@ pub async fn redact_event_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
db.flush().await?;
|
db.flush().await?;
|
||||||
|
|
|
@ -65,11 +65,7 @@ pub async fn create_room_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 2. Let the room creator join
|
// 2. Let the room creator join
|
||||||
|
@ -90,11 +86,7 @@ pub async fn create_room_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 3. Power levels
|
// 3. Power levels
|
||||||
|
@ -135,11 +127,7 @@ pub async fn create_room_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 4. Events set by preset
|
// 4. Events set by preset
|
||||||
|
@ -175,11 +163,7 @@ pub async fn create_room_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 4.2 History Visibility
|
// 4.2 History Visibility
|
||||||
|
@ -196,11 +180,7 @@ pub async fn create_room_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 4.3 Guest Access
|
// 4.3 Guest Access
|
||||||
|
@ -225,11 +205,7 @@ pub async fn create_room_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// 5. Events listed in initial_state
|
// 5. Events listed in initial_state
|
||||||
|
@ -248,11 +224,7 @@ pub async fn create_room_route(
|
||||||
pdu_builder,
|
pdu_builder,
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,11 +245,7 @@ pub async fn create_room_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,11 +263,7 @@ pub async fn create_room_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,11 +286,7 @@ pub async fn create_room_route(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -413,11 +373,7 @@ pub async fn upgrade_room_route(
|
||||||
},
|
},
|
||||||
sender_user,
|
sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Get the old room federations status
|
// Get the old room federations status
|
||||||
|
@ -457,11 +413,7 @@ pub async fn upgrade_room_route(
|
||||||
},
|
},
|
||||||
sender_user,
|
sender_user,
|
||||||
&replacement_room,
|
&replacement_room,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Join the new room
|
// Join the new room
|
||||||
|
@ -482,11 +434,7 @@ pub async fn upgrade_room_route(
|
||||||
},
|
},
|
||||||
sender_user,
|
sender_user,
|
||||||
&replacement_room,
|
&replacement_room,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// Recommended transferable state events list from the specs
|
// Recommended transferable state events list from the specs
|
||||||
|
@ -519,11 +467,7 @@ pub async fn upgrade_room_route(
|
||||||
},
|
},
|
||||||
sender_user,
|
sender_user,
|
||||||
&replacement_room,
|
&replacement_room,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,11 +510,7 @@ pub async fn upgrade_room_route(
|
||||||
},
|
},
|
||||||
sender_user,
|
sender_user,
|
||||||
&body.room_id,
|
&body.room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
db.flush().await?;
|
db.flush().await?;
|
||||||
|
|
|
@ -284,11 +284,7 @@ pub async fn send_state_event_for_key_helper(
|
||||||
},
|
},
|
||||||
&sender_user,
|
&sender_user,
|
||||||
&room_id,
|
&room_id,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(event_id)
|
Ok(event_id)
|
||||||
|
|
|
@ -60,11 +60,7 @@ impl Admin {
|
||||||
},
|
},
|
||||||
&conduit_user,
|
&conduit_user,
|
||||||
&conduit_room,
|
&conduit_room,
|
||||||
&db.globals,
|
&db,
|
||||||
&db.sending,
|
|
||||||
&db.admin,
|
|
||||||
&db.account_data,
|
|
||||||
&db.appservice,
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ mod edus;
|
||||||
|
|
||||||
pub use edus::RoomEdus;
|
pub use edus::RoomEdus;
|
||||||
|
|
||||||
use crate::{pdu::PduBuilder, utils, Error, PduEvent, Result};
|
use crate::{pdu::PduBuilder, utils, Database, Error, PduEvent, Result};
|
||||||
use log::error;
|
use log::error;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use ring::digest;
|
use ring::digest;
|
||||||
|
@ -447,9 +447,7 @@ impl Rooms {
|
||||||
mut pdu_json: CanonicalJsonObject,
|
mut pdu_json: CanonicalJsonObject,
|
||||||
count: u64,
|
count: u64,
|
||||||
pdu_id: IVec,
|
pdu_id: IVec,
|
||||||
globals: &super::globals::Globals,
|
db: &Database,
|
||||||
account_data: &super::account_data::AccountData,
|
|
||||||
admin: &super::admin::Admin,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
// Make unsigned fields correct. This is not properly documented in the spec, but state
|
// Make unsigned fields correct. This is not properly documented in the spec, but state
|
||||||
// events need to have previous content in the unsigned field, so clients can easily
|
// events need to have previous content in the unsigned field, so clients can easily
|
||||||
|
@ -486,7 +484,7 @@ impl Rooms {
|
||||||
// Mark as read first so the sending client doesn't get a notification even if appending
|
// Mark as read first so the sending client doesn't get a notification even if appending
|
||||||
// fails
|
// fails
|
||||||
self.edus
|
self.edus
|
||||||
.private_read_set(&pdu.room_id, &pdu.sender, count, &globals)?;
|
.private_read_set(&pdu.room_id, &pdu.sender, count, &db.globals)?;
|
||||||
|
|
||||||
self.pduid_pdu.insert(
|
self.pduid_pdu.insert(
|
||||||
&pdu_id,
|
&pdu_id,
|
||||||
|
@ -521,8 +519,8 @@ impl Rooms {
|
||||||
)
|
)
|
||||||
})?,
|
})?,
|
||||||
&pdu.sender,
|
&pdu.sender,
|
||||||
account_data,
|
&db.account_data,
|
||||||
globals,
|
&db.globals,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -540,10 +538,10 @@ impl Rooms {
|
||||||
self.tokenids.insert(key, &[])?;
|
self.tokenids.insert(key, &[])?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if body.starts_with(&format!("@conduit:{}: ", globals.server_name()))
|
if body.starts_with(&format!("@conduit:{}: ", db.globals.server_name()))
|
||||||
&& self
|
&& self
|
||||||
.id_from_alias(
|
.id_from_alias(
|
||||||
&format!("#admins:{}", globals.server_name())
|
&format!("#admins:{}", db.globals.server_name())
|
||||||
.try_into()
|
.try_into()
|
||||||
.expect("#admins:server_name is a valid room alias"),
|
.expect("#admins:server_name is a valid room alias"),
|
||||||
)?
|
)?
|
||||||
|
@ -570,10 +568,11 @@ impl Rooms {
|
||||||
);
|
);
|
||||||
match parsed_config {
|
match parsed_config {
|
||||||
Ok(yaml) => {
|
Ok(yaml) => {
|
||||||
admin.send(AdminCommand::RegisterAppservice(yaml));
|
db.admin
|
||||||
|
.send(AdminCommand::RegisterAppservice(yaml));
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
admin.send(AdminCommand::SendMessage(
|
db.admin.send(AdminCommand::SendMessage(
|
||||||
message::MessageEventContent::text_plain(
|
message::MessageEventContent::text_plain(
|
||||||
format!(
|
format!(
|
||||||
"Could not parse appservice config: {}",
|
"Could not parse appservice config: {}",
|
||||||
|
@ -584,7 +583,7 @@ impl Rooms {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
admin.send(AdminCommand::SendMessage(
|
db.admin.send(AdminCommand::SendMessage(
|
||||||
message::MessageEventContent::text_plain(
|
message::MessageEventContent::text_plain(
|
||||||
"Expected code block in command body.",
|
"Expected code block in command body.",
|
||||||
),
|
),
|
||||||
|
@ -592,10 +591,10 @@ impl Rooms {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"list_appservices" => {
|
"list_appservices" => {
|
||||||
admin.send(AdminCommand::ListAppservices);
|
db.admin.send(AdminCommand::ListAppservices);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
admin.send(AdminCommand::SendMessage(
|
db.admin.send(AdminCommand::SendMessage(
|
||||||
message::MessageEventContent::text_plain(format!(
|
message::MessageEventContent::text_plain(format!(
|
||||||
"Command: {}, Args: {:?}",
|
"Command: {}, Args: {:?}",
|
||||||
command, args
|
command, args
|
||||||
|
@ -696,17 +695,12 @@ impl Rooms {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new persisted data unit and adds it to a room.
|
/// Creates a new persisted data unit and adds it to a room.
|
||||||
#[allow(clippy::too_many_arguments)]
|
|
||||||
pub fn build_and_append_pdu(
|
pub fn build_and_append_pdu(
|
||||||
&self,
|
&self,
|
||||||
pdu_builder: PduBuilder,
|
pdu_builder: PduBuilder,
|
||||||
sender: &UserId,
|
sender: &UserId,
|
||||||
room_id: &RoomId,
|
room_id: &RoomId,
|
||||||
globals: &super::globals::Globals,
|
db: &Database,
|
||||||
sending: &super::sending::Sending,
|
|
||||||
admin: &super::admin::Admin,
|
|
||||||
account_data: &super::account_data::AccountData,
|
|
||||||
appservice: &super::appservice::Appservice,
|
|
||||||
) -> Result<EventId> {
|
) -> Result<EventId> {
|
||||||
let PduBuilder {
|
let PduBuilder {
|
||||||
event_type,
|
event_type,
|
||||||
|
@ -789,7 +783,7 @@ impl Rooms {
|
||||||
if !match event_type {
|
if !match event_type {
|
||||||
EventType::RoomEncryption => {
|
EventType::RoomEncryption => {
|
||||||
// Only allow encryption events if it's allowed in the config
|
// Only allow encryption events if it's allowed in the config
|
||||||
globals.allow_encryption()
|
db.globals.allow_encryption()
|
||||||
}
|
}
|
||||||
EventType::RoomMember => {
|
EventType::RoomMember => {
|
||||||
let prev_event = self
|
let prev_event = self
|
||||||
|
@ -895,13 +889,13 @@ impl Rooms {
|
||||||
// Add origin because synapse likes that (and it's required in the spec)
|
// Add origin because synapse likes that (and it's required in the spec)
|
||||||
pdu_json.insert(
|
pdu_json.insert(
|
||||||
"origin".to_owned(),
|
"origin".to_owned(),
|
||||||
to_canonical_value(globals.server_name())
|
to_canonical_value(db.globals.server_name())
|
||||||
.expect("server name is a valid CanonicalJsonValue"),
|
.expect("server name is a valid CanonicalJsonValue"),
|
||||||
);
|
);
|
||||||
|
|
||||||
ruma::signatures::hash_and_sign_event(
|
ruma::signatures::hash_and_sign_event(
|
||||||
globals.server_name().as_str(),
|
db.globals.server_name().as_str(),
|
||||||
globals.keypair(),
|
db.globals.keypair(),
|
||||||
&mut pdu_json,
|
&mut pdu_json,
|
||||||
&RoomVersionId::Version6,
|
&RoomVersionId::Version6,
|
||||||
)
|
)
|
||||||
|
@ -922,24 +916,16 @@ impl Rooms {
|
||||||
|
|
||||||
// Increment the last index and use that
|
// Increment the last index and use that
|
||||||
// This is also the next_batch/since value
|
// This is also the next_batch/since value
|
||||||
let count = globals.next_count()?;
|
let count = db.globals.next_count()?;
|
||||||
let mut pdu_id = room_id.as_bytes().to_vec();
|
let mut pdu_id = room_id.as_bytes().to_vec();
|
||||||
pdu_id.push(0xff);
|
pdu_id.push(0xff);
|
||||||
pdu_id.extend_from_slice(&count.to_be_bytes());
|
pdu_id.extend_from_slice(&count.to_be_bytes());
|
||||||
|
|
||||||
// We append to state before appending the pdu, so we don't have a moment in time with the
|
// We append to state before appending the pdu, so we don't have a moment in time with the
|
||||||
// pdu without it's state. This is okay because append_pdu can't fail.
|
// pdu without it's state. This is okay because append_pdu can't fail.
|
||||||
let statehashid = self.append_to_state(&pdu_id, &pdu, &globals)?;
|
let statehashid = self.append_to_state(&pdu_id, &pdu, &db.globals)?;
|
||||||
|
|
||||||
self.append_pdu(
|
self.append_pdu(&pdu, pdu_json, count, pdu_id.clone().into(), db)?;
|
||||||
&pdu,
|
|
||||||
pdu_json,
|
|
||||||
count,
|
|
||||||
pdu_id.clone().into(),
|
|
||||||
globals,
|
|
||||||
account_data,
|
|
||||||
admin,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// We set the room state after inserting the pdu, so that we never have a moment in time
|
// We set the room state after inserting the pdu, so that we never have a moment in time
|
||||||
// where events in the current room state do not exist
|
// where events in the current room state do not exist
|
||||||
|
@ -948,31 +934,28 @@ impl Rooms {
|
||||||
for server in self
|
for server in self
|
||||||
.room_servers(room_id)
|
.room_servers(room_id)
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
.filter(|server| &**server != globals.server_name())
|
.filter(|server| &**server != db.globals.server_name())
|
||||||
{
|
{
|
||||||
sending.send_pdu(&server, &pdu_id)?;
|
db.sending.send_pdu(&server, &pdu_id)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for appservice in appservice.iter_all().filter_map(|r| r.ok()) {
|
for appservice in db.appservice.iter_all().filter_map(|r| r.ok()) {
|
||||||
if let Some(namespaces) = appservice.1.get("namespaces") {
|
if let Some(namespaces) = appservice.1.get("namespaces") {
|
||||||
let users = namespaces
|
let users = namespaces
|
||||||
.get("users")
|
.get("users")
|
||||||
.and_then(|users| users.as_sequence())
|
.and_then(|users| users.as_sequence())
|
||||||
.map_or_else(
|
.map_or_else(Vec::new, |users| {
|
||||||
|| Vec::new(),
|
users
|
||||||
|users| {
|
.iter()
|
||||||
users
|
.map(|users| {
|
||||||
.iter()
|
users
|
||||||
.map(|users| {
|
.get("regex")
|
||||||
users
|
.and_then(|regex| regex.as_str())
|
||||||
.get("regex")
|
.and_then(|regex| Regex::new(regex).ok())
|
||||||
.and_then(|regex| regex.as_str())
|
})
|
||||||
.and_then(|regex| Regex::new(regex).ok())
|
.filter_map(|o| o)
|
||||||
})
|
.collect::<Vec<_>>()
|
||||||
.filter_map(|o| o)
|
});
|
||||||
.collect::<Vec<_>>()
|
|
||||||
},
|
|
||||||
);
|
|
||||||
let aliases = namespaces
|
let aliases = namespaces
|
||||||
.get("aliases")
|
.get("aliases")
|
||||||
.and_then(|users| users.get("regex"))
|
.and_then(|users| users.get("regex"))
|
||||||
|
@ -989,25 +972,31 @@ impl Rooms {
|
||||||
.get("sender_localpart")
|
.get("sender_localpart")
|
||||||
.and_then(|string| string.as_str())
|
.and_then(|string| string.as_str())
|
||||||
.and_then(|string| {
|
.and_then(|string| {
|
||||||
UserId::parse_with_server_name(string, globals.server_name()).ok()
|
UserId::parse_with_server_name(string, db.globals.server_name()).ok()
|
||||||
});
|
});
|
||||||
|
|
||||||
if bridge_user_id.map_or(false, |bridge_user_id| {
|
let user_is_joined =
|
||||||
self.is_joined(&bridge_user_id, room_id).unwrap_or(false)
|
|bridge_user_id| self.is_joined(&bridge_user_id, room_id).unwrap_or(false);
|
||||||
}) || users.iter().any(|users| {
|
let matching_users = |users: &Regex| {
|
||||||
users.is_match(pdu.sender.as_str())
|
users.is_match(pdu.sender.as_str())
|
||||||
|| pdu.kind == EventType::RoomMember
|
|| pdu.kind == EventType::RoomMember
|
||||||
&& pdu
|
&& pdu
|
||||||
.state_key
|
.state_key
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(false, |state_key| users.is_match(&state_key))
|
.map_or(false, |state_key| users.is_match(&state_key))
|
||||||
}) || aliases.map_or(false, |aliases| {
|
};
|
||||||
|
let matching_aliases = |aliases: Regex| {
|
||||||
room_aliases
|
room_aliases
|
||||||
.filter_map(|r| r.ok())
|
.filter_map(|r| r.ok())
|
||||||
.any(|room_alias| aliases.is_match(room_alias.as_str()))
|
.any(|room_alias| aliases.is_match(room_alias.as_str()))
|
||||||
}) || rooms.map_or(false, |rooms| rooms.contains(&room_id.as_str().into()))
|
};
|
||||||
|
|
||||||
|
if bridge_user_id.map_or(false, user_is_joined)
|
||||||
|
|| users.iter().any(matching_users)
|
||||||
|
|| aliases.map_or(false, matching_aliases)
|
||||||
|
|| rooms.map_or(false, |rooms| rooms.contains(&room_id.as_str().into()))
|
||||||
{
|
{
|
||||||
sending.send_pdu_appservice(&appservice.0, &pdu_id)?;
|
db.sending.send_pdu_appservice(&appservice.0, &pdu_id)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,6 +148,15 @@ impl Sending {
|
||||||
let servernamepduid = key.clone();
|
let servernamepduid = key.clone();
|
||||||
let mut parts = servernamepduid.splitn(2, |&b| b == 0xff);
|
let mut parts = servernamepduid.splitn(2, |&b| b == 0xff);
|
||||||
|
|
||||||
|
let exponential_backoff = |(tries, instant): &(u32, Instant)| {
|
||||||
|
// Fail if a request has failed recently (exponential backoff)
|
||||||
|
let mut min_elapsed_duration = Duration::from_secs(60) * (*tries) * (*tries);
|
||||||
|
if min_elapsed_duration > Duration::from_secs(60*60*24) {
|
||||||
|
min_elapsed_duration = Duration::from_secs(60*60*24);
|
||||||
|
}
|
||||||
|
|
||||||
|
instant.elapsed() < min_elapsed_duration
|
||||||
|
};
|
||||||
if let Some((server, is_appservice, pdu_id)) = utils::string_from_bytes(
|
if let Some((server, is_appservice, pdu_id)) = utils::string_from_bytes(
|
||||||
parts
|
parts
|
||||||
.next()
|
.next()
|
||||||
|
@ -172,15 +181,7 @@ impl Sending {
|
||||||
.map(|pdu_id| (server, is_appservice, pdu_id))
|
.map(|pdu_id| (server, is_appservice, pdu_id))
|
||||||
)
|
)
|
||||||
.filter(|(server, is_appservice, _)| {
|
.filter(|(server, is_appservice, _)| {
|
||||||
if last_failed_try.get(server).map_or(false, |(tries, instant)| {
|
if last_failed_try.get(server).map_or(false, exponential_backoff) {
|
||||||
// Fail if a request has failed recently (exponential backoff)
|
|
||||||
let mut min_elapsed_duration = Duration::from_secs(60) * *tries * *tries;
|
|
||||||
if min_elapsed_duration > Duration::from_secs(60*60*24) {
|
|
||||||
min_elapsed_duration = Duration::from_secs(60*60*24);
|
|
||||||
}
|
|
||||||
|
|
||||||
instant.elapsed() < min_elapsed_duration
|
|
||||||
}) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,10 +121,12 @@ impl log::Log for ConduitLogger {
|
||||||
fn log(&self, record: &log::Record<'_>) {
|
fn log(&self, record: &log::Record<'_>) {
|
||||||
let output = format!("{} - {}", record.level(), record.args());
|
let output = format!("{} - {}", record.level(), record.args());
|
||||||
|
|
||||||
|
let match_mod_path =
|
||||||
|
|path: &str| path.starts_with("conduit::") || path.starts_with("state");
|
||||||
|
|
||||||
if self.enabled(record.metadata())
|
if self.enabled(record.metadata())
|
||||||
&& (record.module_path().map_or(false, |path| {
|
&& (record.module_path().map_or(false, match_mod_path)
|
||||||
path.starts_with("conduit::") || path.starts_with("state")
|
|| record
|
||||||
}) || record
|
|
||||||
.module_path()
|
.module_path()
|
||||||
.map_or(true, |path| !path.starts_with("rocket::")) // Rockets logs are annoying
|
.map_or(true, |path| !path.starts_with("rocket::")) // Rockets logs are annoying
|
||||||
&& record.metadata().level() <= log::Level::Warn)
|
&& record.metadata().level() <= log::Level::Warn)
|
||||||
|
|
|
@ -1113,9 +1113,7 @@ fn append_state(db: &Database, pdu: &PduEvent) -> Result<()> {
|
||||||
utils::to_canonical_object(pdu).expect("Pdu is valid canonical object"),
|
utils::to_canonical_object(pdu).expect("Pdu is valid canonical object"),
|
||||||
count,
|
count,
|
||||||
pdu_id.clone().into(),
|
pdu_id.clone().into(),
|
||||||
&db.globals,
|
&db,
|
||||||
&db.account_data,
|
|
||||||
&db.admin,
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
// We set the room state after inserting the pdu, so that we never have a moment in time
|
// We set the room state after inserting the pdu, so that we never have a moment in time
|
||||||
|
|
Loading…
Reference in a new issue