@@ -177,30 +177,39 @@ async function checkUserGroup(userId, bulkMessage, userGroupInfo) {
177177 try {
178178 const excludeGroupSign = '!'
179179 const groups = _ . get ( bulkMessage , 'recipients.groups' )
180+
180181 let flag = false // default
182+ let excludeGroups = [ ]
183+ let includeGroups = [ ]
184+
185+ _ . map ( groups , ( g ) => {
186+ if ( _ . startsWith ( g , excludeGroupSign ) ) {
187+ excludeGroups . push ( g )
188+ } else {
189+ includeGroups . push ( g )
190+ }
191+ } )
181192
182- if ( groups . length > 0 ) {
193+ if ( includeGroups . length > 0 ) {
183194 _ . map ( userGroupInfo , ( o ) => {
184195 // particular group only condition
185- flag = ( _ . indexOf ( groups , _ . get ( o , "name" ) ) >= 0 ) ? true : flag
196+ flag = ( _ . indexOf ( includeGroups , _ . get ( o , "name" ) ) >= 0 ) ? true : flag
186197 } )
187- } else { // no group condition means its for `public` no private group
198+ }
199+ if ( excludeGroups . length > 0 ) {
188200 flag = true // default allow for all
189- let excludeGroups = [ ]
190- _ . map ( groups , ( g ) => {
191- if ( _ . startWith ( g , excludeGroupSign ) ) {
192- excludeGroups . push ( g )
193- }
194- } )
195201 _ . map ( userGroupInfo , ( o ) => {
196202 // not allow if user is part of any private group i.e. excludeGroups
197- if ( _ . indexOf ( excludeGroups , ( excludeGroupSign + _ . get ( o , "name" ) ) ) >= 0 ) {
198- flag = false
199- }
203+ flag = ( _ . indexOf ( excludeGroups , ( excludeGroupSign + _ . get ( o , "name" ) ) ) >= 0 ) ? false : flag
200204 } )
201205 logger . info ( `public group condition for userId ${ userId } ` +
202206 ` and BC messageId ${ bulkMessage . id } , the result is: ${ flag } ` )
203207 }
208+
209+ if ( groups . length === 0 ) {
210+ flag = true // no restriction
211+ }
212+
204213 return flag
205214 } catch ( e ) {
206215 throw new Error ( `checkUserGroup(): ${ e } ` )
0 commit comments