feat: reimplement system messages

This commit is contained in:
Paul Makles
2022-04-21 16:36:59 +01:00
parent 5ce0c133e8
commit da08a7d722
5 changed files with 50 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
use revolt_quark::{
models::{
channel::{Channel, FieldsChannel, PartialChannel},
message::SystemMessage,
File, User,
},
perms, Database, Error, Permission, Ref, Result,
@@ -129,6 +130,38 @@ pub async fn req(
partial.nsfw = Some(new_nsfw);
}
// Send out mutation system messages.
if let Channel::Group { .. } = &channel {
if let Some(name) = &partial.name {
SystemMessage::ChannelRenamed {
name: name.to_string(),
by: user.id.clone(),
}
.into_message(channel.id().to_string())
.create(db, &channel, None)
.await
.ok();
}
if partial.description.is_some() {
SystemMessage::ChannelDescriptionChanged {
by: user.id.clone(),
}
.into_message(channel.id().to_string())
.create(db, &channel, None)
.await
.ok();
}
if partial.icon.is_some() {
SystemMessage::ChannelIconChanged { by: user.id }
.into_message(channel.id().to_string())
.create(db, &channel, None)
.await
.ok();
}
}
channel
.update(db, partial, data.remove.unwrap_or_default())
.await?;

View File

@@ -9,7 +9,7 @@ use revolt_quark::{
#[openapi(tag = "Groups")]
#[put("/<target>/recipients/<member>")]
pub async fn req(db: &Db, user: User, target: Ref, member: Ref) -> Result<EmptyResponse> {
let channel = target.as_channel(db).await?;
let mut channel = target.as_channel(db).await?;
perms(&user)
.channel(&channel)
.throw_permission_and_view_channel(db, Permission::InviteOthers)