Servers: Create and delete invites. Create and fetch servers.

This commit is contained in:
Paul
2021-06-05 22:41:47 +01:00
parent 681b2b8ab6
commit f9fbe54b17
16 changed files with 281 additions and 57 deletions

View File

@@ -11,6 +11,7 @@ pub async fn req(user: User, target: Ref) -> Result<()> {
.with_channel(&target)
.for_channel()
.await?;
if !perm.get_view() {
Err(Error::MissingPermission)?
}

View File

@@ -45,7 +45,8 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
}
match &target {
Channel::Group { id, icon, .. } => {
Channel::Group { id, icon, .. } |
Channel::TextChannel { id, icon, .. } => {
let mut set = doc! {};
let mut unset = doc! {};
@@ -107,42 +108,44 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
}
.publish(id.clone());
if let Some(name) = data.name {
Message::create(
"00000000000000000000000000".to_string(),
id.clone(),
Content::SystemMessage(SystemMessage::ChannelRenamed {
name,
by: user.id.clone(),
}),
)
.publish(&target)
.await
.ok();
}
if let Channel::Group { .. } = &target {
if let Some(name) = data.name {
Message::create(
"00000000000000000000000000".to_string(),
id.clone(),
Content::SystemMessage(SystemMessage::ChannelRenamed {
name,
by: user.id.clone(),
}),
)
.publish(&target)
.await
.ok();
}
if let Some(_) = data.description {
Message::create(
"00000000000000000000000000".to_string(),
id.clone(),
Content::SystemMessage(SystemMessage::ChannelDescriptionChanged {
by: user.id.clone(),
}),
)
.publish(&target)
.await
.ok();
}
if let Some(_) = data.description {
Message::create(
"00000000000000000000000000".to_string(),
id.clone(),
Content::SystemMessage(SystemMessage::ChannelDescriptionChanged {
by: user.id.clone(),
}),
)
.publish(&target)
.await
.ok();
}
if let Some(_) = data.icon {
Message::create(
"00000000000000000000000000".to_string(),
id.clone(),
Content::SystemMessage(SystemMessage::ChannelIconChanged { by: user.id }),
)
.publish(&target)
.await
.ok();
if let Some(_) = data.icon {
Message::create(
"00000000000000000000000000".to_string(),
id.clone(),
Content::SystemMessage(SystemMessage::ChannelIconChanged { by: user.id }),
)
.publish(&target)
.await
.ok();
}
}
if remove_icon {

View File

@@ -11,6 +11,7 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
.with_channel(&target)
.for_channel()
.await?;
if !perm.get_view() {
Err(Error::MissingPermission)?
}

View File

@@ -13,7 +13,7 @@ lazy_static! {
];
}
#[post("/<target>/invite")]
#[post("/<target>/invites")]
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
let target = target.fetch_channel().await?;
let perm = permissions::PermissionCalculator::new(&user)
@@ -30,10 +30,11 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
Channel::Group { .. } => {
unimplemented!()
}
Channel::TextChannel { id, .. } => {
Channel::TextChannel { id, server, .. } => {
Invite::Server {
code: code.clone(),
creator: user.id,
server: server.clone(),
channel: id.clone(),
}
.save()

View File

@@ -7,7 +7,7 @@ mod fetch_members;
mod group_add_member;
mod group_create;
mod group_remove_member;
mod invite_channel;
mod invite_create;
mod join_call;
mod message_delete;
mod message_edit;
@@ -22,7 +22,7 @@ pub fn routes() -> Vec<Route> {
fetch_members::req,
delete_channel::req,
edit_channel::req,
invite_channel::req,
invite_create::req,
message_send::req,
message_query::req,
message_query_stale::req,