@@ -36,38 +36,13 @@ class NotifyPaymentReceivedHandler @Inject constructor(
3636 ): Result <NotifyPaymentReceived .Result > = withContext(ioDispatcher) {
3737 runCatching {
3838 val shouldShow = when (command) {
39- is NotifyPaymentReceived .Command .Lightning -> true
40- is NotifyPaymentReceived .Command .Onchain -> {
41- activityRepo.handleOnchainTransactionReceived(command.event.txid, command.event.details)
42- if (command.event.details.amountSats > 0 ) {
43- delay(DELAY_FOR_ACTIVITY_SYNC_MS )
44- activityRepo.shouldShowReceivedSheet(
45- command.event.txid,
46- command.event.details.amountSats.toULong()
47- )
48- } else {
49- false
50- }
51- }
39+ is NotifyPaymentReceived .Command .Lightning -> shouldShowLightning(command)
40+ is NotifyPaymentReceived .Command .Onchain -> shouldShowOnchain(command)
5241 }
5342
5443 if (! shouldShow) return @runCatching NotifyPaymentReceived .Result .Skip
5544
56- val details = NewTransactionSheetDetails (
57- type = when (command) {
58- is NotifyPaymentReceived .Command .Lightning -> NewTransactionSheetType .LIGHTNING
59- is NotifyPaymentReceived .Command .Onchain -> NewTransactionSheetType .ONCHAIN
60- },
61- direction = NewTransactionSheetDirection .RECEIVED ,
62- paymentHashOrTxId = when (command) {
63- is NotifyPaymentReceived .Command .Lightning -> command.event.paymentHash
64- is NotifyPaymentReceived .Command .Onchain -> command.event.txid
65- },
66- sats = when (command) {
67- is NotifyPaymentReceived .Command .Lightning -> (command.event.amountMsat / 1000u ).toLong()
68- is NotifyPaymentReceived .Command .Onchain -> command.event.details.amountSats
69- },
70- )
45+ val details = buildSheetDetails(command)
7146
7247 if (command.includeNotification) {
7348 val notification = buildNotificationContent(details.sats)
@@ -80,6 +55,45 @@ class NotifyPaymentReceivedHandler @Inject constructor(
8055 }
8156 }
8257
58+ private suspend fun shouldShowLightning (command : NotifyPaymentReceived .Command .Lightning ): Boolean {
59+ val paymentId = command.event.paymentId ? : return false
60+ delay(DELAY_FOR_ACTIVITY_SYNC_MS )
61+ if (activityRepo.isActivitySeen(paymentId)) return false
62+ activityRepo.markActivityAsSeen(paymentId)
63+ return true
64+ }
65+
66+ private suspend fun shouldShowOnchain (command : NotifyPaymentReceived .Command .Onchain ): Boolean {
67+ activityRepo.handleOnchainTransactionReceived(command.event.txid, command.event.details)
68+ if (command.event.details.amountSats <= 0 ) return false
69+
70+ delay(DELAY_FOR_ACTIVITY_SYNC_MS )
71+ val shouldShowSheet = activityRepo.shouldShowReceivedSheet(
72+ command.event.txid,
73+ command.event.details.amountSats.toULong()
74+ )
75+ if (shouldShowSheet) {
76+ activityRepo.markOnchainActivityAsSeen(command.event.txid)
77+ }
78+ return shouldShowSheet
79+ }
80+
81+ private fun buildSheetDetails (command : NotifyPaymentReceived .Command ) = NewTransactionSheetDetails (
82+ type = when (command) {
83+ is NotifyPaymentReceived .Command .Lightning -> NewTransactionSheetType .LIGHTNING
84+ is NotifyPaymentReceived .Command .Onchain -> NewTransactionSheetType .ONCHAIN
85+ },
86+ direction = NewTransactionSheetDirection .RECEIVED ,
87+ paymentHashOrTxId = when (command) {
88+ is NotifyPaymentReceived .Command .Lightning -> command.event.paymentHash
89+ is NotifyPaymentReceived .Command .Onchain -> command.event.txid
90+ },
91+ sats = when (command) {
92+ is NotifyPaymentReceived .Command .Lightning -> (command.event.amountMsat / 1000u ).toLong()
93+ is NotifyPaymentReceived .Command .Onchain -> command.event.details.amountSats
94+ },
95+ )
96+
8397 private suspend fun buildNotificationContent (sats : Long ): NotificationDetails {
8498 val settings = settingsStore.data.first()
8599 val title = context.getString(R .string.notification_received_title)
0 commit comments