@@ -6,12 +6,18 @@ import Raven from 'shared/raven';
6
6
import { getCommunityById } from '../models/community' ;
7
7
import { storeNotification } from '../models/notification' ;
8
8
import { storeUsersNotifications } from '../models/usersNotifications' ;
9
- import { getOwnersInChannel } from '../models/usersChannels' ;
9
+ import {
10
+ getOwnersInChannel ,
11
+ getModeratorsInChannel ,
12
+ } from '../models/usersChannels' ;
13
+ import {
14
+ getOwnersInCommunity ,
15
+ getModeratorsInCommunity ,
16
+ } from '../models/usersCommunities' ;
10
17
import { getUsers } from '../models/user' ;
11
18
import { fetchPayload , createPayload } from '../utils/payloads' ;
12
19
import isEmail from 'validator/lib/isEmail' ;
13
20
import { sendPrivateChannelRequestEmailQueue } from 'shared/bull/queues' ;
14
- import type { DBChannel } from 'shared/types' ;
15
21
import type { Job , PrivateChannelRequestJobData } from 'shared/bull/types' ;
16
22
17
23
export default async ( job : Job < PrivateChannelRequestJobData > ) => {
@@ -45,12 +51,29 @@ export default async (job: Job<PrivateChannelRequestJobData>) => {
45
51
const updatedNotification = await storeNotification ( nextNotificationRecord ) ;
46
52
47
53
// get the owners of the channel
48
- const recipients = await getOwnersInChannel ( channel . id ) ;
54
+ const [
55
+ ownersInCommunity ,
56
+ moderatorsInCommunity ,
57
+ ownersInChannel ,
58
+ moderatorsInChannel ,
59
+ ] = await Promise . all ( [
60
+ getOwnersInCommunity ( channel . communityId ) ,
61
+ getModeratorsInCommunity ( channel . communityId ) ,
62
+ getOwnersInChannel ( channel . id ) ,
63
+ getModeratorsInChannel ( channel . id ) ,
64
+ ] ) ;
65
+
66
+ const uniqueRecipientIds = [
67
+ ...ownersInCommunity ,
68
+ ...moderatorsInCommunity ,
69
+ ...ownersInChannel ,
70
+ ...moderatorsInChannel ,
71
+ ] . filter ( ( item , i , ar ) => ar . indexOf ( item ) === i ) ;
49
72
50
73
// get all the user data for the owners
51
- const recipientsWithUserData = await getUsers ( [ ...recipients ] ) ;
74
+ const recipientsWithUserData = await getUsers ( [ ...uniqueRecipientIds ] ) ;
52
75
53
- // only get owners with emails
76
+ // only get owners + moderators with emails
54
77
const filteredRecipients = recipientsWithUserData . filter (
55
78
owner => owner . email && isEmail ( owner . email )
56
79
) ;
0 commit comments