forked from jmug/stoatchat
Database: Add user settings sync entity.
Run cargo fmt.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use crate::util::variables::{VAPID_PRIVATE_KEY, USE_JANUARY};
|
||||
use crate::util::variables::{USE_JANUARY, VAPID_PRIVATE_KEY};
|
||||
use crate::{
|
||||
database::*,
|
||||
notifications::{events::ClientboundNotification, websocket::is_online},
|
||||
@@ -297,12 +297,13 @@ impl Message {
|
||||
let channel = self.channel.clone();
|
||||
ClientboundNotification::MessageDelete {
|
||||
id: self.id.clone(),
|
||||
channel: self.channel.clone()
|
||||
channel: self.channel.clone(),
|
||||
}
|
||||
.publish(channel);
|
||||
|
||||
if let Some(attachments) = &self.attachments {
|
||||
let attachment_ids: Vec<String> = attachments.iter().map(|f| f.id.to_string()).collect();
|
||||
let attachment_ids: Vec<String> =
|
||||
attachments.iter().map(|f| f.id.to_string()).collect();
|
||||
get_collection("attachments")
|
||||
.update_one(
|
||||
doc! {
|
||||
|
||||
2
src/database/entities/microservice/mod.rs
Normal file
2
src/database/entities/microservice/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod autumn;
|
||||
pub mod january;
|
||||
@@ -1,9 +1,11 @@
|
||||
mod autumn;
|
||||
mod microservice;
|
||||
mod channel;
|
||||
mod january;
|
||||
mod message;
|
||||
mod server;
|
||||
mod user;
|
||||
mod sync;
|
||||
|
||||
use microservice::*;
|
||||
|
||||
pub use autumn::*;
|
||||
pub use channel::*;
|
||||
@@ -11,3 +13,4 @@ pub use january::*;
|
||||
pub use message::*;
|
||||
pub use server::*;
|
||||
pub use user::*;
|
||||
pub use sync::*;
|
||||
|
||||
3
src/database/entities/sync.rs
Normal file
3
src/database/entities/sync.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub type UserSettings = HashMap<String, (i64, String)>;
|
||||
@@ -4,11 +4,11 @@ use mongodb::{
|
||||
bson::{doc, from_document},
|
||||
options::FindOptions,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
use num_enum::TryFromPrimitive;
|
||||
use ulid::Ulid;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::ops;
|
||||
use ulid::Ulid;
|
||||
use validator::Validate;
|
||||
|
||||
use crate::database::permissions::user::UserPermissions;
|
||||
use crate::database::*;
|
||||
@@ -65,7 +65,7 @@ pub enum Badges {
|
||||
Developer = 1,
|
||||
Translator = 2,
|
||||
Supporter = 4,
|
||||
EarlyAdopter = 256
|
||||
EarlyAdopter = 256,
|
||||
}
|
||||
|
||||
impl_op_ex_commutative!(+ |a: &i32, b: &Badges| -> i32 { *a | *b as i32 });
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
use crate::database::{get_collection, get_db};
|
||||
|
||||
use log::info;
|
||||
use futures::StreamExt;
|
||||
use log::info;
|
||||
use mongodb::{
|
||||
bson::{doc, from_document},
|
||||
options::FindOptions,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use mongodb::{bson::{doc, from_document}, options::FindOptions};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct MigrationInfo {
|
||||
@@ -92,34 +95,36 @@ pub async fn run_migrations(revision: i32) -> i32 {
|
||||
info!("Running migration [revision 3 / 2021-05-25]: Support multiple file uploads, add channel_unreads and user_settings.");
|
||||
|
||||
let messages = get_collection("messages");
|
||||
let mut cursor = messages.find(
|
||||
doc! {
|
||||
"attachment": {
|
||||
"$exists": 1
|
||||
}
|
||||
},
|
||||
FindOptions::builder()
|
||||
.projection(doc! {
|
||||
"_id": 1,
|
||||
"attachments": [ "$attachment" ]
|
||||
})
|
||||
.build()
|
||||
)
|
||||
.await
|
||||
.expect("Failed to fetch messages.");
|
||||
let mut cursor = messages
|
||||
.find(
|
||||
doc! {
|
||||
"attachment": {
|
||||
"$exists": 1
|
||||
}
|
||||
},
|
||||
FindOptions::builder()
|
||||
.projection(doc! {
|
||||
"_id": 1,
|
||||
"attachments": [ "$attachment" ]
|
||||
})
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
.expect("Failed to fetch messages.");
|
||||
|
||||
while let Some(result) = cursor.next().await {
|
||||
let doc = result.unwrap();
|
||||
let id = doc.get_str("_id").unwrap();
|
||||
let attachments = doc.get_array("attachments").unwrap();
|
||||
|
||||
messages.update_one(
|
||||
doc! { "_id": id },
|
||||
doc! { "$unset": { "attachment": 1 }, "$set": { "attachments": attachments } },
|
||||
None
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
messages
|
||||
.update_one(
|
||||
doc! { "_id": id },
|
||||
doc! { "$unset": { "attachment": 1 }, "$set": { "attachments": attachments } },
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
get_db()
|
||||
|
||||
Reference in New Issue
Block a user