Fixes missing cache after AI PR for the desktop app
Removes dependency on the Cache from User. Updates interface methods to match.
This commit is contained in:
@@ -22,11 +22,11 @@ package com.vitorpamplona.amethyst.commons.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.Stable
|
||||
import com.vitorpamplona.amethyst.commons.model.cache.ICacheProvider
|
||||
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.core.toImmutableListOfLists
|
||||
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.metadata.UserMetadata
|
||||
@@ -51,7 +51,6 @@ class User(
|
||||
val pubkeyHex: String,
|
||||
val nip65RelayListNote: Note,
|
||||
val dmRelayListNote: Note,
|
||||
private val cacheProvider: ICacheProvider? = null,
|
||||
) {
|
||||
private var reports: UserReportCache? = null
|
||||
private var cards: UserCardsCache? = null
|
||||
@@ -120,8 +119,8 @@ class User(
|
||||
|
||||
fun profilePicture(): String? = info?.picture
|
||||
|
||||
fun updateContactList(event: ContactListEvent) {
|
||||
if (event.id == latestContactList?.id) return
|
||||
fun updateContactList(event: ContactListEvent): Set<HexKey> {
|
||||
if (event.id == latestContactList?.id) return emptySet()
|
||||
|
||||
val oldContactListEvent = latestContactList
|
||||
latestContactList = event
|
||||
@@ -129,20 +128,9 @@ class User(
|
||||
// Update following of the current user
|
||||
flowSet?.follows?.invalidateData()
|
||||
|
||||
// Update Followers of the past user list
|
||||
// Update Followers of the new contact list
|
||||
(oldContactListEvent)?.unverifiedFollowKeySet()?.forEach {
|
||||
(cacheProvider?.getUserIfExists(it) as? User)
|
||||
?.flowSet
|
||||
?.followers
|
||||
?.invalidateData()
|
||||
}
|
||||
(latestContactList)?.unverifiedFollowKeySet()?.forEach {
|
||||
(cacheProvider?.getUserIfExists(it) as? User)
|
||||
?.flowSet
|
||||
?.followers
|
||||
?.invalidateData()
|
||||
}
|
||||
val affectedUsers = event.verifiedFollowKeySet() + (oldContactListEvent?.verifiedFollowKeySet() ?: emptySet())
|
||||
|
||||
return affectedUsers
|
||||
}
|
||||
|
||||
fun addZap(
|
||||
@@ -217,11 +205,6 @@ class User(
|
||||
|
||||
fun transientFollowCount(): Int? = latestContactList?.unverifiedFollowKeySet()?.size
|
||||
|
||||
fun transientFollowerCount(): Int =
|
||||
cacheProvider?.countUsers { _, it ->
|
||||
(it as? User)?.latestContactList?.isTaggedUser(pubkeyHex) ?: false
|
||||
} ?: 0
|
||||
|
||||
fun reportsOrNull(): UserReportCache? = reports
|
||||
|
||||
fun reports(): UserReportCache = reports ?: UserReportCache().also { reports = it }
|
||||
|
||||
Vendored
+2
-1
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.commons.model.cache
|
||||
|
||||
import com.vitorpamplona.amethyst.commons.model.User
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
|
||||
/**
|
||||
@@ -60,7 +61,7 @@ interface ICacheProvider {
|
||||
* @param predicate Filter function for counting users
|
||||
* @return Count of users matching the predicate
|
||||
*/
|
||||
fun countUsers(predicate: (String, Any) -> Boolean): Int
|
||||
fun countUsers(predicate: (String, User) -> Boolean): Int
|
||||
|
||||
/**
|
||||
* Gets a Note if it exists in cache.
|
||||
|
||||
Reference in New Issue
Block a user