more stuff

This commit is contained in:
Zomatree
2024-04-24 02:23:52 +01:00
parent 7a4421089c
commit 67569f932e
11 changed files with 254 additions and 79 deletions

View File

@@ -19,7 +19,7 @@ struct MigrationInfo {
revision: i32,
}
pub const LATEST_REVISION: i32 = 26;
pub const LATEST_REVISION: i32 = 27;
pub async fn migrate_database(db: &MongoDb) {
let migrations = db.col::<Document>("migrations");
@@ -983,6 +983,24 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
.expect("Failed to create ratelimit_events index.");
}
if revision <= 26 {
info!("Running migration [revision 26 / 17-04-2024]: Add `can_publish` and `can_receive` to members");
db.col::<Document>("server_members")
.update_many(
doc! {},
doc! {
"$set": {
"can_publish": true,
"can_receive": true
}
},
None
)
.await
.expect("Failed to update members");
}
// Need to migrate fields on attachments, change `user_id`, `object_id`, etc to `parent`.
// Reminder to update LATEST_REVISION when adding new migrations.

View File

@@ -3,8 +3,8 @@ use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
use revolt_result::{create_error, Result};
use crate::{
events::client::EventV1, util::permissions::DatabasePermissionQuery, Channel, Database, File,
Server, SystemMessage, User,
events::client::EventV1, if_false, util::permissions::DatabasePermissionQuery, Channel,
Database, File, Server, SystemMessage, User,
};
auto_derived_partial!(
@@ -30,6 +30,13 @@ auto_derived_partial!(
/// Timestamp this member is timed out until
#[serde(skip_serializing_if = "Option::is_none")]
pub timeout: Option<Timestamp>,
/// Whether the member is server-wide voice muted
#[serde(skip_serializing_if = "if_false")]
pub can_publish: bool,
/// Whether the member is server-wide voice deafened
#[serde(skip_serializing_if = "if_false")]
pub can_receive: bool,
},
"PartialMember"
);
@@ -69,6 +76,8 @@ impl Default for Member {
avatar: None,
roles: vec![],
timeout: None,
can_publish: false,
can_receive: false,
}
}
}

View File

@@ -186,7 +186,7 @@ impl From<crate::Channel> for Channel {
default_permissions,
role_permissions,
nsfw,
voice
voice,
} => Channel::TextChannel {
id,
server,
@@ -197,7 +197,7 @@ impl From<crate::Channel> for Channel {
default_permissions,
role_permissions,
nsfw,
voice
voice,
},
crate::Channel::VoiceChannel {
id,
@@ -268,7 +268,7 @@ impl From<Channel> for crate::Channel {
default_permissions,
role_permissions,
nsfw,
voice
voice,
} => crate::Channel::TextChannel {
id,
server,
@@ -279,7 +279,7 @@ impl From<Channel> for crate::Channel {
default_permissions,
role_permissions,
nsfw,
voice
voice,
},
Channel::VoiceChannel {
id,
@@ -614,6 +614,8 @@ impl From<crate::Member> for Member {
avatar: value.avatar.map(|f| f.into()),
roles: value.roles,
timeout: value.timeout,
can_publish: value.can_publish,
can_receive: value.can_receive,
}
}
}
@@ -627,6 +629,8 @@ impl From<Member> for crate::Member {
avatar: value.avatar.map(|f| f.into()),
roles: value.roles,
timeout: value.timeout,
can_publish: value.can_publish,
can_receive: value.can_receive,
}
}
}
@@ -640,6 +644,8 @@ impl From<crate::PartialMember> for PartialMember {
avatar: value.avatar.map(|f| f.into()),
roles: value.roles,
timeout: value.timeout,
can_publish: value.can_publish,
can_receive: value.can_receive,
}
}
}
@@ -653,6 +659,8 @@ impl From<PartialMember> for crate::PartialMember {
avatar: value.avatar.map(|f| f.into()),
roles: value.roles,
timeout: value.timeout,
can_publish: value.can_publish,
can_receive: value.can_receive,
}
}
}

View File

@@ -1,6 +1,7 @@
use std::collections::HashMap;
use super::{File, Role, User};
use crate::if_false;
use iso8601_timestamp::Timestamp;
use once_cell::sync::Lazy;
@@ -57,6 +58,13 @@ auto_derived_partial!(
/// Timestamp this member is timed out until
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
pub timeout: Option<Timestamp>,
/// Whether the member is server-wide voice muted
#[serde(skip_serializing_if = "if_false")]
pub can_publish: bool,
/// Whether the member is server-wide voice deafened
#[serde(skip_serializing_if = "if_false")]
pub can_receive: bool,
},
"PartialMember"
);
@@ -126,5 +134,9 @@ auto_derived!(
/// Fields to remove from channel object
#[cfg_attr(feature = "validator", validate(length(min = 1)))]
pub remove: Option<Vec<FieldsMember>>,
/// server-wide voice muted
pub can_publish: Option<bool>,
/// server-wide voice deafened
pub can_receive: Option<bool>,
}
);

View File

@@ -276,10 +276,10 @@ auto_derived_partial!(
/// Voice State information for a user
pub struct UserVoiceState {
pub id: String,
pub audio: bool,
pub deafened: bool,
pub can_receive: bool,
pub can_publish: bool,
pub screensharing: bool,
pub camera: bool
pub camera: bool,
},
"PartialUserVoiceState"
);

View File

@@ -1,3 +1,5 @@
use std::panic::Location;
#[cfg(feature = "serde")]
#[macro_use]
extern crate serde;
@@ -172,6 +174,37 @@ macro_rules! query {
};
}
pub trait ToRevoltError<T> {
#[track_caller]
fn to_internal_error(self) -> Result<T, Error>;
}
impl<T, E> ToRevoltError<T> for Result<T, E> {
fn to_internal_error(self) -> Result<T, Error> {
self.map_err(|_| {
let loc = Location::caller();
Error {
error_type: ErrorType::InternalError,
location: format!("{}:{}:{}", loc.file(), loc.line(), loc.column())
}
})
}
}
impl<T> ToRevoltError<T> for Option<T> {
fn to_internal_error(self) -> Result<T, Error> {
self.ok_or_else(|| {
let loc = Location::caller();
Error {
error_type: ErrorType::InternalError,
location: format!("{}:{}:{}", loc.file(), loc.line(), loc.column())
}
})
}
}
#[cfg(test)]
mod tests {
use crate::ErrorType;