@@ -11,6 +11,8 @@ import com.onesignal.core.internal.startup.IStartableService
1111import com.onesignal.core.internal.time.ITime
1212import com.onesignal.debug.LogLevel
1313import com.onesignal.debug.internal.logging.Logging
14+ import com.onesignal.user.internal.backend.IdentityConstants
15+ import com.onesignal.user.internal.identity.IdentityModelStore
1416import com.onesignal.user.internal.operations.impl.states.NewRecordsState
1517import kotlinx.coroutines.CompletableDeferred
1618import kotlinx.coroutines.CoroutineScope
@@ -26,6 +28,7 @@ internal class OperationRepo(
2628 executors : List <IOperationExecutor >,
2729 private val _operationModelStore : OperationModelStore ,
2830 private val _configModelStore : ConfigModelStore ,
31+ private val _identityModelStore : IdentityModelStore ,
2932 private val _time : ITime ,
3033 private val _newRecordState : NewRecordsState ,
3134) : IOperationRepo, IStartableService {
@@ -359,13 +362,32 @@ internal class OperationRepo(
359362
360363 internal fun getNextOps (bucketFilter : Int ): List <OperationQueueItem >? {
361364 return synchronized(queue) {
362- val startingOp =
363- queue.firstOrNull {
364- it.operation.canStartExecute &&
365- _newRecordState .canAccess(it.operation.applyToRecordId) &&
366- it.bucket <= bucketFilter
365+ var startingOp: OperationQueueItem ? = null
366+ // Search for the first operation that is qualified to execute
367+ for (queueItem in queue) {
368+ val operation = queueItem.operation
369+
370+ // Ensure the operation is in an executable state
371+ if (! operation.canStartExecute ||
372+ ! _newRecordState .canAccess(
373+ operation.applyToRecordId,
374+ ) || queueItem.bucket > bucketFilter
375+ ) {
376+ continue
367377 }
368378
379+ // Ensure the operation does not have empty JWT if identity verification is on
380+ if (_configModelStore .model.useIdentityVerification &&
381+ operation.hasProperty(IdentityConstants .EXTERNAL_ID ) &&
382+ _identityModelStore .model.jwtToken.isNullOrEmpty()
383+ ) {
384+ continue
385+ }
386+
387+ startingOp = queueItem
388+ break
389+ }
390+
369391 if (startingOp != null ) {
370392 queue.remove(startingOp)
371393 getGroupableOperations(startingOp)
0 commit comments