forked from jmug/stoatchat
refactor: Remove VoiceChannel
This commit is contained in:
@@ -18,6 +18,7 @@ use super::state::{Cache, State};
|
|||||||
impl Cache {
|
impl Cache {
|
||||||
/// Check whether the current user can view a channel
|
/// Check whether the current user can view a channel
|
||||||
pub async fn can_view_channel(&self, db: &Database, channel: &Channel) -> bool {
|
pub async fn can_view_channel(&self, db: &Database, channel: &Channel) -> bool {
|
||||||
|
#[allow(deprecated)]
|
||||||
match &channel {
|
match &channel {
|
||||||
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => {
|
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => {
|
||||||
let member = self.members.get(server);
|
let member = self.members.get(server);
|
||||||
@@ -284,6 +285,7 @@ impl State {
|
|||||||
|
|
||||||
let id = &id.to_string();
|
let id = &id.to_string();
|
||||||
for (channel_id, channel) in &self.cache.channels {
|
for (channel_id, channel) in &self.cache.channels {
|
||||||
|
#[allow(deprecated)]
|
||||||
match channel {
|
match channel {
|
||||||
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => {
|
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => {
|
||||||
if server == id {
|
if server == id {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ struct MigrationInfo {
|
|||||||
revision: i32,
|
revision: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const LATEST_REVISION: i32 = 31;
|
pub const LATEST_REVISION: i32 = 33;
|
||||||
|
|
||||||
pub async fn migrate_database(db: &MongoDb) {
|
pub async fn migrate_database(db: &MongoDb) {
|
||||||
let migrations = db.col::<Document>("migrations");
|
let migrations = db.col::<Document>("migrations");
|
||||||
@@ -1185,6 +1185,7 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
for webhook in webhooks {
|
for webhook in webhooks {
|
||||||
|
#[allow(deprecated)]
|
||||||
match db.fetch_channel(&webhook.channel_id).await {
|
match db.fetch_channel(&webhook.channel_id).await {
|
||||||
Ok(channel) => {
|
Ok(channel) => {
|
||||||
let creator_id = match channel {
|
let creator_id = match channel {
|
||||||
@@ -1246,6 +1247,24 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
|||||||
.expect("Failed to update members");
|
.expect("Failed to update members");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if revision <= 33 {
|
||||||
|
info!("Running migration [revision 33 / 29-04-2025]: Convert all `VoiceChannel`'s into `TextChannel` ");
|
||||||
|
|
||||||
|
db.col::<Document>("channels")
|
||||||
|
.update_many(
|
||||||
|
doc! { "channel_type": "VoiceChannel" },
|
||||||
|
doc! {
|
||||||
|
"$set": {
|
||||||
|
"channel_type": "TextChannel",
|
||||||
|
"voice": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("Failed to update voice channels");
|
||||||
|
};
|
||||||
|
|
||||||
// Reminder to update LATEST_REVISION when adding new migrations.
|
// Reminder to update LATEST_REVISION when adding new migrations.
|
||||||
LATEST_REVISION.max(revision)
|
LATEST_REVISION.max(revision)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ impl Invite {
|
|||||||
creator: creator.id.clone(),
|
creator: creator.id.clone(),
|
||||||
channel: id.clone(),
|
channel: id.clone(),
|
||||||
}),
|
}),
|
||||||
Channel::TextChannel { id, server, .. } | Channel::VoiceChannel { id, server, .. } => {
|
Channel::TextChannel { id, server, .. } => {
|
||||||
Ok(Invite::Server {
|
Ok(Invite::Server {
|
||||||
code,
|
code,
|
||||||
creator: creator.id.clone(),
|
creator: creator.id.clone(),
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#![allow(deprecated)]
|
||||||
use std::{borrow::Cow, collections::HashMap};
|
use std::{borrow::Cow, collections::HashMap};
|
||||||
|
|
||||||
use revolt_config::config;
|
use revolt_config::config;
|
||||||
@@ -108,7 +109,7 @@ auto_derived!(
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
voice: Option<VoiceInformation>
|
voice: Option<VoiceInformation>
|
||||||
},
|
},
|
||||||
/// Voice channel belonging to a server
|
#[deprecated = "Use TextChannel { voice } instead"]
|
||||||
VoiceChannel {
|
VoiceChannel {
|
||||||
/// Unique Id
|
/// Unique Id
|
||||||
#[serde(rename = "_id")]
|
#[serde(rename = "_id")]
|
||||||
@@ -165,6 +166,8 @@ auto_derived!(
|
|||||||
pub default_permissions: Option<OverrideField>,
|
pub default_permissions: Option<OverrideField>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub last_message_id: Option<String>,
|
pub last_message_id: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub voice: Option<VoiceInformation>
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Optional fields on channel object
|
/// Optional fields on channel object
|
||||||
@@ -225,15 +228,17 @@ impl Channel {
|
|||||||
nsfw: data.nsfw.unwrap_or(false),
|
nsfw: data.nsfw.unwrap_or(false),
|
||||||
voice: data.voice
|
voice: data.voice
|
||||||
},
|
},
|
||||||
v0::LegacyServerChannelType::Voice => Channel::VoiceChannel {
|
v0::LegacyServerChannelType::Voice => Channel::TextChannel {
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
server: server.id.to_owned(),
|
server: server.id.to_owned(),
|
||||||
name: data.name,
|
name: data.name,
|
||||||
description: data.description,
|
description: data.description,
|
||||||
icon: None,
|
icon: None,
|
||||||
|
last_message_id: None,
|
||||||
default_permissions: None,
|
default_permissions: None,
|
||||||
role_permissions: HashMap::new(),
|
role_permissions: HashMap::new(),
|
||||||
nsfw: data.nsfw.unwrap_or(false),
|
nsfw: data.nsfw.unwrap_or(false),
|
||||||
|
voice: Some(data.voice.unwrap_or_default())
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -464,12 +469,6 @@ impl Channel {
|
|||||||
server,
|
server,
|
||||||
role_permissions,
|
role_permissions,
|
||||||
..
|
..
|
||||||
}
|
|
||||||
| Channel::VoiceChannel {
|
|
||||||
id,
|
|
||||||
server,
|
|
||||||
role_permissions,
|
|
||||||
..
|
|
||||||
} => {
|
} => {
|
||||||
db.set_channel_role_permission(id, role_id, permissions)
|
db.set_channel_role_permission(id, role_id, permissions)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -516,7 +515,7 @@ impl Channel {
|
|||||||
clear: remove.into_iter().map(|v| v.into()).collect(),
|
clear: remove.into_iter().map(|v| v.into()).collect(),
|
||||||
}
|
}
|
||||||
.p(match self {
|
.p(match self {
|
||||||
Self::TextChannel { server, .. } | Self::VoiceChannel { server, .. } => server.clone(),
|
Self::TextChannel { server, .. } => server.clone(),
|
||||||
_ => id,
|
_ => id,
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
@@ -529,16 +528,14 @@ impl Channel {
|
|||||||
match field {
|
match field {
|
||||||
FieldsChannel::Description => match self {
|
FieldsChannel::Description => match self {
|
||||||
Self::Group { description, .. }
|
Self::Group { description, .. }
|
||||||
| Self::TextChannel { description, .. }
|
| Self::TextChannel { description, .. } => {
|
||||||
| Self::VoiceChannel { description, .. } => {
|
|
||||||
description.take();
|
description.take();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
FieldsChannel::Icon => match self {
|
FieldsChannel::Icon => match self {
|
||||||
Self::Group { icon, .. }
|
Self::Group { icon, .. }
|
||||||
| Self::TextChannel { icon, .. }
|
| Self::TextChannel { icon, .. } => {
|
||||||
| Self::VoiceChannel { icon, .. } => {
|
|
||||||
icon.take();
|
icon.take();
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -547,10 +544,6 @@ impl Channel {
|
|||||||
Self::TextChannel {
|
Self::TextChannel {
|
||||||
default_permissions,
|
default_permissions,
|
||||||
..
|
..
|
||||||
}
|
|
||||||
| Self::VoiceChannel {
|
|
||||||
default_permissions,
|
|
||||||
..
|
|
||||||
} => {
|
} => {
|
||||||
default_permissions.take();
|
default_permissions.take();
|
||||||
}
|
}
|
||||||
@@ -567,6 +560,7 @@ impl Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Apply partial channel to channel
|
/// Apply partial channel to channel
|
||||||
|
#[allow(deprecated)]
|
||||||
pub fn apply_options(&mut self, partial: PartialChannel) {
|
pub fn apply_options(&mut self, partial: PartialChannel) {
|
||||||
match self {
|
match self {
|
||||||
Self::SavedMessages { .. } => {}
|
Self::SavedMessages { .. } => {}
|
||||||
@@ -615,15 +609,7 @@ impl Channel {
|
|||||||
nsfw,
|
nsfw,
|
||||||
default_permissions,
|
default_permissions,
|
||||||
role_permissions,
|
role_permissions,
|
||||||
..
|
voice,
|
||||||
}
|
|
||||||
| Self::VoiceChannel {
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
icon,
|
|
||||||
nsfw,
|
|
||||||
default_permissions,
|
|
||||||
role_permissions,
|
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
if let Some(v) = partial.name {
|
if let Some(v) = partial.name {
|
||||||
@@ -649,7 +635,12 @@ impl Channel {
|
|||||||
if let Some(v) = partial.default_permissions {
|
if let Some(v) = partial.default_permissions {
|
||||||
default_permissions.replace(v);
|
default_permissions.replace(v);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if let Some(v) = partial.voice {
|
||||||
|
voice.replace(v);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Self::VoiceChannel { .. } => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ impl AbstractChannels for MongoDb {
|
|||||||
async fn delete_channel(&self, channel: &Channel) -> Result<()> {
|
async fn delete_channel(&self, channel: &Channel) -> Result<()> {
|
||||||
let id = channel.id().to_string();
|
let id = channel.id().to_string();
|
||||||
let server_id = match channel {
|
let server_id = match channel {
|
||||||
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => {
|
Channel::TextChannel { server, .. } => {
|
||||||
Some(server)
|
Some(server)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|||||||
@@ -94,9 +94,6 @@ impl AbstractChannels for ReferenceDb {
|
|||||||
match &mut channel {
|
match &mut channel {
|
||||||
Channel::TextChannel {
|
Channel::TextChannel {
|
||||||
role_permissions, ..
|
role_permissions, ..
|
||||||
}
|
|
||||||
| Channel::VoiceChannel {
|
|
||||||
role_permissions, ..
|
|
||||||
} => {
|
} => {
|
||||||
if role_permissions.get(role_id).is_some() {
|
if role_permissions.get(role_id).is_some() {
|
||||||
role_permissions.remove(role_id);
|
role_permissions.remove(role_id);
|
||||||
|
|||||||
@@ -342,6 +342,7 @@ impl Message {
|
|||||||
|
|
||||||
// Validate the mentions go to users in the channel/server
|
// Validate the mentions go to users in the channel/server
|
||||||
if !mentions.is_empty() {
|
if !mentions.is_empty() {
|
||||||
|
#[allow(deprecated)]
|
||||||
match channel {
|
match channel {
|
||||||
Channel::DirectMessage { ref recipients, .. }
|
Channel::DirectMessage { ref recipients, .. }
|
||||||
| Channel::Group { ref recipients, .. } => {
|
| Channel::Group { ref recipients, .. } => {
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ impl From<crate::FieldsWebhook> for FieldsWebhook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<crate::Channel> for Channel {
|
impl From<crate::Channel> for Channel {
|
||||||
|
#[allow(deprecated)]
|
||||||
fn from(value: crate::Channel) -> Self {
|
fn from(value: crate::Channel) -> Self {
|
||||||
match value {
|
match value {
|
||||||
crate::Channel::SavedMessages { id, user } => Channel::SavedMessages { id, user },
|
crate::Channel::SavedMessages { id, user } => Channel::SavedMessages { id, user },
|
||||||
@@ -225,6 +226,7 @@ impl From<crate::Channel> for Channel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<Channel> for crate::Channel {
|
impl From<Channel> for crate::Channel {
|
||||||
|
#[allow(deprecated)]
|
||||||
fn from(value: Channel) -> crate::Channel {
|
fn from(value: Channel) -> crate::Channel {
|
||||||
match value {
|
match value {
|
||||||
Channel::SavedMessages { id, user } => crate::Channel::SavedMessages { id, user },
|
Channel::SavedMessages { id, user } => crate::Channel::SavedMessages { id, user },
|
||||||
@@ -319,6 +321,7 @@ impl From<crate::PartialChannel> for PartialChannel {
|
|||||||
role_permissions: value.role_permissions,
|
role_permissions: value.role_permissions,
|
||||||
default_permissions: value.default_permissions,
|
default_permissions: value.default_permissions,
|
||||||
last_message_id: value.last_message_id,
|
last_message_id: value.last_message_id,
|
||||||
|
voice: value.voice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -336,6 +339,7 @@ impl From<PartialChannel> for crate::PartialChannel {
|
|||||||
role_permissions: value.role_permissions,
|
role_permissions: value.role_permissions,
|
||||||
default_permissions: value.default_permissions,
|
default_permissions: value.default_permissions,
|
||||||
last_message_id: value.last_message_id,
|
last_message_id: value.last_message_id,
|
||||||
|
voice: value.voice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,10 +121,6 @@ impl<'z> BulkDatabasePermissionQuery<'z> {
|
|||||||
Channel::TextChannel {
|
Channel::TextChannel {
|
||||||
default_permissions,
|
default_permissions,
|
||||||
..
|
..
|
||||||
}
|
|
||||||
| Channel::VoiceChannel {
|
|
||||||
default_permissions,
|
|
||||||
..
|
|
||||||
} => default_permissions.unwrap_or_default().into(),
|
} => default_permissions.unwrap_or_default().into(),
|
||||||
_ => Default::default(),
|
_ => Default::default(),
|
||||||
}
|
}
|
||||||
@@ -133,7 +129,7 @@ impl<'z> BulkDatabasePermissionQuery<'z> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code, deprecated)]
|
||||||
fn get_channel_type(&mut self) -> ChannelType {
|
fn get_channel_type(&mut self) -> ChannelType {
|
||||||
if let Some(channel) = &self.channel {
|
if let Some(channel) = &self.channel {
|
||||||
match channel {
|
match channel {
|
||||||
@@ -156,9 +152,6 @@ impl<'z> BulkDatabasePermissionQuery<'z> {
|
|||||||
match channel {
|
match channel {
|
||||||
Channel::TextChannel {
|
Channel::TextChannel {
|
||||||
role_permissions, ..
|
role_permissions, ..
|
||||||
}
|
|
||||||
| Channel::VoiceChannel {
|
|
||||||
role_permissions, ..
|
|
||||||
} => role_permissions,
|
} => role_permissions,
|
||||||
_ => panic!("Not supported for non-server channels"),
|
_ => panic!("Not supported for non-server channels"),
|
||||||
}
|
}
|
||||||
@@ -185,12 +178,6 @@ async fn calculate_members_permissions<'a>(
|
|||||||
role_permissions,
|
role_permissions,
|
||||||
default_permissions,
|
default_permissions,
|
||||||
..
|
..
|
||||||
}
|
|
||||||
| Channel::VoiceChannel {
|
|
||||||
id,
|
|
||||||
role_permissions,
|
|
||||||
default_permissions,
|
|
||||||
..
|
|
||||||
} => (id, role_permissions, default_permissions),
|
} => (id, role_permissions, default_permissions),
|
||||||
_ => panic!("Calculation of member permissions must be done on a server channel"),
|
_ => panic!("Calculation of member permissions must be done on a server channel"),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -204,6 +204,7 @@ impl PermissionQuery for DatabasePermissionQuery<'_> {
|
|||||||
// * For calculating channel permission
|
// * For calculating channel permission
|
||||||
|
|
||||||
/// Get the type of the channel
|
/// Get the type of the channel
|
||||||
|
#[allow(deprecated)]
|
||||||
async fn get_channel_type(&mut self) -> ChannelType {
|
async fn get_channel_type(&mut self) -> ChannelType {
|
||||||
if let Some(channel) = &self.channel {
|
if let Some(channel) = &self.channel {
|
||||||
match channel {
|
match channel {
|
||||||
@@ -241,14 +242,6 @@ impl PermissionQuery for DatabasePermissionQuery<'_> {
|
|||||||
| Cow::Owned(Channel::TextChannel {
|
| Cow::Owned(Channel::TextChannel {
|
||||||
default_permissions,
|
default_permissions,
|
||||||
..
|
..
|
||||||
})
|
|
||||||
| Cow::Borrowed(Channel::VoiceChannel {
|
|
||||||
default_permissions,
|
|
||||||
..
|
|
||||||
})
|
|
||||||
| Cow::Owned(Channel::VoiceChannel {
|
|
||||||
default_permissions,
|
|
||||||
..
|
|
||||||
}) => default_permissions.unwrap_or_default().into(),
|
}) => default_permissions.unwrap_or_default().into(),
|
||||||
_ => Default::default(),
|
_ => Default::default(),
|
||||||
}
|
}
|
||||||
@@ -266,12 +259,6 @@ impl PermissionQuery for DatabasePermissionQuery<'_> {
|
|||||||
})
|
})
|
||||||
| Cow::Owned(Channel::TextChannel {
|
| Cow::Owned(Channel::TextChannel {
|
||||||
role_permissions, ..
|
role_permissions, ..
|
||||||
})
|
|
||||||
| Cow::Borrowed(Channel::VoiceChannel {
|
|
||||||
role_permissions, ..
|
|
||||||
})
|
|
||||||
| Cow::Owned(Channel::VoiceChannel {
|
|
||||||
role_permissions, ..
|
|
||||||
}) => {
|
}) => {
|
||||||
if let Some(server) = &self.server {
|
if let Some(server) = &self.server {
|
||||||
let member_roles = self
|
let member_roles = self
|
||||||
@@ -361,6 +348,7 @@ impl PermissionQuery for DatabasePermissionQuery<'_> {
|
|||||||
/// (this will only ever be called for server channels, use unimplemented!() for other code paths)
|
/// (this will only ever be called for server channels, use unimplemented!() for other code paths)
|
||||||
async fn set_server_from_channel(&mut self) {
|
async fn set_server_from_channel(&mut self) {
|
||||||
if let Some(channel) = &self.channel {
|
if let Some(channel) = &self.channel {
|
||||||
|
#[allow(deprecated)]
|
||||||
match channel {
|
match channel {
|
||||||
Cow::Borrowed(Channel::TextChannel { server, .. })
|
Cow::Borrowed(Channel::TextChannel { server, .. })
|
||||||
| Cow::Owned(Channel::TextChannel { server, .. })
|
| Cow::Owned(Channel::TextChannel { server, .. })
|
||||||
|
|||||||
@@ -284,10 +284,7 @@ pub async fn get_voice_state(
|
|||||||
pub async fn get_channel_voice_state(channel: &Channel) -> Result<Option<v0::ChannelVoiceState>> {
|
pub async fn get_channel_voice_state(channel: &Channel) -> Result<Option<v0::ChannelVoiceState>> {
|
||||||
let members = get_voice_channel_members(channel.id()).await?;
|
let members = get_voice_channel_members(channel.id()).await?;
|
||||||
|
|
||||||
let server = match channel {
|
let server = channel.server();
|
||||||
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => Some(server.as_str()),
|
|
||||||
_ => None
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Some(members) = members {
|
if let Some(members) = members {
|
||||||
let mut participants = Vec::with_capacity(members.len());
|
let mut participants = Vec::with_capacity(members.len());
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ impl VoiceClient {
|
|||||||
let room = self.get_node(node)?;
|
let room = self.get_node(node)?;
|
||||||
|
|
||||||
let voice = match channel {
|
let voice = match channel {
|
||||||
Channel::DirectMessage { .. } | Channel::VoiceChannel { .. } => Some(Cow::Owned(v0::VoiceInformation::default())),
|
Channel::DirectMessage { .. } => Some(Cow::Owned(v0::VoiceInformation::default())),
|
||||||
Channel::TextChannel { voice: Some(voice), .. } => Some(Cow::Borrowed(voice)),
|
Channel::TextChannel { voice: Some(voice), .. } => Some(Cow::Borrowed(voice)),
|
||||||
_ => None
|
_ => None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#![allow(deprecated)]
|
||||||
use super::{File, UserVoiceState};
|
use super::{File, UserVoiceState};
|
||||||
|
|
||||||
use revolt_permissions::{Override, OverrideField};
|
use revolt_permissions::{Override, OverrideField};
|
||||||
@@ -112,7 +113,7 @@ auto_derived!(
|
|||||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
voice: Option<VoiceInformation>
|
voice: Option<VoiceInformation>
|
||||||
},
|
},
|
||||||
/// DEPRECATED (use TextChannel { voice }): Voice channel belonging to a server
|
#[deprecated = "Use TextChannel { voice } instead"]
|
||||||
VoiceChannel {
|
VoiceChannel {
|
||||||
/// Unique Id
|
/// Unique Id
|
||||||
#[cfg_attr(feature = "serde", serde(rename = "_id"))]
|
#[cfg_attr(feature = "serde", serde(rename = "_id"))]
|
||||||
@@ -183,6 +184,8 @@ auto_derived!(
|
|||||||
pub default_permissions: Option<OverrideField>,
|
pub default_permissions: Option<OverrideField>,
|
||||||
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
pub last_message_id: Option<String>,
|
pub last_message_id: Option<String>,
|
||||||
|
#[cfg_attr(feature = "serde", serde(skip_serializing_if = "Option::is_none"))]
|
||||||
|
pub voice: Option<VoiceInformation>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Optional fields on channel object
|
/// Optional fields on channel object
|
||||||
@@ -218,6 +221,9 @@ auto_derived!(
|
|||||||
/// Whether this channel is archived
|
/// Whether this channel is archived
|
||||||
pub archived: Option<bool>,
|
pub archived: Option<bool>,
|
||||||
|
|
||||||
|
/// Voice Information for voice channels
|
||||||
|
pub voice: Option<VoiceInformation>,
|
||||||
|
|
||||||
/// Fields to remove from channel
|
/// Fields to remove from channel
|
||||||
#[cfg_attr(feature = "serde", serde(default))]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
pub remove: Option<Vec<FieldsChannel>>,
|
pub remove: Option<Vec<FieldsChannel>>,
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ impl ApnsOutboundConsumer {
|
|||||||
// in a dm it should just be "Sendername".
|
// in a dm it should just be "Sendername".
|
||||||
// not sure how feasible all those are given the PushNotification object as it currently stands.
|
// not sure how feasible all those are given the PushNotification object as it currently stands.
|
||||||
|
|
||||||
|
#[allow(deprecated)]
|
||||||
match ¬ification.channel {
|
match ¬ification.channel {
|
||||||
Channel::DirectMessage { .. } => notification.author.clone(),
|
Channel::DirectMessage { .. } => notification.author.clone(),
|
||||||
Channel::Group { name, .. } => format!("{}, #{}", notification.author, name),
|
Channel::Group { name, .. } => format!("{}, #{}", notification.author, name),
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ impl FcmOutboundConsumer {
|
|||||||
// in a dm it should just be "Sendername".
|
// in a dm it should just be "Sendername".
|
||||||
// not sure how feasible all those are given the PushNotification object as it currently stands.
|
// not sure how feasible all those are given the PushNotification object as it currently stands.
|
||||||
|
|
||||||
|
#[allow(deprecated)]
|
||||||
match ¬ification.channel {
|
match ¬ification.channel {
|
||||||
Channel::DirectMessage { .. } => notification.author.clone(),
|
Channel::DirectMessage { .. } => notification.author.clone(),
|
||||||
Channel::Group { name, .. } => format!("{}, #{}", notification.author, name),
|
Channel::Group { name, .. } => format!("{}, #{}", notification.author, name),
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ pub async fn delete(
|
|||||||
|
|
||||||
permissions.throw_if_lacking_channel_permission(ChannelPermission::ViewChannel)?;
|
permissions.throw_if_lacking_channel_permission(ChannelPermission::ViewChannel)?;
|
||||||
|
|
||||||
|
#[allow(deprecated)]
|
||||||
match &channel {
|
match &channel {
|
||||||
Channel::SavedMessages { .. } => Err(create_error!(NoEffect))?,
|
Channel::SavedMessages { .. } => Err(create_error!(NoEffect))?,
|
||||||
Channel::DirectMessage { .. } => channel
|
Channel::DirectMessage { .. } => channel
|
||||||
|
|||||||
@@ -95,22 +95,6 @@ pub async fn edit(
|
|||||||
icon,
|
icon,
|
||||||
nsfw,
|
nsfw,
|
||||||
..
|
..
|
||||||
}
|
|
||||||
| Channel::TextChannel {
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
icon,
|
|
||||||
nsfw,
|
|
||||||
..
|
|
||||||
}
|
|
||||||
| Channel::VoiceChannel {
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
icon,
|
|
||||||
nsfw,
|
|
||||||
..
|
|
||||||
} => {
|
} => {
|
||||||
if let Some(fields) = &data.remove {
|
if let Some(fields) = &data.remove {
|
||||||
if fields.contains(&v0::FieldsChannel::Icon) {
|
if fields.contains(&v0::FieldsChannel::Icon) {
|
||||||
@@ -153,77 +137,129 @@ pub async fn edit(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send out mutation system messages.
|
// Send out mutation system messages.
|
||||||
if let Channel::Group { .. } = &channel {
|
if let Some(name) = &partial.name {
|
||||||
if let Some(name) = &partial.name {
|
SystemMessage::ChannelRenamed {
|
||||||
SystemMessage::ChannelRenamed {
|
name: name.to_string(),
|
||||||
name: name.to_string(),
|
by: user.id.clone(),
|
||||||
by: user.id.clone(),
|
}
|
||||||
|
.into_message(channel.id().to_string())
|
||||||
|
.send(
|
||||||
|
db,
|
||||||
|
Some(amqp),
|
||||||
|
user.as_author_for_system(),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
&channel,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
if partial.description.is_some() {
|
||||||
|
SystemMessage::ChannelDescriptionChanged {
|
||||||
|
by: user.id.clone(),
|
||||||
|
}
|
||||||
|
.into_message(channel.id().to_string())
|
||||||
|
.send(
|
||||||
|
db,
|
||||||
|
Some(amqp),
|
||||||
|
user.as_author_for_system(),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
&channel,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
if partial.icon.is_some() {
|
||||||
|
SystemMessage::ChannelIconChanged {
|
||||||
|
by: user.id.clone(),
|
||||||
|
}
|
||||||
|
.into_message(channel.id().to_string())
|
||||||
|
.send(
|
||||||
|
db,
|
||||||
|
Some(amqp),
|
||||||
|
user.as_author_for_system(),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
&channel,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Channel::TextChannel {
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
description,
|
||||||
|
icon,
|
||||||
|
nsfw,
|
||||||
|
voice,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
if let Some(fields) = &data.remove {
|
||||||
|
if fields.contains(&v0::FieldsChannel::Icon) {
|
||||||
|
if let Some(icon) = &icon {
|
||||||
|
db.mark_attachment_as_deleted(&icon.id).await?;
|
||||||
}
|
}
|
||||||
.into_message(channel.id().to_string())
|
|
||||||
.send(
|
|
||||||
db,
|
|
||||||
Some(amqp),
|
|
||||||
user.as_author_for_system(),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
&channel,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if partial.description.is_some() {
|
for field in fields {
|
||||||
SystemMessage::ChannelDescriptionChanged {
|
match field {
|
||||||
by: user.id.clone(),
|
v0::FieldsChannel::Description => {
|
||||||
|
description.take();
|
||||||
|
}
|
||||||
|
v0::FieldsChannel::Icon => {
|
||||||
|
icon.take();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
.into_message(channel.id().to_string())
|
|
||||||
.send(
|
|
||||||
db,
|
|
||||||
Some(amqp),
|
|
||||||
user.as_author_for_system(),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
&channel,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
if partial.icon.is_some() {
|
|
||||||
SystemMessage::ChannelIconChanged {
|
|
||||||
by: user.id.clone(),
|
|
||||||
}
|
|
||||||
.into_message(channel.id().to_string())
|
|
||||||
.send(
|
|
||||||
db,
|
|
||||||
Some(amqp),
|
|
||||||
user.as_author_for_system(),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
&channel,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.ok();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
channel
|
if let Some(icon_id) = data.icon {
|
||||||
.update(
|
partial.icon = Some(File::use_channel_icon(db, &icon_id, id, &user.id).await?);
|
||||||
db,
|
*icon = partial.icon.clone();
|
||||||
partial,
|
}
|
||||||
data.remove
|
|
||||||
.unwrap_or_default()
|
if let Some(new_name) = data.name {
|
||||||
.into_iter()
|
*name = new_name.clone();
|
||||||
.map(|f| f.into())
|
partial.name = Some(new_name);
|
||||||
.collect(),
|
}
|
||||||
)
|
|
||||||
.await?;
|
if let Some(new_description) = data.description {
|
||||||
|
partial.description = Some(new_description);
|
||||||
|
*description = partial.description.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(new_nsfw) = data.nsfw {
|
||||||
|
*nsfw = new_nsfw;
|
||||||
|
partial.nsfw = Some(new_nsfw);
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(new_voice) = data.voice {
|
||||||
|
*voice = Some(new_voice.clone());
|
||||||
|
partial.voice = Some(new_voice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_ => return Err(create_error!(InvalidOperation)),
|
_ => return Err(create_error!(InvalidOperation)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
channel
|
||||||
|
.update(
|
||||||
|
db,
|
||||||
|
partial,
|
||||||
|
data.remove
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into_iter()
|
||||||
|
.map(|f| f.into())
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(Json(channel.into()))
|
Ok(Json(channel.into()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ pub async fn query(
|
|||||||
},
|
},
|
||||||
&user,
|
&user,
|
||||||
include_users,
|
include_users,
|
||||||
|
#[allow(deprecated)]
|
||||||
match channel {
|
match channel {
|
||||||
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => {
|
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => {
|
||||||
Some(server)
|
Some(server)
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ pub async fn search(
|
|||||||
},
|
},
|
||||||
&user,
|
&user,
|
||||||
include_users,
|
include_users,
|
||||||
|
#[allow(deprecated)]
|
||||||
match channel {
|
match channel {
|
||||||
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => {
|
Channel::TextChannel { server, .. } | Channel::VoiceChannel { server, .. } => {
|
||||||
Some(server)
|
Some(server)
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ mod test {
|
|||||||
d: ChannelPermission::ViewChannel as i64,
|
d: ChannelPermission::ViewChannel as i64,
|
||||||
}),
|
}),
|
||||||
last_message_id: None,
|
last_message_id: None,
|
||||||
|
voice: None,
|
||||||
};
|
};
|
||||||
locked_channel
|
locked_channel
|
||||||
.update(&harness.db, partial, vec![])
|
.update(&harness.db, partial, vec![])
|
||||||
|
|||||||
@@ -48,10 +48,6 @@ pub async fn set_default_permissions(
|
|||||||
Channel::TextChannel {
|
Channel::TextChannel {
|
||||||
default_permissions,
|
default_permissions,
|
||||||
..
|
..
|
||||||
}
|
|
||||||
| Channel::VoiceChannel {
|
|
||||||
default_permissions,
|
|
||||||
..
|
|
||||||
} => {
|
} => {
|
||||||
if let DataDefaultChannelPermissions::Field { permissions: field } = data {
|
if let DataDefaultChannelPermissions::Field { permissions: field } = data {
|
||||||
permissions
|
permissions
|
||||||
|
|||||||
@@ -23,13 +23,6 @@ pub async fn fetch(db: &State<Database>, target: Reference) -> Result<Json<v0::I
|
|||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
..
|
..
|
||||||
}
|
|
||||||
| Channel::VoiceChannel {
|
|
||||||
id,
|
|
||||||
server,
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
..
|
|
||||||
} => {
|
} => {
|
||||||
let server = db.fetch_server(&server).await?;
|
let server = db.fetch_server(&server).await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user