Skip to content

Commit 81a5c37

Browse files
committed
refactor: remove self variable
1 parent 58eca81 commit 81a5c37

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

app/src/main/java/to/bitkit/fcm/WakeNodeWorker.kt

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ class WakeNodeWorker @AssistedInject constructor(
5252
private val settingsStore: SettingsStore,
5353
private val cacheStore: CacheStore,
5454
) : CoroutineWorker(appContext, workerParams) {
55-
private val self = this
56-
5755
private var bestAttemptContent: NotificationDetails? = null
5856

5957
private var notificationType: BlocktankNotificationType? = null
@@ -83,7 +81,7 @@ class WakeNodeWorker @AssistedInject constructor(
8381
lightningRepo.connectToTrustedPeers()
8482

8583
// Once node is started, handle the manual channel opening if needed
86-
if (self.notificationType == orderPaymentConfirmed) {
84+
if (notificationType == orderPaymentConfirmed) {
8785
val orderId = (notificationPayload?.get("orderId") as? JsonPrimitive)?.contentOrNull
8886

8987
if (orderId == null) {
@@ -94,11 +92,11 @@ class WakeNodeWorker @AssistedInject constructor(
9492
coreService.blocktank.open(orderId = orderId)
9593
} catch (e: Exception) {
9694
Logger.error("failed to open channel", e)
97-
self.bestAttemptContent = NotificationDetails(
95+
bestAttemptContent = NotificationDetails(
9896
title = appContext.getString(R.string.notification_channel_open_failed_title),
9997
body = e.message ?: appContext.getString(R.string.notification_unknown_error),
10098
)
101-
self.deliver()
99+
deliver()
102100
}
103101
}
104102
}
@@ -108,12 +106,12 @@ class WakeNodeWorker @AssistedInject constructor(
108106
} catch (e: Exception) {
109107
val reason = e.message ?: appContext.getString(R.string.notification_unknown_error)
110108

111-
self.bestAttemptContent = NotificationDetails(
109+
bestAttemptContent = NotificationDetails(
112110
title = appContext.getString(R.string.notification_lightning_error_title),
113111
body = reason,
114112
)
115113
Logger.error("Lightning error", e)
116-
self.deliver()
114+
deliver()
117115

118116
return Result.failure(workDataOf("Reason" to reason))
119117
}
@@ -130,7 +128,7 @@ class WakeNodeWorker @AssistedInject constructor(
130128
is Event.PaymentReceived -> onPaymentReceived(event, showDetails, hiddenBody)
131129

132130
is Event.ChannelPending -> {
133-
self.bestAttemptContent = NotificationDetails(
131+
bestAttemptContent = NotificationDetails(
134132
title = appContext.getString(R.string.notification_channel_opened_title),
135133
body = appContext.getString(R.string.notification_channel_pending_body),
136134
)
@@ -141,13 +139,13 @@ class WakeNodeWorker @AssistedInject constructor(
141139
is Event.ChannelClosed -> onChannelClosed(event)
142140

143141
is Event.PaymentFailed -> {
144-
self.bestAttemptContent = NotificationDetails(
142+
bestAttemptContent = NotificationDetails(
145143
title = appContext.getString(R.string.notification_payment_failed_title),
146144
body = "${event.reason}",
147145
)
148146

149-
if (self.notificationType == wakeToTimeout) {
150-
self.deliver()
147+
if (notificationType == wakeToTimeout) {
148+
deliver()
151149
}
152150
}
153151

@@ -156,7 +154,7 @@ class WakeNodeWorker @AssistedInject constructor(
156154
}
157155

158156
private suspend fun onChannelClosed(event: Event.ChannelClosed) {
159-
self.bestAttemptContent = when (self.notificationType) {
157+
bestAttemptContent = when (notificationType) {
160158
mutualClose -> NotificationDetails(
161159
title = appContext.getString(R.string.notification_channel_closed_title),
162160
body = appContext.getString(R.string.notification_channel_closed_mutual_body),
@@ -173,7 +171,7 @@ class WakeNodeWorker @AssistedInject constructor(
173171
)
174172
}
175173

176-
self.deliver()
174+
deliver()
177175
}
178176

179177
private suspend fun onPaymentReceived(
@@ -196,8 +194,8 @@ class WakeNodeWorker @AssistedInject constructor(
196194
title = appContext.getString(R.string.notification_received_title),
197195
body = content,
198196
)
199-
if (self.notificationType == incomingHtlc) {
200-
self.deliver()
197+
if (notificationType == incomingHtlc) {
198+
deliver()
201199
}
202200
}
203201

@@ -207,16 +205,16 @@ class WakeNodeWorker @AssistedInject constructor(
207205
hiddenBody: String,
208206
) {
209207
val viaNewChannel = appContext.getString(R.string.notification_via_new_channel_body)
210-
if (self.notificationType == cjitPaymentArrived) {
211-
self.bestAttemptContent = NotificationDetails(
208+
if (notificationType == cjitPaymentArrived) {
209+
bestAttemptContent = NotificationDetails(
212210
title = appContext.getString(R.string.notification_received_title),
213211
body = viaNewChannel,
214212
)
215213

216214
lightningRepo.getChannels()?.find { it.channelId == event.channelId }?.let { channel ->
217215
val sats = channel.amountOnClose
218216
val content = if (showDetails) "$BITCOIN_SYMBOL $sats" else hiddenBody
219-
self.bestAttemptContent = NotificationDetails(
217+
bestAttemptContent = NotificationDetails(
220218
title = content,
221219
body = viaNewChannel,
222220
)
@@ -233,13 +231,13 @@ class WakeNodeWorker @AssistedInject constructor(
233231
activityRepo.insertActivityFromCjit(cjitEntry = cjitEntry, channel = channel)
234232
}
235233
}
236-
} else if (self.notificationType == orderPaymentConfirmed) {
237-
self.bestAttemptContent = NotificationDetails(
234+
} else if (notificationType == orderPaymentConfirmed) {
235+
bestAttemptContent = NotificationDetails(
238236
title = appContext.getString(R.string.notification_channel_opened_title),
239237
body = appContext.getString(R.string.notification_channel_ready_body),
240238
)
241239
}
242-
self.deliver()
240+
deliver()
243241
}
244242

245243
private suspend fun deliver() {

0 commit comments

Comments
 (0)