-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Supports computed email subject #2863
Supports computed email subject #2863
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of the tests are failing because the assertions are wrong
Thank you for this great PR! @martijnvdbrug since you were involved in the original issue, do you have any feedback on this implementation? |
Will review this Tuesday! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, and nice work on the mocks in the e2e tests 👌
I am wondering if we need the templateLoader.loadSubject()
function. It's a bit confusing to me that there are now 2 ways to load a subject: templateLoader.loadSubject
and setSubject()
. You could even use both methods, in which case it is not clear which subject function is used.
Can we remove the templateLoader.loadSubject
, and have the template loader only handle templates? What do you think about this? Maybe I am missing something...
In my opinion, I think it's fine having the I also noted the |
Thanks for the review @martijnvdbrug I tend to bias toward adding fewer APIs in general, but I also appreciate the case for the One other concern is that I think having Just to explore this further before we commit to one path or the other, let's imagine how code reuse could look without the new method on // subject.service.ts
export class SubjectService {
loadSubject(event: Event, ctx: RequestContext): string {
// ... custom logic here
}
}
// email-event-handlers.ts
function loadEmailSubject(event: Event, ctx: RequestContext, injector: Injector) {
return injector.get(SubjectService).loadSubject(event, ctx);
}
for (const handler of myEmailHandlers) {
handler.loadSubject(loadEmailSubject);
} And compare this to an implementation with // subject.service.ts
export class SubjectService {
loadSubject(ctx: RequestContext, input: LoadTemplateInput & { subject: string; }): string {
// ... custom logic here
}
}
// my-template-loader.ts
export class MyTemplateLoader implements TemplateLoader {
async loadTemplate(/* ... */ ): Promise<string> {
// ... omitted
}
async loadSubject(injector: Injector, ctx: RequestContext, input: LoadTemplateInput & { subject: string; }): Promise<string> {
return injector.get(SubjectService).loadSubject(ctx, input);
}
} The amount of code involved in both approaches is comparable I'd say. What do you think @rein1410? |
I guess a for loop could be a good alternative to the |
Done! @michaelbromley |
Thank you @rein1410 👍 |
Ah, this just got merged during me reading this 😆 , sorry for the late response. I agree with the solution though. Thanks @rein1410 for picking this up. |
Description
EmailEventListener
'ssetSubject
function how accepts either a string or a callback function that containsEvent
,RequestContext
andInjector
as arguments. Allowing better email subject customization.The email plugin's
TemplateLoader
now has an optional functionloadSubject
that hasInjector
,RequestContext
andLoadTemplateInput
along with the original subject configured from theEmailEventListener
as arguments.These changes allow the user to more freely define their email subjects based on their injected providers, the event or the incoming request.
Should be noted that the
TemplateLoader
's subject will override theEmailEventListener
's subjectBreaking changes
No
Checklist
📌 Always:
👍 Most of the time: