Commit e39f4a35 authored by MozLando's avatar MozLando
Browse files

Merge #6706



6706: Closes #4822: Changed function name from DeliveryManager.with to DeliveryManager.runWithInitialized r=jonalmeida a=apoorv9990
Co-authored-by: default avatarapoorv9990 <patelapoorv9990@gmail.com>
parents 1a627651 465ead5b
......@@ -129,7 +129,7 @@ class AutoPushFeature(
* This should only be done on an account logout or app data deletion.
*/
override fun shutdown() {
DeliveryManager.with(connection) {
DeliveryManager.runWithInitialized(connection) {
coroutineScope.launch {
unsubscribeAll()
}
......@@ -163,7 +163,7 @@ class AutoPushFeature(
* New encrypted messages received from a supported push messaging service.
*/
override fun onMessageReceived(message: EncryptedPushMessage) {
DeliveryManager.with(connection) {
DeliveryManager.runWithInitialized(connection) {
coroutineScope.launchAndTry {
logger.info("New push message decrypted.")
......@@ -200,7 +200,7 @@ class AutoPushFeature(
onSubscribeError: () -> Unit = {},
onSubscribe: ((AutoPushSubscription) -> Unit) = {}
) {
DeliveryManager.with(connection) {
DeliveryManager.runWithInitialized(connection) {
coroutineScope.launchAndTry(errorBlock = {
onSubscribeError()
}, block = {
......@@ -222,7 +222,7 @@ class AutoPushFeature(
onUnsubscribeError: () -> Unit = {},
onUnsubscribe: (Boolean) -> Unit = {}
) {
DeliveryManager.with(connection) {
DeliveryManager.runWithInitialized(connection) {
coroutineScope.launchAndTry(errorBlock = {
onUnsubscribeError()
}, block = {
......@@ -260,7 +260,7 @@ class AutoPushFeature(
*/
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
internal fun verifyActiveSubscriptions() {
DeliveryManager.with(connection) {
DeliveryManager.runWithInitialized(connection) {
coroutineScope.launchAndTry {
val subscriptionChanges = verifyConnection()
......@@ -383,7 +383,7 @@ internal object DeliveryManager {
/**
* Executes the block if the Push Manager is initialized.
*/
fun with(connection: PushConnection, block: PushConnection.() -> Unit) {
fun runWithInitialized(connection: PushConnection, block: PushConnection.() -> Unit) {
if (connection.isInitialized()) {
block(connection)
}
......
......@@ -16,13 +16,13 @@ class DeliveryManagerTest {
val connection: PushConnection = mock()
var invoked = false
DeliveryManager.with(connection) { invoked = true }
DeliveryManager.runWithInitialized(connection) { invoked = true }
assertFalse(invoked)
`when`(connection.isInitialized()).thenReturn(true)
DeliveryManager.with(connection) { invoked = true }
DeliveryManager.runWithInitialized(connection) { invoked = true }
assertTrue(invoked)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment