@@ -15,8 +15,9 @@ import kotlinx.coroutines.flow.debounce
1515import kotlinx.coroutines.launch
1616import kotlinx.coroutines.withContext
1717import to.bitkit.di.BgDispatcher
18+ import to.bitkit.ext.rawId
1819import to.bitkit.repositories.ActivityRepo
19- import to.bitkit.repositories.LightningRepo
20+ import to.bitkit.repositories.WalletRepo
2021import to.bitkit.services.CoreService
2122import to.bitkit.services.LdkNodeEventBus
2223import to.bitkit.ui.screens.wallets.activity.components.ActivityTab
@@ -27,9 +28,9 @@ import javax.inject.Inject
2728class ActivityListViewModel @Inject constructor(
2829 @BgDispatcher private val bgDispatcher : CoroutineDispatcher ,
2930 private val coreService : CoreService ,
30- private val lightningRepo : LightningRepo ,
31+ private val walletRepo : WalletRepo ,
3132 private val ldkNodeEventBus : LdkNodeEventBus ,
32- private val activityRepo : ActivityRepo
33+ private val activityRepo : ActivityRepo ,
3334) : ViewModel() {
3435 private val _filteredActivities = MutableStateFlow <List <Activity >? > (null )
3536 val filteredActivities = _filteredActivities .asStateFlow()
@@ -224,6 +225,7 @@ class ActivityListViewModel @Inject constructor(
224225 viewModelScope.launch {
225226 activityRepo.syncActivities().onSuccess {
226227 syncState()
228+ syncActivityTags()
227229 }.onFailure { e ->
228230 Logger .error(" Failed to sync ldk-node payments" , e)
229231 }
@@ -243,4 +245,25 @@ class ActivityListViewModel @Inject constructor(
243245 syncState()
244246 }
245247 }
248+
249+ private fun syncActivityTags () {
250+ viewModelScope.launch {
251+ walletRepo.getAllInvoiceTags().onSuccess { invoiceTags ->
252+ invoiceTags.forEach { tagEntity ->
253+ activityRepo.findActivityByPaymentId(
254+ paymentHashOrTxId = tagEntity.paymentHash,
255+ type = ActivityFilter .ALL ,
256+ txType = null
257+ ).onSuccess { activity ->
258+ activityRepo.addTagsToActivity(
259+ activityId = activity.rawId(),
260+ tags = tagEntity.tags
261+ ).onSuccess {
262+ walletRepo.deleteInvoice(tagEntity.paymentHash)
263+ }
264+ }
265+ }
266+ }
267+ }
268+ }
246269}
0 commit comments