1
1
import { ModuleRef } from '@nestjs/core' ;
2
2
import {
3
3
asNonEmptyArray ,
4
+ asyncPool ,
4
5
groupBy ,
5
6
type NonEmptyArray ,
6
7
setOf ,
@@ -11,7 +12,6 @@ import {
11
12
splitRangeByBook ,
12
13
type Verse ,
13
14
} from '@seedcompany/scripture' ;
14
- import { type ComponentProps as PropsOf } from 'react' ;
15
15
import { type ID , type Range } from '~/common' ;
16
16
import {
17
17
ConfigService ,
@@ -96,44 +96,23 @@ export class DBLUploadNotificationHandler
96
96
. get ( ProjectMemberRepository , { strict : false } )
97
97
. listAsNotifiers ( engagement . project . id , [ 'ProjectManager' ] ) ;
98
98
99
- const notifyeesProps = await Promise . all (
100
- notifyees
101
- . filter ( ( n ) => n . email )
102
- . map ( ( { id : userId } ) =>
103
- this . gatherTemplateProps (
104
- userId ,
105
- engagement . id ,
106
- engagement . language . value ! . id ,
107
- engagement . project . id ,
108
- completedBooks ,
109
- ) ,
110
- ) ,
111
- ) ;
112
-
113
99
this . logger . info ( 'Notifying' , {
114
- engagement : notifyeesProps [ 0 ] ?. engagement . id ?? undefined ,
115
- reportId : report . id ,
116
- reportDate : report . start ,
100
+ language : engagement . language . value ! . id ,
117
101
books : completedBooks . map ( ( r ) => r . start . book . name ) ,
118
- emails : notifyeesProps . map ( ( r ) => r . recipient . email . value ) ,
102
+ emails : notifyees . flatMap ( ( r ) => r . email ?? [ ] ) ,
119
103
} ) ;
120
104
121
- for ( const props of notifyeesProps ) {
122
- // members without an email address are already omitted
123
- const to = props . recipient . email . value ! ;
124
- await this . mailer
125
- . withOptions ( { send : ! ! this . config . email . notifyDblUpload } )
126
- . compose (
127
- {
128
- to,
129
- ...( this . config . email . notifyDblUpload ?. replyTo && {
130
- 'reply-to' : this . config . email . notifyDblUpload . replyTo ,
131
- } ) ,
132
- } ,
133
- < DBLUpload { ...props } /> ,
134
- )
135
- . send ( ) ;
136
- }
105
+ await asyncPool ( Infinity , notifyees , async ( { id : user , email } ) => {
106
+ if ( ! email ) {
107
+ return ;
108
+ }
109
+ const msg = await this . identity . asUser ( user , async ( ) =>
110
+ this . mailer
111
+ . withOptions ( { send : ! ! this . config . email . notifyDblUpload } )
112
+ . compose ( email , [ DBLUpload , { engagement, completedBooks } ] ) ,
113
+ ) ;
114
+ await msg . send ( ) ;
115
+ } ) ;
137
116
}
138
117
139
118
private async determineCompletedProducts ( report : ProgressReport ) {
@@ -215,30 +194,4 @@ export class DBLUploadNotificationHandler
215
194
} ) ;
216
195
return asNonEmptyArray ( completedBooks ) ;
217
196
}
218
-
219
- private async gatherTemplateProps (
220
- recipientId : ID < 'User' > ,
221
- engagementId : ID ,
222
- languageId : ID ,
223
- projectId : ID ,
224
- completedBooks : NonEmptyArray < Range < Verse > > ,
225
- ) {
226
- return await this . identity . asUser ( recipientId , async ( ) => {
227
- const [ recipient , language , engagement , project ] = await Promise . all ( [
228
- this . resources . load ( 'User' , recipientId ) ,
229
- this . resources . load ( 'Language' , languageId ) ,
230
- this . resources . load ( 'Engagement' , engagementId ) ,
231
- this . resources . load ( 'Project' , projectId ) ,
232
- ] ) ;
233
-
234
- return {
235
- recipient,
236
- language,
237
- project,
238
- engagement,
239
- completedBooks,
240
- dblFormUrl : this . config . email . notifyDblUpload ?. formUrl ?? '' ,
241
- } satisfies PropsOf < typeof DBLUpload > ;
242
- } ) ;
243
- }
244
197
}
0 commit comments