Refactor FollowSetFeedFilter and Account.
This commit is contained in:
@@ -23,7 +23,6 @@ package com.vitorpamplona.amethyst.model
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import androidx.compose.ui.util.fastFilter
|
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.asLiveData
|
import androidx.lifecycle.asLiveData
|
||||||
import androidx.lifecycle.liveData
|
import androidx.lifecycle.liveData
|
||||||
@@ -33,6 +32,7 @@ import com.vitorpamplona.amethyst.BuildConfig
|
|||||||
import com.vitorpamplona.amethyst.service.FileHeader
|
import com.vitorpamplona.amethyst.service.FileHeader
|
||||||
import com.vitorpamplona.amethyst.service.NostrLnZapPaymentResponseDataSource
|
import com.vitorpamplona.amethyst.service.NostrLnZapPaymentResponseDataSource
|
||||||
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.FollowSet
|
||||||
import com.vitorpamplona.amethyst.ui.tor.TorType
|
import com.vitorpamplona.amethyst.ui.tor.TorType
|
||||||
import com.vitorpamplona.ammolite.relays.Client
|
import com.vitorpamplona.ammolite.relays.Client
|
||||||
import com.vitorpamplona.ammolite.relays.Constants
|
import com.vitorpamplona.ammolite.relays.Constants
|
||||||
@@ -108,7 +108,6 @@ import com.vitorpamplona.quartz.events.ZapSplitSetup
|
|||||||
import com.vitorpamplona.quartz.signers.NostrSigner
|
import com.vitorpamplona.quartz.signers.NostrSigner
|
||||||
import com.vitorpamplona.quartz.signers.NostrSignerInternal
|
import com.vitorpamplona.quartz.signers.NostrSignerInternal
|
||||||
import com.vitorpamplona.quartz.utils.DualCase
|
import com.vitorpamplona.quartz.utils.DualCase
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -131,6 +130,7 @@ import kotlinx.coroutines.flow.update
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import kotlinx.coroutines.suspendCancellableCoroutine
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.coroutines.withTimeoutOrNull
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
@@ -2897,17 +2897,25 @@ class Account(
|
|||||||
return LocalCache.getOrCreateAddressableNote(aTag)
|
return LocalCache.getOrCreateAddressableNote(aTag)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFollowSetNotes(): List<AddressableNote> = LocalCache.getFollowSetsFor(userProfile())
|
suspend fun getFollowSetNotes() =
|
||||||
|
withContext(Dispatchers.Default) {
|
||||||
fun loadUserFollowSets() {
|
val followSetNotes = LocalCache.getFollowSetsFor(userProfile())
|
||||||
val sets =
|
userProfile().followSets.addAll(followSetNotes)
|
||||||
getFollowSetNotes()
|
println("Number of follow sets: ${followSetNotes.size}")
|
||||||
.fastFilter { !it.dTag().isNullOrBlank() }
|
|
||||||
|
|
||||||
userProfile().followSets = sets.toImmutableList()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun followSetNotesFlow() = userProfile().flow().followSets.stateFlow
|
fun mapNoteToFollowSet(note: Note): FollowSet =
|
||||||
|
FollowSet
|
||||||
|
.mapEventToSet(
|
||||||
|
event = note.event as PeopleListEvent,
|
||||||
|
signer,
|
||||||
|
)
|
||||||
|
|
||||||
|
fun followSetNotesFlow(): MutableStateFlow<List<AddressableNote>> {
|
||||||
|
val setStateFlow = MutableStateFlow(userProfile().followSets.toList())
|
||||||
|
println("Follow set flow value: ${setStateFlow.value}")
|
||||||
|
return setStateFlow
|
||||||
|
}
|
||||||
|
|
||||||
fun getMuteListFlow(): StateFlow<NoteState> = getMuteListNote().flow().metadata.stateFlow
|
fun getMuteListFlow(): StateFlow<NoteState> = getMuteListNote().flow().metadata.stateFlow
|
||||||
|
|
||||||
@@ -3702,11 +3710,6 @@ class Account(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.launch(Dispatchers.IO) {
|
|
||||||
Log.d("AccountFollowSetsWorker", "Loading Follow Sets for Account")
|
|
||||||
loadUserFollowSets()
|
|
||||||
}
|
|
||||||
|
|
||||||
scope.launch(Dispatchers.Default) {
|
scope.launch(Dispatchers.Default) {
|
||||||
Log.d("AccountRegisterObservers", "Mute List Collector Start")
|
Log.d("AccountRegisterObservers", "Mute List Collector Start")
|
||||||
getMuteListFlow().collect {
|
getMuteListFlow().collect {
|
||||||
|
|||||||
@@ -21,17 +21,20 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.dal
|
package com.vitorpamplona.amethyst.ui.dal
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.model.Account
|
import com.vitorpamplona.amethyst.model.Account
|
||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.FollowSet
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class FollowSetFeedFilter(
|
class FollowSetFeedFilter(
|
||||||
val account: Account,
|
val account: Account,
|
||||||
) : FeedFilter<Note>() {
|
) : FeedFilter<FollowSet>() {
|
||||||
override fun feedKey(): String = account.userProfile().pubkeyHex
|
override fun feedKey(): String = account.userProfile().pubkeyHex
|
||||||
|
|
||||||
override fun feed(): List<Note> =
|
override fun feed(): List<FollowSet> {
|
||||||
account
|
if (account.userProfile().followSets.isEmpty()) {
|
||||||
.followSetNotesFlow()
|
account.scope.launch {
|
||||||
.value
|
account.getFollowSetNotes()
|
||||||
.user
|
}
|
||||||
.followSets
|
}
|
||||||
|
return account.followSetNotesFlow().value.map { account.mapNoteToFollowSet(it) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user