🔔 Adding directory level notifications (#349)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user