Limit RefreshSvrCredentialsJob to registered users.

This commit is contained in:
Greyson Parrelli 2023-07-28 17:14:27 -04:00
parent 148cff1b48
commit 2abf30e94b

View file

@ -24,7 +24,7 @@ class RefreshSvrCredentialsJob private constructor(parameters: Parameters) : Bas
@JvmStatic
fun enqueueIfNecessary() {
if (SignalStore.svr().hasPin()) {
if (SignalStore.svr().hasPin() && SignalStore.account().isRegistered) {
val lastTimestamp = SignalStore.svr().lastRefreshAuthTimestamp
if (lastTimestamp + FREQUENCY.inWholeMilliseconds < System.currentTimeMillis() || lastTimestamp > System.currentTimeMillis()) {
ApplicationDependencies.getJobManager().add(RefreshSvrCredentialsJob())
@ -40,6 +40,7 @@ class RefreshSvrCredentialsJob private constructor(parameters: Parameters) : Bas
.setQueue("RefreshKbsCredentials")
.addConstraint(NetworkConstraint.KEY)
.setMaxInstancesForQueue(2)
.setMaxAttempts(3)
.setLifespan(1.days.inWholeMilliseconds)
.build()
)
@ -49,6 +50,11 @@ class RefreshSvrCredentialsJob private constructor(parameters: Parameters) : Bas
override fun getFactoryKey(): String = KEY
override fun onRun() {
if (!SignalStore.account().isRegistered) {
Log.w(TAG, "Not registered! Skipping.")
return
}
SvrRepository.refreshAndStoreAuthorization()
}