@@ -12,6 +12,8 @@ import com.onesignal.core.internal.startup.IStartableService
1212import com.onesignal.core.internal.time.ITime
1313import com.onesignal.debug.LogLevel
1414import com.onesignal.debug.internal.logging.Logging
15+ import com.onesignal.user.internal.backend.IdentityConstants
16+ import com.onesignal.user.internal.identity.IdentityModelStore
1517import com.onesignal.user.internal.operations.impl.states.NewRecordsState
1618import kotlinx.coroutines.CompletableDeferred
1719import kotlinx.coroutines.CoroutineScope
@@ -27,6 +29,7 @@ internal class OperationRepo(
2729 executors : List <IOperationExecutor >,
2830 private val _operationModelStore : OperationModelStore ,
2931 private val _configModelStore : ConfigModelStore ,
32+ private val _identityModelStore : IdentityModelStore ,
3033 private val _time : ITime ,
3134 private val _newRecordState : NewRecordsState ,
3235) : IOperationRepo, IStartableService {
@@ -377,13 +380,32 @@ internal class OperationRepo(
377380
378381 internal fun getNextOps (bucketFilter : Int ): List <OperationQueueItem >? {
379382 return synchronized(queue) {
380- val startingOp =
381- queue.firstOrNull {
382- it.operation.canStartExecute &&
383- _newRecordState .canAccess(it.operation.applyToRecordId) &&
384- it.bucket <= bucketFilter
383+ var startingOp: OperationQueueItem ? = null
384+ // Search for the first operation that is qualified to execute
385+ for (queueItem in queue) {
386+ val operation = queueItem.operation
387+
388+ // Ensure the operation is in an executable state
389+ if (! operation.canStartExecute ||
390+ ! _newRecordState .canAccess(
391+ operation.applyToRecordId,
392+ ) || queueItem.bucket > bucketFilter
393+ ) {
394+ continue
385395 }
386396
397+ // Ensure the operation does not have empty JWT if identity verification is on
398+ if (_configModelStore .model.useIdentityVerification &&
399+ operation.hasProperty(IdentityConstants .EXTERNAL_ID ) &&
400+ _identityModelStore .model.jwtToken.isNullOrEmpty()
401+ ) {
402+ continue
403+ }
404+
405+ startingOp = queueItem
406+ break
407+ }
408+
387409 if (startingOp != null ) {
388410 queue.remove(startingOp)
389411 getGroupableOperations(startingOp)
0 commit comments