fix: Subscribe to document automatically on share (#8108)

This commit is contained in:
Tom Moor authored and GitHub committed 2024-12-15 17:37:20 -08:00
1 parent a458690bfc
commit e89c32424f
1 file changed
+27
@@ -0,0 +1,27 @@
import subscriptionCreator from "@server/commands/subscriptionCreator";
import { User } from "@server/models";
import { sequelize } from "@server/storage/database";
import { DocumentUserEvent, Event } from "@server/types";
import BaseProcessor from "./BaseProcessor";
export default class DocumentUserAddedProcessor extends BaseProcessor {
static applicableEvents: Event["name"][] = ["documents.add_user"];
async perform(event: DocumentUserEvent) {
const user = await User.findByPk(event.userId);
if (!user) {
return;
}
await sequelize.transaction(async (transaction) => {
await subscriptionCreator({
user,
documentId: event.documentId,
event: "documents.update",
resubscribe: false,
transaction,
ip: event.ip,
});
});
}
}