forked from jmug/stoatchat
Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab4c3f913e | ||
|
|
8be51dc4f0 | ||
|
|
96fd18f679 | ||
|
|
2db54cf8de | ||
|
|
c3f092aaef | ||
|
|
ce68f7eeed | ||
|
|
139e704746 | ||
|
|
345c4c627c | ||
|
|
03ca611553 | ||
|
|
0fe63e3955 | ||
|
|
4474061103 | ||
|
|
788580a64f |
@@ -2,7 +2,7 @@ name: Add PR to Board
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened]
|
||||
types: [opened, synchronize, ready_for_review, review_requested]
|
||||
|
||||
jobs:
|
||||
track_pr:
|
||||
|
||||
Generated
+3
-3
@@ -2577,7 +2577,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rauth"
|
||||
version = "1.0.0"
|
||||
source = "git+https://github.com/insertish/rauth?rev=775a6f3ffb9ffc0e382af32fac2924e9a707e890#775a6f3ffb9ffc0e382af32fac2924e9a707e890"
|
||||
source = "git+https://github.com/insertish/rauth?rev=157263ffcbd6cb1073e288b215db227634c4c29a#157263ffcbd6cb1073e288b215db227634c4c29a"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"base32",
|
||||
@@ -2852,7 +2852,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rmp"
|
||||
version = "0.8.10"
|
||||
source = "git+https://github.com/3Hren/msgpack-rust?rev=5bf2c24203ad422233cf35b7b7bfad9f7e811814#5bf2c24203ad422233cf35b7b7bfad9f7e811814"
|
||||
source = "git+https://github.com/insertish/msgpack-rust?rev=5bf2c24203ad422233cf35b7b7bfad9f7e811814#5bf2c24203ad422233cf35b7b7bfad9f7e811814"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"num-traits",
|
||||
@@ -2861,7 +2861,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rmp-serde"
|
||||
version = "0.15.5"
|
||||
source = "git+https://github.com/3Hren/msgpack-rust?rev=5bf2c24203ad422233cf35b7b7bfad9f7e811814#5bf2c24203ad422233cf35b7b7bfad9f7e811814"
|
||||
source = "git+https://github.com/insertish/msgpack-rust?rev=5bf2c24203ad422233cf35b7b7bfad9f7e811814#5bf2c24203ad422233cf35b7b7bfad9f7e811814"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"rmp",
|
||||
|
||||
+2
-2
@@ -37,7 +37,7 @@ base64 = "0.13.0"
|
||||
serde_json = "1.0.57"
|
||||
serde = { version = "1.0.115", features = ["derive"] }
|
||||
validator = { version = "0.11", features = ["derive"] }
|
||||
rmp-serde = { git = "https://github.com/3Hren/msgpack-rust", rev = "5bf2c24203ad422233cf35b7b7bfad9f7e811814" }
|
||||
rmp-serde = { git = "https://github.com/insertish/msgpack-rust", rev = "5bf2c24203ad422233cf35b7b7bfad9f7e811814" }
|
||||
|
||||
# async
|
||||
futures = "0.3.8"
|
||||
@@ -50,7 +50,7 @@ async-std = { version = "1.8.0", features = ["tokio1", "tokio02", "attributes"]
|
||||
web-push = "0.7.2"
|
||||
many-to-many = "0.1.2"
|
||||
lettre = "0.10.0-alpha.4"
|
||||
rauth = { git = "https://github.com/insertish/rauth", rev = "775a6f3ffb9ffc0e382af32fac2924e9a707e890" }
|
||||
rauth = { git = "https://github.com/insertish/rauth", rev = "157263ffcbd6cb1073e288b215db227634c4c29a" }
|
||||
hive_pubsub = { git = "https://gitlab.insrt.uk/insert/hive", rev = "b0f3db9d33990530d7640d4bbb309c8d9eb5c0cf", features = ["redis-backend"] }
|
||||
|
||||
# redis
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
export version=0.5.3-alpha.9
|
||||
export version=0.5.3-alpha.16
|
||||
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
pub fn if_false(t: &bool) -> bool {
|
||||
!t
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Bot {
|
||||
#[serde(rename = "_id")]
|
||||
@@ -7,6 +11,10 @@ pub struct Bot {
|
||||
pub owner: String,
|
||||
pub token: String,
|
||||
pub public: bool,
|
||||
#[serde(skip_serializing_if = "if_false", default)]
|
||||
pub analytics: bool,
|
||||
#[serde(skip_serializing_if = "if_false", default)]
|
||||
pub discoverable: bool,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub interactions_url: Option<String>,
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ use crate::util::{
|
||||
variables::JANUARY_URL,
|
||||
variables::MAX_EMBED_COUNT,
|
||||
};
|
||||
use crate::database::entities::microservice::autumn::File;
|
||||
use linkify::{LinkFinder, LinkKind};
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -92,11 +93,28 @@ pub struct Metadata {
|
||||
colour: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Text {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub icon_url: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub url: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub title: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub media: Option<File>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub colour: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum Embed {
|
||||
Website(Metadata),
|
||||
Image(Image),
|
||||
Text(Text),
|
||||
None,
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,11 @@ pub struct Server {
|
||||
pub flags: Option<i32>,
|
||||
|
||||
#[serde(skip_serializing_if = "if_false", default)]
|
||||
pub nsfw: bool
|
||||
pub nsfw: bool,
|
||||
#[serde(skip_serializing_if = "if_false", default)]
|
||||
pub analytics: bool,
|
||||
#[serde(skip_serializing_if = "if_false", default)]
|
||||
pub discoverable: bool
|
||||
}
|
||||
|
||||
impl Server {
|
||||
@@ -232,6 +236,30 @@ impl Server {
|
||||
.collect::<Vec<Member>>())
|
||||
}
|
||||
|
||||
pub async fn fetch_members_with_ids(id: &str, ids: &Vec<String>) -> Result<Vec<Member>> {
|
||||
Ok(get_collection("server_members")
|
||||
.find(
|
||||
doc! {
|
||||
"_id.server": id,
|
||||
"_id.user": {
|
||||
"$in": ids
|
||||
}
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find",
|
||||
with: "server_members",
|
||||
})?
|
||||
.filter_map(async move |s| s.ok())
|
||||
.collect::<Vec<Document>>()
|
||||
.await
|
||||
.into_iter()
|
||||
.filter_map(|x| from_document(x).ok())
|
||||
.collect::<Vec<Member>>())
|
||||
}
|
||||
|
||||
pub async fn fetch_member_ids(id: &str) -> Result<Vec<String>> {
|
||||
Ok(get_collection("server_members")
|
||||
.find(
|
||||
|
||||
@@ -218,7 +218,7 @@ impl User {
|
||||
|
||||
/// Utility function for fetching multiple users from the perspective of one.
|
||||
/// Assumes user has a mutual connection with others.
|
||||
pub async fn fetch_multiple_users(&self, user_ids: Vec<String>) -> Result<Vec<User>> {
|
||||
pub async fn fetch_multiple_users(&self, user_ids: &Vec<String>) -> Result<Vec<User>> {
|
||||
let mut users = vec![];
|
||||
let mut cursor = get_collection("users")
|
||||
.find(
|
||||
|
||||
@@ -58,7 +58,25 @@ impl Ref {
|
||||
}
|
||||
|
||||
pub async fn fetch_invite(&self) -> Result<Invite> {
|
||||
self.fetch("channel_invites").await
|
||||
match self.fetch("channel_invites").await {
|
||||
Ok(invite) => Ok(invite),
|
||||
Err(err) => {
|
||||
if let Ok(server) = self.fetch::<Server>("servers").await {
|
||||
if server.discoverable {
|
||||
return Ok(
|
||||
Invite::Server {
|
||||
code: server.id.clone(),
|
||||
server: server.id,
|
||||
creator: server.owner,
|
||||
channel: server.channels[0].clone(),
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn fetch_bot(&self) -> Result<Bot> {
|
||||
|
||||
@@ -108,6 +108,13 @@ pub async fn create_database() {
|
||||
"channel": 1
|
||||
},
|
||||
"name": "channel"
|
||||
},
|
||||
{
|
||||
"key": {
|
||||
"channel": 1,
|
||||
"_id": 1
|
||||
},
|
||||
"name": "channel_id_compound"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -119,7 +126,7 @@ pub async fn create_database() {
|
||||
get_db()
|
||||
.run_command(
|
||||
doc! {
|
||||
"createIndexes": "messages",
|
||||
"createIndexes": "channel_unreads",
|
||||
"indexes": [
|
||||
{
|
||||
"key": {
|
||||
@@ -144,7 +151,7 @@ pub async fn create_database() {
|
||||
get_db()
|
||||
.run_command(
|
||||
doc! {
|
||||
"createIndexes": "messages",
|
||||
"createIndexes": "server_members",
|
||||
"indexes": [
|
||||
{
|
||||
"key": {
|
||||
|
||||
@@ -11,7 +11,7 @@ struct MigrationInfo {
|
||||
revision: i32,
|
||||
}
|
||||
|
||||
pub const LATEST_REVISION: i32 = 12;
|
||||
pub const LATEST_REVISION: i32 = 13;
|
||||
|
||||
pub async fn migrate_database() {
|
||||
let migrations = get_collection("migrations");
|
||||
@@ -396,7 +396,7 @@ pub async fn run_migrations(revision: i32) -> i32 {
|
||||
get_db()
|
||||
.run_command(
|
||||
doc! {
|
||||
"createIndexes": "messages",
|
||||
"createIndexes": "channel_unreads",
|
||||
"indexes": [
|
||||
{
|
||||
"key": {
|
||||
@@ -421,7 +421,7 @@ pub async fn run_migrations(revision: i32) -> i32 {
|
||||
get_db()
|
||||
.run_command(
|
||||
doc! {
|
||||
"createIndexes": "messages",
|
||||
"createIndexes": "server_members",
|
||||
"indexes": [
|
||||
{
|
||||
"key": {
|
||||
@@ -444,6 +444,29 @@ pub async fn run_migrations(revision: i32) -> i32 {
|
||||
.expect("Failed to create server_members index.");
|
||||
}
|
||||
|
||||
if revision <= 12 {
|
||||
info!("Running migration [revision 12 / 2021-11-21]: Add indexes to database.");
|
||||
|
||||
get_db()
|
||||
.run_command(
|
||||
doc! {
|
||||
"createIndexes": "messages",
|
||||
"indexes": [
|
||||
{
|
||||
"key": {
|
||||
"channel": 1,
|
||||
"_id": 1
|
||||
},
|
||||
"name": "channel_id_compound"
|
||||
}
|
||||
]
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.expect("Failed to create message index.");
|
||||
}
|
||||
|
||||
// Need to migrate fields on attachments, change `user_id`, `object_id`, etc to `parent`.
|
||||
|
||||
// Reminder to update LATEST_REVISION when adding new migrations.
|
||||
|
||||
@@ -104,7 +104,7 @@ pub async fn generate_ready(mut user: User) -> Result<ClientboundNotification> {
|
||||
|
||||
user_ids.remove(&user.id);
|
||||
let mut users = if user_ids.len() > 0 {
|
||||
user.fetch_multiple_users(user_ids.into_iter().collect::<Vec<String>>())
|
||||
user.fetch_multiple_users(&user_ids.into_iter().collect::<Vec<String>>())
|
||||
.await?
|
||||
} else {
|
||||
vec![]
|
||||
|
||||
@@ -48,6 +48,8 @@ pub async fn create_bot(user: User, info: Json<Data>) -> Result<Value> {
|
||||
owner: user.id.clone(),
|
||||
token,
|
||||
public: false,
|
||||
analytics: false,
|
||||
discoverable: false,
|
||||
interactions_url: None
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ pub struct Data {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
name: Option<String>,
|
||||
public: Option<bool>,
|
||||
analytics: Option<bool>,
|
||||
interactions_url: Option<String>,
|
||||
remove: Option<RemoveBotField>,
|
||||
}
|
||||
@@ -30,6 +31,7 @@ pub async fn edit_bot(user: User, target: Ref, data: Json<Data>) -> Result<Empty
|
||||
|
||||
if data.name.is_none()
|
||||
&& data.public.is_none()
|
||||
&& data.analytics.is_none()
|
||||
&& data.interactions_url.is_none()
|
||||
&& data.remove.is_none()
|
||||
{
|
||||
@@ -87,6 +89,10 @@ pub async fn edit_bot(user: User, target: Ref, data: Json<Data>) -> Result<Empty
|
||||
set.insert("public", public);
|
||||
}
|
||||
|
||||
if let Some(analytics) = &data.analytics {
|
||||
set.insert("analytics", analytics);
|
||||
}
|
||||
|
||||
if let Some(interactions_url) = &data.interactions_url {
|
||||
set.insert("interactions_url", interactions_url);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||
}
|
||||
|
||||
if let Channel::Group { recipients, .. } = target {
|
||||
Ok(json!(user.fetch_multiple_users(recipients).await?))
|
||||
Ok(json!(user.fetch_multiple_users(&recipients).await?))
|
||||
} else {
|
||||
Err(Error::InvalidOperation)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
use crate::routes::channels::message_send::SendableEmbed;
|
||||
|
||||
use chrono::Utc;
|
||||
use mongodb::bson::{doc, Bson, DateTime, Document};
|
||||
use mongodb::bson::{Bson, Document, doc, to_document};
|
||||
use rocket::serde::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
@@ -10,7 +11,9 @@ use validator::Validate;
|
||||
#[derive(Validate, Serialize, Deserialize)]
|
||||
pub struct Data {
|
||||
#[validate(length(min = 1, max = 2000))]
|
||||
content: String,
|
||||
content: Option<String>,
|
||||
#[validate(length(min = 0, max = 10))]
|
||||
embeds: Option<Vec<SendableEmbed>>
|
||||
}
|
||||
|
||||
#[patch("/<target>/messages/<msg>", data = "<edit>")]
|
||||
@@ -35,26 +38,50 @@ pub async fn req(user: User, target: Ref, msg: Ref, edit: Json<Data>) -> Result<
|
||||
}
|
||||
|
||||
let edited = Utc::now();
|
||||
let mut set = doc! {
|
||||
"content": &edit.content,
|
||||
"edited": Bson::DateTime(edited)
|
||||
};
|
||||
let mut set = doc! { "edited": Bson::DateTime(edited) };
|
||||
let mut unset = doc! {};
|
||||
let mut update = json!({ "edited": Bson::DateTime(edited) });
|
||||
|
||||
message.content = Content::Text(edit.content.clone());
|
||||
let mut update = json!({ "content": edit.content, "edited": DateTime(edited) });
|
||||
if let Some(new_content) = &edit.content {
|
||||
set.insert("content", new_content.clone());
|
||||
update.as_object_mut().unwrap().insert("content".to_string(), json!(new_content.clone()));
|
||||
message.content = Content::Text(new_content.clone());
|
||||
}
|
||||
|
||||
let mut new_embeds: Vec<Embed> = vec![];
|
||||
|
||||
if let Some(embeds) = &message.embeds {
|
||||
let new_embeds: Vec<Document> = vec![];
|
||||
|
||||
for embed in embeds {
|
||||
match embed {
|
||||
Embed::Website(_) | Embed::Image(_) | Embed::None => {} // Otherwise push to new_embeds.
|
||||
Embed::Text(embed) => new_embeds.push(Embed::Text(embed.clone())),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(edited_embeds) = &edit.embeds {
|
||||
new_embeds.clear();
|
||||
|
||||
for embed in edited_embeds {
|
||||
new_embeds.push(embed.clone().into_embed(message.id.clone()).await?);
|
||||
}
|
||||
}
|
||||
|
||||
if new_embeds.len() > 0 {
|
||||
let embed_docs: Vec<Document> = new_embeds
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|embed| to_document(&embed).unwrap())
|
||||
.collect();
|
||||
|
||||
let obj = update.as_object_mut().unwrap();
|
||||
obj.insert("embeds".to_string(), json!(new_embeds));
|
||||
set.insert("embeds", new_embeds);
|
||||
obj.insert("embeds".to_string(), json!(embed_docs));
|
||||
set.insert("embeds", embed_docs);
|
||||
message.embeds = Some(new_embeds)
|
||||
} else if edit.embeds.is_some() {
|
||||
let obj = update.as_object_mut().unwrap();
|
||||
obj.insert("embeds".to_string(), json!([]));
|
||||
unset.insert("embeds", 1 as u32);
|
||||
}
|
||||
|
||||
get_collection("messages")
|
||||
@@ -63,7 +90,8 @@ pub async fn req(user: User, target: Ref, msg: Ref, edit: Json<Data>) -> Result<
|
||||
"_id": &message.id
|
||||
},
|
||||
doc! {
|
||||
"$set": set
|
||||
"$set": set,
|
||||
"$unset": unset
|
||||
},
|
||||
None,
|
||||
)
|
||||
|
||||
@@ -166,13 +166,13 @@ pub async fn req(user: User, target: Ref, options: Options) -> Result<Value> {
|
||||
|
||||
ids.remove(&user.id);
|
||||
let user_ids = ids.into_iter().collect();
|
||||
let users = user.fetch_multiple_users(user_ids).await?;
|
||||
let users = user.fetch_multiple_users(&user_ids).await?;
|
||||
|
||||
if let Channel::TextChannel { server, .. } = target {
|
||||
Ok(json!({
|
||||
"messages": messages,
|
||||
"users": users,
|
||||
"members": Server::fetch_members(&server).await?
|
||||
"members": Server::fetch_members_with_ids(&server, &user_ids).await?
|
||||
}))
|
||||
} else {
|
||||
Ok(json!({
|
||||
|
||||
@@ -108,10 +108,10 @@ pub async fn req(user: User, target: Ref, options: Json<Options>) -> Result<Valu
|
||||
}
|
||||
},
|
||||
Sort::Latest => doc! {
|
||||
"_id": -1
|
||||
"_id": -1 as i32
|
||||
},
|
||||
Sort::Oldest => doc! {
|
||||
"_id": 1
|
||||
"_id": 1 as i32
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -142,13 +142,13 @@ pub async fn req(user: User, target: Ref, options: Json<Options>) -> Result<Valu
|
||||
|
||||
ids.remove(&user.id);
|
||||
let user_ids = ids.into_iter().collect();
|
||||
let users = user.fetch_multiple_users(user_ids).await?;
|
||||
let users = user.fetch_multiple_users(&user_ids).await?;
|
||||
|
||||
if let Channel::TextChannel { server, .. } = target {
|
||||
Ok(json!({
|
||||
"messages": messages,
|
||||
"users": users,
|
||||
"members": Server::fetch_members(&server).await?
|
||||
"members": Server::fetch_members_with_ids(&server, &user_ids).await?
|
||||
}))
|
||||
} else {
|
||||
Ok(json!({
|
||||
|
||||
@@ -18,6 +18,35 @@ pub struct Reply {
|
||||
mention: bool
|
||||
}
|
||||
|
||||
#[derive(Validate, Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct SendableEmbed {
|
||||
icon_url: Option<String>,
|
||||
url: Option<String>,
|
||||
#[validate(length(min = 1, max = 100))]
|
||||
title: Option<String>,
|
||||
#[validate(length(min = 1, max = 2000))]
|
||||
description: Option<String>,
|
||||
media: Option<String>,
|
||||
colour: Option<String>,
|
||||
}
|
||||
|
||||
impl SendableEmbed {
|
||||
pub async fn into_embed(self, message_id: String) -> Result<Embed> {
|
||||
let media = if let Some(id) = self.media {
|
||||
Some(File::find_and_use(&id, "attachments", "message", &message_id).await?)
|
||||
} else { None };
|
||||
|
||||
Ok(Embed::Text(Text {
|
||||
icon_url: self.icon_url,
|
||||
url: self.url,
|
||||
title: self.title,
|
||||
description: self.description,
|
||||
media,
|
||||
colour: self.colour
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Validate, Serialize, Deserialize)]
|
||||
pub struct Data {
|
||||
#[validate(length(min = 0, max = 2000))]
|
||||
@@ -27,7 +56,9 @@ pub struct Data {
|
||||
nonce: Option<String>,
|
||||
replies: Option<Vec<Reply>>,
|
||||
#[validate]
|
||||
masquerade: Option<Masquerade>
|
||||
masquerade: Option<Masquerade>,
|
||||
#[validate(length(min = 1, max = 10))]
|
||||
embeds: Option<Vec<SendableEmbed>>
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
@@ -114,6 +145,14 @@ pub async fn message_send(user: User, _r: Ratelimiter, mut idempotency: Idempote
|
||||
}
|
||||
}
|
||||
|
||||
let mut embeds = vec![];
|
||||
|
||||
if let Some(sendable_embeds) = message.embeds {
|
||||
for sendable_embed in sendable_embeds {
|
||||
embeds.push(sendable_embed.into_embed(id.clone()).await?)
|
||||
}
|
||||
}
|
||||
|
||||
let msg = Message {
|
||||
id,
|
||||
channel: target.id().to_string(),
|
||||
@@ -122,8 +161,7 @@ pub async fn message_send(user: User, _r: Ratelimiter, mut idempotency: Idempote
|
||||
content: Content::Text(message.content.clone()),
|
||||
nonce: Some(idempotency.key),
|
||||
edited: None,
|
||||
embeds: None,
|
||||
|
||||
embeds: if embeds.len() > 0 { Some(embeds) } else { None },
|
||||
attachments: if attachments.len() > 0 { Some(attachments) } else { None },
|
||||
mentions: if mentions.len() > 0 {
|
||||
Some(mentions.into_iter().collect::<Vec<String>>())
|
||||
|
||||
@@ -4,9 +4,8 @@ use serde::{Serialize, Deserialize};
|
||||
use validator::Contains;
|
||||
|
||||
use crate::database::*;
|
||||
use crate::database::permissions::channel::ChannelPermission;
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Data {
|
||||
@@ -34,7 +33,7 @@ pub async fn req(user: User, target: Ref, role: String, data: Json<Data>) -> Res
|
||||
return Err(Error::NotFound);
|
||||
}
|
||||
|
||||
let permissions: u32 = ChannelPermission::View as u32 | data.permissions;
|
||||
let permissions: u32 = data.permissions;
|
||||
|
||||
get_collection("channels")
|
||||
.update_one(
|
||||
|
||||
@@ -63,7 +63,7 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<EmptyRespo
|
||||
return Err(Error::MissingPermission);
|
||||
}
|
||||
|
||||
let permissions: u32 = ChannelPermission::View as u32 | data.permissions;
|
||||
let permissions: u32 = data.permissions;
|
||||
|
||||
get_collection("channels")
|
||||
.update_one(
|
||||
|
||||
@@ -46,6 +46,6 @@ pub async fn req(user: User, target: Ref) -> Result<Value> {
|
||||
|
||||
Ok(json!({
|
||||
"members": members,
|
||||
"users": user.fetch_multiple_users(member_ids).await?
|
||||
"users": user.fetch_multiple_users(&member_ids).await?
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ use rocket::serde::json::Json;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::database::*;
|
||||
use crate::database::permissions::channel::ChannelPermission;
|
||||
use crate::database::permissions::server::ServerPermission;
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
|
||||
@@ -36,8 +34,8 @@ pub async fn req(user: User, target: Ref, role_id: String, data: Json<Data>) ->
|
||||
return Err(Error::NotFound);
|
||||
}
|
||||
|
||||
let server_permissions: u32 = ServerPermission::View as u32 | data.permissions.server;
|
||||
let channel_permissions: u32 = ChannelPermission::View as u32 | data.permissions.channel;
|
||||
let server_permissions: u32 = data.permissions.server;
|
||||
let channel_permissions: u32 = data.permissions.channel;
|
||||
|
||||
get_collection("servers")
|
||||
.update_one(
|
||||
|
||||
@@ -3,8 +3,6 @@ use rocket::serde::json::Json;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
use crate::database::*;
|
||||
use crate::database::permissions::channel::ChannelPermission;
|
||||
use crate::database::permissions::server::ServerPermission;
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result, EmptyResponse};
|
||||
|
||||
@@ -32,8 +30,8 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<EmptyRespo
|
||||
return Err(Error::MissingPermission);
|
||||
}
|
||||
|
||||
let server_permissions: u32 = ServerPermission::View as u32 | data.permissions.server;
|
||||
let channel_permissions: u32 = ChannelPermission::View as u32 | data.permissions.channel;
|
||||
let server_permissions: u32 = data.permissions.server;
|
||||
let channel_permissions: u32 = data.permissions.channel;
|
||||
|
||||
get_collection("servers")
|
||||
.update_one(
|
||||
|
||||
@@ -66,7 +66,9 @@ pub async fn req(_idempotency: IdempotencyKey, user: User, info: Json<Data>) ->
|
||||
banner: None,
|
||||
|
||||
flags: None,
|
||||
nsfw: info.nsfw.unwrap_or_default()
|
||||
nsfw: info.nsfw.unwrap_or_default(),
|
||||
analytics: false,
|
||||
discoverable: false,
|
||||
};
|
||||
|
||||
Channel::TextChannel {
|
||||
|
||||
@@ -18,8 +18,8 @@ pub struct Data {
|
||||
categories: Option<Vec<Category>>,
|
||||
system_messages: Option<SystemMessageChannels>,
|
||||
remove: Option<RemoveServerField>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
nsfw: Option<bool>
|
||||
nsfw: Option<bool>,
|
||||
analytics: Option<bool>,
|
||||
}
|
||||
|
||||
#[patch("/<target>", data = "<data>")]
|
||||
@@ -28,7 +28,7 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<EmptyRespo
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
if data.name.is_none() && data.description.is_none() && data.icon.is_none() && data.banner.is_none() && data.remove.is_none() && data.categories.is_none() && data.system_messages.is_none()
|
||||
if data.name.is_none() && data.description.is_none() && data.icon.is_none() && data.banner.is_none() && data.remove.is_none() && data.categories.is_none() && data.system_messages.is_none() && data.nsfw.is_none() && data.analytics.is_none()
|
||||
{
|
||||
return Ok(EmptyResponse {});
|
||||
}
|
||||
@@ -111,6 +111,10 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<EmptyRespo
|
||||
set.insert("nsfw", nsfw);
|
||||
}
|
||||
|
||||
if let Some(analytics) = &data.analytics {
|
||||
set.insert("analytics", analytics);
|
||||
}
|
||||
|
||||
let mut operations = doc! {};
|
||||
if set.len() > 0 {
|
||||
operations.insert("$set", &set);
|
||||
|
||||
@@ -31,8 +31,10 @@ pub async fn run() {
|
||||
"_id": &id
|
||||
},
|
||||
doc! {
|
||||
"$set": {
|
||||
"embeds": bson
|
||||
"$push": {
|
||||
"embeds": {
|
||||
"$each": bson
|
||||
}
|
||||
}
|
||||
},
|
||||
None,
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
pub const VERSION: &str = "0.5.3-alpha.9";
|
||||
pub const VERSION: &str = "0.5.3-alpha.16";
|
||||
|
||||
Reference in New Issue
Block a user