Migrates contact list management to addressable notes

Creates new observable flows for LocalCache.
This commit is contained in:
Vitor Pamplona
2026-02-06 16:12:11 -05:00
parent 130a83f0b9
commit ec629ff081
25 changed files with 563 additions and 590 deletions
@@ -28,13 +28,10 @@ import com.vitorpamplona.amethyst.commons.model.nip56Reports.UserReportCache
import com.vitorpamplona.amethyst.commons.model.trustedAssertions.UserCardsCache
import com.vitorpamplona.amethyst.commons.util.toShortDisplay
import com.vitorpamplona.quartz.lightning.Lud06
import com.vitorpamplona.quartz.nip01Core.core.HexKey
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
import com.vitorpamplona.quartz.nip01Core.metadata.UserMetadata
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
import com.vitorpamplona.quartz.nip01Core.tags.people.PTag
import com.vitorpamplona.quartz.nip01Core.tags.people.isTaggedUser
import com.vitorpamplona.quartz.nip02FollowList.ContactListEvent
import com.vitorpamplona.quartz.nip17Dm.settings.ChatMessageRelayListEvent
import com.vitorpamplona.quartz.nip19Bech32.entities.NProfile
import com.vitorpamplona.quartz.nip19Bech32.toNpub
@@ -58,8 +55,6 @@ class User(
private var cards: UserCardsCache? = null
private var nip05: UserNip05Cache? = null
var latestContactList: ContactListEvent? = null
var zaps = mapOf<Note, Note?>()
private set
@@ -128,20 +123,6 @@ class User(
?.info
?.lnAddress()
fun updateContactList(event: ContactListEvent): Set<HexKey> {
if (event.id == latestContactList?.id) return emptySet()
val oldContactListEvent = latestContactList
latestContactList = event
// Update following of the current user
flowSet?.follows?.invalidateData()
val affectedUsers = event.verifiedFollowKeySet() + (oldContactListEvent?.verifiedFollowKeySet() ?: emptySet())
return affectedUsers
}
fun addZap(
zapRequest: Note,
zap: Note?,
@@ -214,10 +195,6 @@ class User(
nip05StateOrNull()?.newMetadata(newUserInfo.nip05, metaEvent.pubKey)
}
fun isFollowing(user: User): Boolean = latestContactList?.isTaggedUser(user.pubkeyHex) ?: false
fun transientFollowCount(): Int? = latestContactList?.unverifiedFollowKeySet()?.size
fun reportsOrNull(): UserReportCache? = reports
fun reports(): UserReportCache = reports ?: UserReportCache().also { reports = it }
@@ -322,16 +299,12 @@ class UserFlowSet(
u: User,
) {
// Observers line up here.
val follows = UserBundledRefresherFlow(u)
val followers = UserBundledRefresherFlow(u)
val usedRelays = UserBundledRefresherFlow(u)
val zaps = UserBundledRefresherFlow(u)
val statuses = UserBundledRefresherFlow(u)
fun isInUse(): Boolean =
follows.hasObservers() ||
followers.hasObservers() ||
usedRelays.hasObservers() ||
usedRelays.hasObservers() ||
zaps.hasObservers() ||
statuses.hasObservers()
}
@@ -50,9 +50,7 @@ sealed interface Nip05State {
fun reset() = verificationState.tryEmit(Nip05VerifState.NotStarted)
suspend fun checkAndUpdate(nip05Client: Nip05Client) {
println("AABBCC checkAndUpdate $nip05")
if (verificationState.value.isExpired()) {
println("AABBCC Veryfing $nip05")
markAsVerifying()
try {
if (nip05Client.verify(nip05, hexKey)) {