Base model refactor (#810)
* Big upgrades * WIP: Stash * Stash, 30 flow errors left * Downgrade mobx * WIP * When I understand the difference between class and instance methods * 💚 * Fixes: File import Model saving edge cases pinning and starring docs Collection editing Upgrade mobx devtools * Notification settings saving works * Disabled settings * Document mailer * Working notifications * Colletion created notification Ensure not notified for own actions * Tidy up * Document updated event only for document creation Add indexes Notification setting on user creation * Commentary * Fixed: Notification setting on signup * Fix document move / duplicate stale data Add BaseModel.refresh method * Fixes: Title in sidebar not updated after editing document * 💚 * Improve / restore error handling Better handle offline errors * 👕
This commit is contained in:
@@ -8,6 +8,16 @@ import Queue from 'bull';
|
||||
import { baseStyles } from './emails/components/EmailLayout';
|
||||
import { WelcomeEmail, welcomeEmailText } from './emails/WelcomeEmail';
|
||||
import { ExportEmail, exportEmailText } from './emails/ExportEmail';
|
||||
import {
|
||||
type Props as DocumentNotificationEmailT,
|
||||
DocumentNotificationEmail,
|
||||
documentNotificationEmailText,
|
||||
} from './emails/DocumentNotificationEmail';
|
||||
import {
|
||||
type Props as CollectionNotificationEmailT,
|
||||
CollectionNotificationEmail,
|
||||
collectionNotificationEmailText,
|
||||
} from './emails/CollectionNotificationEmail';
|
||||
|
||||
const log = debug('emails');
|
||||
|
||||
@@ -42,12 +52,9 @@ type EmailJob = {
|
||||
* HTML: http://localhost:3000/email/:email_type/html
|
||||
* TEXT: http://localhost:3000/email/:email_type/text
|
||||
*/
|
||||
export default class Mailer {
|
||||
export class Mailer {
|
||||
transporter: ?any;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
sendMail = async (data: SendMailType): ?Promise<*> => {
|
||||
const { transporter } = this;
|
||||
|
||||
@@ -98,6 +105,30 @@ export default class Mailer {
|
||||
});
|
||||
};
|
||||
|
||||
documentNotification = async (
|
||||
opts: { to: string } & DocumentNotificationEmailT
|
||||
) => {
|
||||
this.sendMail({
|
||||
to: opts.to,
|
||||
title: `"${opts.document.title}" ${opts.eventName}`,
|
||||
previewText: `${opts.actor.name} ${opts.eventName} a new document`,
|
||||
html: <DocumentNotificationEmail {...opts} />,
|
||||
text: documentNotificationEmailText(opts),
|
||||
});
|
||||
};
|
||||
|
||||
collectionNotification = async (
|
||||
opts: { to: string } & CollectionNotificationEmailT
|
||||
) => {
|
||||
this.sendMail({
|
||||
to: opts.to,
|
||||
title: `"${opts.collection.name}" ${opts.eventName}`,
|
||||
previewText: `${opts.actor.name} ${opts.eventName} a collection`,
|
||||
html: <CollectionNotificationEmail {...opts} />,
|
||||
text: collectionNotificationEmailText(opts),
|
||||
});
|
||||
};
|
||||
|
||||
constructor() {
|
||||
if (process.env.SMTP_HOST) {
|
||||
let smtpConfig = {
|
||||
@@ -120,6 +151,8 @@ export default class Mailer {
|
||||
}
|
||||
|
||||
const mailer = new Mailer();
|
||||
export default mailer;
|
||||
|
||||
export const mailerQueue = new Queue('email', process.env.REDIS_URL);
|
||||
|
||||
mailerQueue.process(async (job: EmailJob) => {
|
||||
|
||||
Reference in New Issue
Block a user