@@ -9,12 +9,14 @@ import { ExecutorResult } from './ExecutorResult';
99import Log from '../../shared/libraries/Log' ;
1010import Database from '../../shared/services/Database' ;
1111import LocalStorage from '../../shared/utils/LocalStorage' ;
12+ import { NewRecordsState } from '../../shared/models/NewRecordsState' ;
1213
1314const RETRY_AFTER = 5_000 ;
1415
1516export default abstract class ExecutorBase {
1617 protected _deltaQueue : CoreDelta < SupportedModel > [ ] = [ ] ;
1718 protected _operationQueue : Operation < SupportedModel > [ ] = [ ] ;
19+ protected _newRecordsState : NewRecordsState ;
1820
1921 protected _executeAdd ?: (
2022 operation : Operation < SupportedModel > ,
@@ -31,7 +33,10 @@ export default abstract class ExecutorBase {
3133 static OPERATIONS_BATCH_PROCESSING_TIME = 5 ;
3234 static RETRY_COUNT = 5 ;
3335
34- constructor ( executorConfig : ExecutorConfig < SupportedModel > ) {
36+ constructor (
37+ executorConfig : ExecutorConfig < SupportedModel > ,
38+ newRecordsState : NewRecordsState ,
39+ ) {
3540 setInterval ( ( ) => {
3641 Log . debug ( 'OneSignal: checking for operations to process from cache' ) ;
3742 const cachedOperations = this . getOperationsFromCache ( ) ;
@@ -48,6 +53,8 @@ export default abstract class ExecutorBase {
4853 this . _executeAdd = executorConfig . add ;
4954 this . _executeUpdate = executorConfig . update ;
5055 this . _executeRemove = executorConfig . remove ;
56+
57+ this . _newRecordsState = newRecordsState ;
5158 }
5259
5360 abstract processDeltaQueue ( ) : void ;
@@ -124,7 +131,7 @@ export default abstract class ExecutorBase {
124131 if ( operation ) {
125132 OperationCache . enqueue ( operation ) ;
126133
127- if ( this . onlineStatus ) {
134+ if ( this . _canExecute ( operation ) ) {
128135 this . _processOperation ( operation , ExecutorBase . RETRY_COUNT ) . catch (
129136 ( err ) => {
130137 Log . error ( err ) ;
@@ -187,4 +194,18 @@ export default abstract class ExecutorBase {
187194 this . _processOperationQueue . call ( this ) ;
188195 }
189196 }
197+
198+ private _canExecute ( operation : Operation < SupportedModel > ) : boolean {
199+ if ( ! this . onlineStatus ) {
200+ return false ;
201+ }
202+
203+ if ( operation . applyToRecordId ) {
204+ if ( ! this . _newRecordsState . canAccess ( operation . applyToRecordId ) ) {
205+ return false ;
206+ }
207+ }
208+
209+ return true ;
210+ }
190211}
0 commit comments