diff --git a/src/database/entities/channel.rs b/src/database/entities/channel.rs index d110fa8a66c770ccd900855d3385c36aad7f65e3..0ab74fc6bb23019769c7e10a904d61c9d9a79e2b 100644 --- a/src/database/entities/channel.rs +++ b/src/database/entities/channel.rs @@ -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 {