🔔 Adding directory level notifications (#349)

This commit is contained in:
Montassar Ghanmy
2024-01-30 10:43:12 +01:00
committed by GitHub
parent f6b67565b7
commit 49ac30136b
@@ -327,6 +327,41 @@ export class DocumentsService {
this.repository,
context,
);
// TODO: notify the user a document has been added to the directory shared with them
try {
if (driveItem.parent_id !== "root" && driveItem.parent_id !== "trash") {
const parentItem = await this.repository.findOne(
{
id: driveItem.parent_id,
company_id: context.company.id,
},
{},
context,
);
const sharedWith = parentItem?.access_info
? parentItem.access_info.entities.filter(
info => info.type === "user" && info.id !== context.user.id,
)
: [];
if (sharedWith.length > 0) {
// Notify the user that the document has been shared with them
this.logger.info("Notifying users that the document has been shared with them: ", {
sharedWith,
});
for (const info of sharedWith) {
gr.services.documents.engine.notifyDocumentShared({
context,
item: driveItem,
notificationEmitter: context.user.id,
notificationReceiver: info.id,
});
}
}
}
} catch (error) {
console.error("🚀🚀 error:", error);
}
await this.repository.save(driveItem);
driveItemVersion.drive_item_id = driveItem.id;