Channels: Make sure to delete last, to keep integrity.

This commit is contained in:
Paul
2021-06-16 15:42:46 +01:00
parent c4b39c56d4
commit 9a2ccecb89

View File

@@ -189,19 +189,6 @@ impl Channel {
with: "messages",
})?;
get_collection("channels")
.delete_one(
doc! {
"_id": id
},
None,
)
.await
.map_err(|_| Error::DatabaseError {
operation: "delete_one",
with: "channel",
})?;
// Remove from server object.
if let Channel::TextChannel { server, .. } = &self {
let server = Ref::from_unchecked(server.clone()).fetch_server().await?;
@@ -258,6 +245,20 @@ impl Channel {
})?;
}
// Finally, delete the channel object.
get_collection("channels")
.delete_one(
doc! {
"_id": id
},
None,
)
.await
.map_err(|_| Error::DatabaseError {
operation: "delete_one",
with: "channel",
})?;
ClientboundNotification::ChannelDelete { id: id.to_string() }.publish(id.to_string());
if let Channel::Group { icon, .. } = self {