forked from jmug/stoatchat
fix: rewrite attachment deletion logic
This commit is contained in:
@@ -39,4 +39,9 @@ impl AbstractAttachment for DummyDb {
|
|||||||
info!("Marked {id} as deleted");
|
info!("Marked {id} as deleted");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn mark_attachments_as_deleted(&self, ids: &[String]) -> Result<()> {
|
||||||
|
info!("Marked {ids:?} as deleted");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -135,7 +135,17 @@ impl Message {
|
|||||||
|
|
||||||
/// Delete a message
|
/// Delete a message
|
||||||
pub async fn delete(self, db: &Database) -> Result<()> {
|
pub async fn delete(self, db: &Database) -> Result<()> {
|
||||||
|
let file_ids: Vec<String> = self
|
||||||
|
.attachments
|
||||||
|
.map(|files| files.iter().map(|file| file.id.to_string()).collect())
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if !file_ids.is_empty() {
|
||||||
|
db.mark_attachments_as_deleted(&file_ids).await?;
|
||||||
|
}
|
||||||
|
|
||||||
db.delete_message(&self.id).await?;
|
db.delete_message(&self.id).await?;
|
||||||
|
|
||||||
EventV1::MessageDelete {
|
EventV1::MessageDelete {
|
||||||
id: self.id,
|
id: self.id,
|
||||||
channel: self.channel.clone(),
|
channel: self.channel.clone(),
|
||||||
|
|||||||
@@ -122,4 +122,27 @@ impl AbstractAttachment for MongoDb {
|
|||||||
with: "attachment",
|
with: "attachment",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn mark_attachments_as_deleted(&self, ids: &[String]) -> Result<()> {
|
||||||
|
self.col::<Document>(COL)
|
||||||
|
.update_many(
|
||||||
|
doc! {
|
||||||
|
"_id": {
|
||||||
|
"$in": ids
|
||||||
|
}
|
||||||
|
},
|
||||||
|
doc! {
|
||||||
|
"$set": {
|
||||||
|
"deleted": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map(|_| ())
|
||||||
|
.map_err(|_| Error::DatabaseError {
|
||||||
|
operation: "update",
|
||||||
|
with: "attachments",
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ impl MongoDb {
|
|||||||
pub async fn delete_bulk_messages(&self, projection: Document) -> Result<()> {
|
pub async fn delete_bulk_messages(&self, projection: Document) -> Result<()> {
|
||||||
let mut for_attachments = projection.clone();
|
let mut for_attachments = projection.clone();
|
||||||
for_attachments.insert(
|
for_attachments.insert(
|
||||||
"attachment",
|
"attachments",
|
||||||
doc! {
|
doc! {
|
||||||
"$exists": 1_i32
|
"$exists": 1_i32
|
||||||
},
|
},
|
||||||
@@ -126,10 +126,7 @@ impl AbstractMessage for MongoDb {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn delete_message(&self, id: &str) -> Result<()> {
|
async fn delete_message(&self, id: &str) -> Result<()> {
|
||||||
self.delete_bulk_messages(doc! {
|
self.delete_one_by_id(COL, id).await.map(|_| ())
|
||||||
"_id": id
|
|
||||||
})
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete_messages(&self, channel: &str, ids: Vec<String>) -> Result<()> {
|
async fn delete_messages(&self, channel: &str, ids: Vec<String>) -> Result<()> {
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ pub trait AbstractAttachment: Sync + Send {
|
|||||||
async fn insert_attachment(&self, attachment: &File) -> Result<()>;
|
async fn insert_attachment(&self, attachment: &File) -> Result<()>;
|
||||||
async fn mark_attachment_as_reported(&self, id: &str) -> Result<()>;
|
async fn mark_attachment_as_reported(&self, id: &str) -> Result<()>;
|
||||||
async fn mark_attachment_as_deleted(&self, id: &str) -> Result<()>;
|
async fn mark_attachment_as_deleted(&self, id: &str) -> Result<()>;
|
||||||
|
async fn mark_attachments_as_deleted(&self, ids: &[String]) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,73 @@
|
|||||||
version: "3.3"
|
version: "3.3"
|
||||||
services:
|
services:
|
||||||
|
# Redis
|
||||||
redis:
|
redis:
|
||||||
image: eqalpha/keydb
|
image: eqalpha/keydb
|
||||||
ports:
|
ports:
|
||||||
- "6379:6379"
|
- "6379:6379"
|
||||||
|
|
||||||
|
# MongoDB
|
||||||
database:
|
database:
|
||||||
image: mongo
|
image: mongo
|
||||||
ports:
|
ports:
|
||||||
- "27017:27017"
|
- "27017:27017"
|
||||||
volumes:
|
volumes:
|
||||||
- ./.data/db:/data/db
|
- ./.data/db:/data/db
|
||||||
|
|
||||||
|
# MinIO
|
||||||
|
minio:
|
||||||
|
image: minio/minio
|
||||||
|
command: server /data
|
||||||
|
env_file: .env
|
||||||
|
volumes:
|
||||||
|
- ./.data/minio:/data
|
||||||
|
ports:
|
||||||
|
- "10000:9000"
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
# Mongo Express
|
||||||
mongo-express:
|
mongo-express:
|
||||||
image: mongo-express
|
image: mongo-express
|
||||||
ports:
|
ports:
|
||||||
- "8081:8081"
|
- "8081:8081"
|
||||||
environment:
|
environment:
|
||||||
- ME_CONFIG_MONGODB_SERVER=database
|
- ME_CONFIG_MONGODB_SERVER=database
|
||||||
|
depends_on:
|
||||||
|
- database
|
||||||
|
|
||||||
|
# Create buckets for minio.
|
||||||
|
createbuckets:
|
||||||
|
image: minio/mc
|
||||||
|
depends_on:
|
||||||
|
- minio
|
||||||
|
env_file: .env
|
||||||
|
entrypoint: >
|
||||||
|
/bin/sh -c "
|
||||||
|
while ! curl -s --output /dev/null --connect-timeout 1 http://minio:9000; do echo 'Waiting minio...' && sleep 0.1; done;
|
||||||
|
/usr/bin/mc alias set minio http://minio:9000 $MINIO_ROOT_USER $MINIO_ROOT_PASSWORD;
|
||||||
|
/usr/bin/mc mb minio/attachments;
|
||||||
|
/usr/bin/mc mb minio/avatars;
|
||||||
|
/usr/bin/mc mb minio/backgrounds;
|
||||||
|
/usr/bin/mc mb minio/icons;
|
||||||
|
/usr/bin/mc mb minio/banners;
|
||||||
|
exit 0;
|
||||||
|
"
|
||||||
|
# File server (autumn)
|
||||||
|
autumn:
|
||||||
|
image: ghcr.io/revoltchat/autumn:1.1.4
|
||||||
|
env_file: .env
|
||||||
|
depends_on:
|
||||||
|
- database
|
||||||
|
- createbuckets
|
||||||
|
environment:
|
||||||
|
- AUTUMN_MONGO_URI=mongodb://database
|
||||||
|
ports:
|
||||||
|
- "3000:3000"
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
# Metadata and image proxy (january)
|
||||||
|
january:
|
||||||
|
image: ghcr.io/revoltchat/january:0.3.4
|
||||||
|
ports:
|
||||||
|
- "7000:7000"
|
||||||
|
restart: always
|
||||||
|
|||||||
Reference in New Issue
Block a user