Moves badges out of the User class
This commit is contained in:
@@ -518,7 +518,7 @@ object LocalCache {
|
|||||||
if (event.createdAt > (note.createdAt() ?: 0)) {
|
if (event.createdAt > (note.createdAt() ?: 0)) {
|
||||||
note.loadEvent(event, author, replyTo)
|
note.loadEvent(event, author, replyTo)
|
||||||
|
|
||||||
author.updateAcceptedBadges(note)
|
refreshObservers(note)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ class User(val pubkeyHex: String) {
|
|||||||
|
|
||||||
var latestContactList: ContactListEvent? = null
|
var latestContactList: ContactListEvent? = null
|
||||||
var latestBookmarkList: BookmarkListEvent? = null
|
var latestBookmarkList: BookmarkListEvent? = null
|
||||||
var latestAcceptedBadges: AddressableNote? = null
|
|
||||||
|
|
||||||
var notes = setOf<Note>()
|
var notes = setOf<Note>()
|
||||||
private set
|
private set
|
||||||
@@ -144,13 +143,6 @@ class User(val pubkeyHex: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateAcceptedBadges(note: AddressableNote) {
|
|
||||||
if (latestAcceptedBadges?.idHex != note.idHex) {
|
|
||||||
latestAcceptedBadges = note
|
|
||||||
liveSet?.badges?.invalidateData()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addZap(zapRequest: Note, zap: Note?) {
|
fun addZap(zapRequest: Note, zap: Note?) {
|
||||||
if (zapRequest !in zaps.keys) {
|
if (zapRequest !in zaps.keys) {
|
||||||
zaps = zaps + Pair(zapRequest, zap)
|
zaps = zaps + Pair(zapRequest, zap)
|
||||||
@@ -351,7 +343,6 @@ class UserLiveSet(u: User) {
|
|||||||
val relayInfo: UserLiveData = UserLiveData(u)
|
val relayInfo: UserLiveData = UserLiveData(u)
|
||||||
val metadata: UserLiveData = UserLiveData(u)
|
val metadata: UserLiveData = UserLiveData(u)
|
||||||
val zaps: UserLiveData = UserLiveData(u)
|
val zaps: UserLiveData = UserLiveData(u)
|
||||||
val badges: UserLiveData = UserLiveData(u)
|
|
||||||
val bookmarks: UserLiveData = UserLiveData(u)
|
val bookmarks: UserLiveData = UserLiveData(u)
|
||||||
|
|
||||||
fun isInUse(): Boolean {
|
fun isInUse(): Boolean {
|
||||||
@@ -363,7 +354,6 @@ class UserLiveSet(u: User) {
|
|||||||
relayInfo.hasObservers() ||
|
relayInfo.hasObservers() ||
|
||||||
metadata.hasObservers() ||
|
metadata.hasObservers() ||
|
||||||
zaps.hasObservers() ||
|
zaps.hasObservers() ||
|
||||||
badges.hasObservers() ||
|
|
||||||
bookmarks.hasObservers()
|
bookmarks.hasObservers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,5 +25,6 @@ class BadgeProfilesEvent(
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val kind = 30008
|
const val kind = 30008
|
||||||
|
const val standardDTAg = "profile_badges"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ import androidx.compose.ui.unit.sp
|
|||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.LifecycleEventObserver
|
import androidx.lifecycle.LifecycleEventObserver
|
||||||
|
import androidx.lifecycle.distinctUntilChanged
|
||||||
|
import androidx.lifecycle.map
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import com.vitorpamplona.amethyst.R
|
import com.vitorpamplona.amethyst.R
|
||||||
@@ -57,6 +59,7 @@ import com.vitorpamplona.amethyst.model.LocalCache
|
|||||||
import com.vitorpamplona.amethyst.model.Note
|
import com.vitorpamplona.amethyst.model.Note
|
||||||
import com.vitorpamplona.amethyst.model.User
|
import com.vitorpamplona.amethyst.model.User
|
||||||
import com.vitorpamplona.amethyst.service.NostrUserProfileDataSource
|
import com.vitorpamplona.amethyst.service.NostrUserProfileDataSource
|
||||||
|
import com.vitorpamplona.amethyst.service.model.ATag
|
||||||
import com.vitorpamplona.amethyst.service.model.AppDefinitionEvent
|
import com.vitorpamplona.amethyst.service.model.AppDefinitionEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.BadgeDefinitionEvent
|
import com.vitorpamplona.amethyst.service.model.BadgeDefinitionEvent
|
||||||
import com.vitorpamplona.amethyst.service.model.BadgeProfilesEvent
|
import com.vitorpamplona.amethyst.service.model.BadgeProfilesEvent
|
||||||
@@ -78,6 +81,7 @@ import com.vitorpamplona.amethyst.ui.components.figureOutMimeType
|
|||||||
import com.vitorpamplona.amethyst.ui.dal.UserProfileReportsFeedFilter
|
import com.vitorpamplona.amethyst.ui.dal.UserProfileReportsFeedFilter
|
||||||
import com.vitorpamplona.amethyst.ui.navigation.ShowQRDialog
|
import com.vitorpamplona.amethyst.ui.navigation.ShowQRDialog
|
||||||
import com.vitorpamplona.amethyst.ui.note.ClickableUserPicture
|
import com.vitorpamplona.amethyst.ui.note.ClickableUserPicture
|
||||||
|
import com.vitorpamplona.amethyst.ui.note.LoadAddressableNote
|
||||||
import com.vitorpamplona.amethyst.ui.screen.FeedState
|
import com.vitorpamplona.amethyst.ui.screen.FeedState
|
||||||
import com.vitorpamplona.amethyst.ui.screen.LnZapFeedView
|
import com.vitorpamplona.amethyst.ui.screen.LnZapFeedView
|
||||||
import com.vitorpamplona.amethyst.ui.screen.NostrUserAppRecommendationsFeedViewModel
|
import com.vitorpamplona.amethyst.ui.screen.NostrUserAppRecommendationsFeedViewModel
|
||||||
@@ -97,6 +101,7 @@ import com.vitorpamplona.amethyst.ui.theme.BitcoinOrange
|
|||||||
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
||||||
import com.vitorpamplona.amethyst.ui.theme.Size35dp
|
import com.vitorpamplona.amethyst.ui.theme.Size35dp
|
||||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||||
|
import kotlinx.collections.immutable.ImmutableList
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -1115,26 +1120,38 @@ private fun DisplayBadges(
|
|||||||
baseUser: User,
|
baseUser: User,
|
||||||
nav: (String) -> Unit
|
nav: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val userBadgeState by baseUser.live().badges.observeAsState()
|
LoadAddressableNote(
|
||||||
val badgeList by remember(userBadgeState) {
|
aTag = ATag(
|
||||||
derivedStateOf {
|
BadgeProfilesEvent.kind,
|
||||||
val list = (userBadgeState?.user?.latestAcceptedBadges?.event as? BadgeProfilesEvent)?.badgeAwardEvents()
|
baseUser.pubkeyHex,
|
||||||
if (list.isNullOrEmpty()) {
|
BadgeProfilesEvent.standardDTAg,
|
||||||
null
|
null
|
||||||
} else {
|
)
|
||||||
list.toImmutableList()
|
) {
|
||||||
|
if (it != null) {
|
||||||
|
val badgeList by it.live().metadata.map {
|
||||||
|
(it.note.event as? BadgeProfilesEvent)?.badgeAwardEvents()?.toImmutableList()
|
||||||
|
}.distinctUntilChanged().observeAsState()
|
||||||
|
|
||||||
|
badgeList?.let { list ->
|
||||||
|
RenderBadgeList(list, nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
badgeList?.let { list ->
|
@Composable
|
||||||
FlowRow(
|
@OptIn(ExperimentalLayoutApi::class)
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
private fun RenderBadgeList(
|
||||||
modifier = Modifier.padding(vertical = 5.dp)
|
list: ImmutableList<String>,
|
||||||
) {
|
nav: (String) -> Unit
|
||||||
list.forEach { badgeAwardEvent ->
|
) {
|
||||||
LoadAndRenderBadge(badgeAwardEvent, nav)
|
FlowRow(
|
||||||
}
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier.padding(vertical = 5.dp)
|
||||||
|
) {
|
||||||
|
list.forEach { badgeAwardEvent ->
|
||||||
|
LoadAndRenderBadge(badgeAwardEvent, nav)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user