feat(messaging): add masquerade to messages
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
export version=0.5.3-alpha.7
|
export version=0.5.3-alpha.8
|
||||||
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs
|
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use mongodb::bson::{doc, to_bson, DateTime};
|
|||||||
use rocket::serde::json::Value;
|
use rocket::serde::json::Value;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
|
use validator::Validate;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
@@ -123,6 +124,7 @@ impl Content {
|
|||||||
target.id().to_string(),
|
target.id().to_string(),
|
||||||
self,
|
self,
|
||||||
None,
|
None,
|
||||||
|
None,
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
.publish(&target, false)
|
.publish(&target, false)
|
||||||
@@ -130,6 +132,16 @@ impl Content {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone, Validate)]
|
||||||
|
pub struct Masquerade {
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[validate(length(min = 1, max = 32))]
|
||||||
|
name: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
#[validate(length(min = 1, max = 128))]
|
||||||
|
avatar: Option<String>
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
#[serde(rename = "_id")]
|
#[serde(rename = "_id")]
|
||||||
@@ -149,7 +161,9 @@ pub struct Message {
|
|||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub mentions: Option<Vec<String>>,
|
pub mentions: Option<Vec<String>>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub replies: Option<Vec<String>>
|
pub replies: Option<Vec<String>>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub masquerade: Option<Masquerade>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
@@ -159,6 +173,7 @@ impl Message {
|
|||||||
content: Content,
|
content: Content,
|
||||||
mentions: Option<Vec<String>>,
|
mentions: Option<Vec<String>>,
|
||||||
replies: Option<Vec<String>>,
|
replies: Option<Vec<String>>,
|
||||||
|
masquerade: Option<Masquerade>,
|
||||||
) -> Message {
|
) -> Message {
|
||||||
Message {
|
Message {
|
||||||
id: Ulid::new().to_string(),
|
id: Ulid::new().to_string(),
|
||||||
@@ -170,7 +185,8 @@ impl Message {
|
|||||||
edited: None,
|
edited: None,
|
||||||
embeds: None,
|
embeds: None,
|
||||||
mentions,
|
mentions,
|
||||||
replies
|
replies,
|
||||||
|
masquerade
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ struct MigrationInfo {
|
|||||||
revision: i32,
|
revision: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const LATEST_REVISION: i32 = 10;
|
pub const LATEST_REVISION: i32 = 11;
|
||||||
|
|
||||||
pub async fn migrate_database() {
|
pub async fn migrate_database() {
|
||||||
let migrations = get_collection("migrations");
|
let migrations = get_collection("migrations");
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub enum ChannelPermission {
|
|||||||
InviteOthers = 0b00000000000000000000000000100000, // 32
|
InviteOthers = 0b00000000000000000000000000100000, // 32
|
||||||
EmbedLinks = 0b00000000000000000000000001000000, // 64
|
EmbedLinks = 0b00000000000000000000000001000000, // 64
|
||||||
UploadFiles = 0b00000000000000000000000010000000, // 128
|
UploadFiles = 0b00000000000000000000000010000000, // 128
|
||||||
|
Masquerade = 0b00000000000000000000000100000000, // 256
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
@@ -27,7 +28,8 @@ lazy_static! {
|
|||||||
+ ChannelPermission::VoiceCall
|
+ ChannelPermission::VoiceCall
|
||||||
+ ChannelPermission::InviteOthers
|
+ ChannelPermission::InviteOthers
|
||||||
+ ChannelPermission::EmbedLinks
|
+ ChannelPermission::EmbedLinks
|
||||||
+ ChannelPermission::UploadFiles;
|
+ ChannelPermission::UploadFiles
|
||||||
|
+ ChannelPermission::Masquerade;
|
||||||
|
|
||||||
pub static ref DEFAULT_PERMISSION_SERVER: u32 =
|
pub static ref DEFAULT_PERMISSION_SERVER: u32 =
|
||||||
ChannelPermission::View
|
ChannelPermission::View
|
||||||
@@ -52,6 +54,7 @@ bitfield! {
|
|||||||
pub get_invite_others, _: 26;
|
pub get_invite_others, _: 26;
|
||||||
pub get_embed_links, _: 25;
|
pub get_embed_links, _: 25;
|
||||||
pub get_upload_files, _: 24;
|
pub get_upload_files, _: 24;
|
||||||
|
pub get_masquerade, _: 23;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> PermissionCalculator<'a> {
|
impl<'a> PermissionCalculator<'a> {
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ pub struct Data {
|
|||||||
attachments: Option<Vec<String>>,
|
attachments: Option<Vec<String>>,
|
||||||
nonce: Option<String>,
|
nonce: Option<String>,
|
||||||
replies: Option<Vec<Reply>>,
|
replies: Option<Vec<Reply>>,
|
||||||
|
#[validate]
|
||||||
|
masquerade: Option<Masquerade>
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
@@ -62,11 +64,17 @@ pub async fn message_send(user: User, _r: Ratelimiter, mut idempotency: Idempote
|
|||||||
|
|
||||||
let mut mentions = HashSet::new();
|
let mut mentions = HashSet::new();
|
||||||
for capture in RE_MENTION.captures_iter(&message.content) {
|
for capture in RE_MENTION.captures_iter(&message.content) {
|
||||||
if let Some(mention) = capture.get(1) {
|
if let Some(mention) = capture.get(1) {
|
||||||
mentions.insert(mention.as_str().to_string());
|
mentions.insert(mention.as_str().to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(_) = &message.masquerade {
|
||||||
|
if !perm.get_masquerade() {
|
||||||
|
return Err(Error::MissingPermission)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut replies = HashSet::new();
|
let mut replies = HashSet::new();
|
||||||
if let Some(entries) = message.replies {
|
if let Some(entries) = message.replies {
|
||||||
// ! FIXME: move this to app config
|
// ! FIXME: move this to app config
|
||||||
@@ -127,6 +135,7 @@ pub async fn message_send(user: User, _r: Ratelimiter, mut idempotency: Idempote
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
masquerade: message.masquerade
|
||||||
};
|
};
|
||||||
|
|
||||||
msg.clone().publish(&target, perm.get_embed_links()).await?;
|
msg.clone().publish(&target, perm.get_embed_links()).await?;
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
pub const VERSION: &str = "0.5.3-alpha.7";
|
pub const VERSION: &str = "0.5.3-alpha.8";
|
||||||
|
|||||||
Reference in New Issue
Block a user