forked from jmug/stoatchat
Servers: Add invites. Create, view and join.
This commit is contained in:
@@ -15,7 +15,8 @@ pub async fn req(user: User, target: Ref, member: Ref) -> Result<()> {
|
||||
.with_channel(&channel)
|
||||
.for_channel()
|
||||
.await?;
|
||||
if !perm.get_view() {
|
||||
|
||||
if !perm.get_invite_others() {
|
||||
Err(Error::MissingPermission)?
|
||||
}
|
||||
|
||||
|
||||
46
src/routes/channels/invite_channel.rs
Normal file
46
src/routes/channels/invite_channel.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use nanoid::nanoid;
|
||||
use rocket_contrib::json::JsonValue;
|
||||
|
||||
lazy_static! {
|
||||
static ref ALPHABET: [char; 54] = [
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
|
||||
'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'
|
||||
];
|
||||
}
|
||||
|
||||
#[post("/<target>/invite")]
|
||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
let target = target.fetch_channel().await?;
|
||||
let perm = permissions::PermissionCalculator::new(&user)
|
||||
.with_channel(&target)
|
||||
.for_channel()
|
||||
.await?;
|
||||
|
||||
if !perm.get_invite_others() {
|
||||
return Err(Error::MissingPermission);
|
||||
}
|
||||
|
||||
let code = nanoid!(8, &*ALPHABET);
|
||||
match &target {
|
||||
Channel::Group { .. } => {
|
||||
unimplemented!()
|
||||
}
|
||||
Channel::TextChannel { id, .. } => {
|
||||
Invite::Server {
|
||||
code: code.clone(),
|
||||
creator: user.id,
|
||||
channel: id.clone(),
|
||||
}
|
||||
.save()
|
||||
.await?;
|
||||
|
||||
Ok(json!({ "code": code }))
|
||||
}
|
||||
_ => Err(Error::InvalidOperation),
|
||||
}
|
||||
}
|
||||
@@ -18,8 +18,9 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
|
||||
let target = target.fetch_channel().await?;
|
||||
match target {
|
||||
Channel::SavedMessages { .. }
|
||||
| Channel::TextChannel { .. } => return Err(Error::CannotJoinCall),
|
||||
Channel::SavedMessages { .. } | Channel::TextChannel { .. } => {
|
||||
return Err(Error::CannotJoinCall)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ mod fetch_members;
|
||||
mod group_add_member;
|
||||
mod group_create;
|
||||
mod group_remove_member;
|
||||
mod invite_channel;
|
||||
mod join_call;
|
||||
mod message_delete;
|
||||
mod message_edit;
|
||||
@@ -21,6 +22,7 @@ pub fn routes() -> Vec<Route> {
|
||||
fetch_members::req,
|
||||
delete_channel::req,
|
||||
edit_channel::req,
|
||||
invite_channel::req,
|
||||
message_send::req,
|
||||
message_query::req,
|
||||
message_query_stale::req,
|
||||
|
||||
Reference in New Issue
Block a user