forked from jmug/stoatchat
Servers: Route for kicking a member.
This commit is contained in:
@@ -258,4 +258,30 @@ impl Server {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn remove_member(&self, id: &str) -> Result<()> {
|
||||
get_collection("server_members")
|
||||
.delete_one(
|
||||
doc! {
|
||||
"_id": {
|
||||
"server": &self.id,
|
||||
"user": &id
|
||||
}
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "delete_one",
|
||||
with: "server_members",
|
||||
})?;
|
||||
|
||||
ClientboundNotification::ServerMemberLeave {
|
||||
id: self.id.clone(),
|
||||
user: id.to_string()
|
||||
}
|
||||
.publish(self.id.clone());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ pub enum RelationshipStatus {
|
||||
BlockedOther,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Relationship {
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
pub status: RelationshipStatus,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub enum Presence {
|
||||
Online,
|
||||
Idle,
|
||||
@@ -43,7 +43,7 @@ pub enum Presence {
|
||||
Invisible,
|
||||
}
|
||||
|
||||
#[derive(Validate, Serialize, Deserialize, Debug)]
|
||||
#[derive(Validate, Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct UserStatus {
|
||||
#[validate(length(min = 1, max = 128))]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@@ -52,7 +52,7 @@ pub struct UserStatus {
|
||||
pub presence: Option<Presence>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct UserProfile {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub content: Option<String>,
|
||||
@@ -72,7 +72,7 @@ pub enum Badges {
|
||||
impl_op_ex_commutative!(+ |a: &i32, b: &Badges| -> i32 { *a | *b as i32 });
|
||||
|
||||
// When changing this struct, update notifications/payload.rs#80
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct User {
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
|
||||
@@ -9,7 +9,8 @@ use std::ops;
|
||||
#[repr(u32)]
|
||||
pub enum ServerPermission {
|
||||
View = 0b00000000000000000000000000000001, // 1
|
||||
// 2 bits of space
|
||||
ManageMembers = 0b00000000000000000000000000000010, // 2
|
||||
ManageChannels = 0b00000000000000000000000000000100, // 4
|
||||
ManageServer = 0b00000000000000000000000000001000, // 8
|
||||
// 8 bits of space
|
||||
ChangeNickname = 0b00000000000000000001000000000000, // 4096
|
||||
@@ -26,6 +27,8 @@ bitfield! {
|
||||
pub struct ServerPermissions(MSB0 [u32]);
|
||||
u32;
|
||||
pub get_view, _: 31;
|
||||
pub get_manage_members, _: 30;
|
||||
pub get_manage_channels, _: 29;
|
||||
pub get_manage_server, _: 28;
|
||||
|
||||
pub get_change_nickname, _: 19;
|
||||
|
||||
Reference in New Issue
Block a user