Skip to content

Commit

Permalink
Do not register to distrib from UnifiedPushReceiver
Browse files Browse the repository at this point in the history
To avoid a loop if a distributor changes the endpoint for
every new registration request
  • Loading branch information
p1gp1g committed Dec 9, 2024
1 parent 6e9e089 commit 891d030
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class UnifiedPushReceiver : MessagingReceiver() {
message.contains("\"test\":true") -> {
Log.d(TAG, "Test message received.")
UnifiedPushNotificationBuilder(context).setNotificationTest()
AppDependencies.jobManager.add(UnifiedPushRefreshJob())
AppDependencies.jobManager.add(UnifiedPushRefreshJob(testPing = false, registerDistrib = false))
}

else -> {
Expand All @@ -117,7 +117,7 @@ class UnifiedPushReceiver : MessagingReceiver() {
val stored = SignalStore.unifiedpush.endpoint
return if (endpoint != stored) {
SignalStore.unifiedpush.endpoint = endpoint
AppDependencies.jobManager.add(UnifiedPushRefreshJob())
AppDependencies.jobManager.add(UnifiedPushRefreshJob(testPing = false, registerDistrib = false))
true
} else false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ import java.util.concurrent.TimeUnit
*/
class UnifiedPushRefreshJob private constructor(
private val testPing: Boolean,
private val registerDistrib: Boolean,
parameters: Parameters,
) : BaseJob(parameters) {

constructor() : this(testPing = false)

constructor(testPing: Boolean) : this(
constructor(testPing: Boolean) : this(testPing = testPing, registerDistrib = true)

constructor(testPing: Boolean, registerDistrib: Boolean) : this(
testPing = testPing,
registerDistrib = registerDistrib,
parameters = Parameters.Builder()
.setQueue(FcmRefreshJob.QUEUE_KEY)
.addConstraint(NetworkConstraint.KEY)
Expand Down Expand Up @@ -107,7 +111,9 @@ class UnifiedPushRefreshJob private constructor(
}
}

UnifiedPushDistributor.registerApp(vapid)
if (registerDistrib) {
UnifiedPushDistributor.registerApp(vapid)
}

if (!UnifiedPushDistributor.checkIfActive() || endpoint == null) {
Log.e(TAG, "Distributor is not active or endpoint is missing.")
Expand Down Expand Up @@ -163,6 +169,7 @@ class UnifiedPushRefreshJob private constructor(
override fun serialize(): ByteArray? {
return JsonJobData.Builder()
.putBoolean(KEY_PING, testPing)
.putBoolean(KEY_REGISTER, registerDistrib)
.serialize()
}

Expand All @@ -173,6 +180,7 @@ class UnifiedPushRefreshJob private constructor(
val data = JsonJobData.deserialize(serializedData)
return UnifiedPushRefreshJob(
testPing = data.getBoolean(KEY_PING),
registerDistrib = data.getBoolean(KEY_REGISTER),
parameters = parameters,
)
}
Expand All @@ -183,5 +191,6 @@ class UnifiedPushRefreshJob private constructor(

const val KEY = "UnifiedPushRefreshJob"
private const val KEY_PING = "ping"
private const val KEY_REGISTER = "register"
}
}

0 comments on commit 891d030

Please sign in to comment.