feat: add emoji
This commit is contained in:
@@ -16,7 +16,7 @@ struct MigrationInfo {
|
||||
revision: i32,
|
||||
}
|
||||
|
||||
pub const LATEST_REVISION: i32 = 16;
|
||||
pub const LATEST_REVISION: i32 = 17;
|
||||
|
||||
pub async fn migrate_database(db: &MongoDb) {
|
||||
let migrations = db.col::<Document>("migrations");
|
||||
@@ -611,6 +611,39 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
if revision <= 16 {
|
||||
info!("Running migration [revision 16 / 07-07-2022]: Add `emojis` collection and rAuth migration.");
|
||||
|
||||
let rauth_db = rauth::Database::MongoDb(rauth::database::MongoDb(db.db()));
|
||||
rauth_db
|
||||
.run_migration(rauth::Migration::M2022_06_09AddIndexForDeletion)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
db.db()
|
||||
.create_collection("emojis", None)
|
||||
.await
|
||||
.expect("Failed to create emojis collection.");
|
||||
|
||||
db.db()
|
||||
.run_command(
|
||||
doc! {
|
||||
"createIndexes": "emojis",
|
||||
"indexes": [
|
||||
{
|
||||
"key": {
|
||||
"parent.id": 1_i32,
|
||||
},
|
||||
"name": "parent_id"
|
||||
}
|
||||
]
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.expect("Failed to create emoji parent index.");
|
||||
}
|
||||
|
||||
// Need to migrate fields on attachments, change `user_id`, `object_id`, etc to `parent`.
|
||||
|
||||
// Reminder to update LATEST_REVISION when adding new migrations.
|
||||
|
||||
48
crates/quark/src/impl/mongo/media/emoji.rs
Normal file
48
crates/quark/src/impl/mongo/media/emoji.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use crate::models::Emoji;
|
||||
use crate::{AbstractEmoji, Result};
|
||||
|
||||
use super::super::MongoDb;
|
||||
|
||||
static COL: &str = "emojis";
|
||||
|
||||
#[async_trait]
|
||||
impl AbstractEmoji for MongoDb {
|
||||
/// Fetch an emoji by its id
|
||||
async fn fetch_emoji(&self, id: &str) -> Result<Emoji> {
|
||||
self.find_one_by_id(COL, id).await
|
||||
}
|
||||
|
||||
/// Fetch emoji by their ids
|
||||
async fn fetch_emoji_by_parent_id(&self, parent_id: &str) -> Result<Vec<Emoji>> {
|
||||
self.find(
|
||||
COL,
|
||||
doc! {
|
||||
"parent.id": parent_id
|
||||
},
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Fetch emoji by their parent ids
|
||||
async fn fetch_emoji_by_parent_ids(&self, parent_ids: &[String]) -> Result<Vec<Emoji>> {
|
||||
self.find(
|
||||
COL,
|
||||
doc! {
|
||||
"parent.id": {
|
||||
"$in": parent_ids
|
||||
}
|
||||
},
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Insert emoji into database.
|
||||
async fn insert_emoji(&self, emoji: &Emoji) -> Result<()> {
|
||||
self.insert_one(COL, emoji).await.map(|_| ())
|
||||
}
|
||||
|
||||
/// Delete an emoji by its id
|
||||
async fn delete_emoji(&self, emoji: &Emoji) -> Result<()> {
|
||||
self.delete_one_by_id(COL, &emoji.id).await.map(|_| ())
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ pub mod admin {
|
||||
|
||||
pub mod media {
|
||||
pub mod attachment;
|
||||
pub mod emoji;
|
||||
}
|
||||
|
||||
pub mod channels {
|
||||
|
||||
@@ -18,6 +18,20 @@ impl MongoDb {
|
||||
})
|
||||
.await?;
|
||||
|
||||
// Delete all emoji.
|
||||
self.col::<Document>("emojis")
|
||||
.delete_many(
|
||||
doc! {
|
||||
"parent.id": &server.id
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "delete_many",
|
||||
with: "emojis",
|
||||
})?;
|
||||
|
||||
// Delete all channels.
|
||||
self.col::<Document>("channels")
|
||||
.delete_many(
|
||||
|
||||
Reference in New Issue
Block a user