Migrates to the new 10008 profile badges kind
This commit is contained in:
@@ -168,9 +168,10 @@ import com.vitorpamplona.quartz.nip54Wiki.WikiNoteEvent
|
||||
import com.vitorpamplona.quartz.nip56Reports.ReportEvent
|
||||
import com.vitorpamplona.quartz.nip57Zaps.LnZapEvent
|
||||
import com.vitorpamplona.quartz.nip57Zaps.LnZapRequestEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.accepted.AcceptedBadgeSetEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.award.BadgeAwardEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.definition.BadgeDefinitionEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.profiles.BadgeProfilesEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.profile.ProfileBadgesEvent
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.WrappedEvent
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealedRumorEvent
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
|
||||
@@ -843,7 +844,12 @@ object LocalCache : ILocalCache, ICacheProvider {
|
||||
event.taggedAddresses().map { getOrCreateAddressableNote(it) }
|
||||
}
|
||||
|
||||
is BadgeProfilesEvent -> {
|
||||
is AcceptedBadgeSetEvent -> {
|
||||
event.badgeAwardEvents().mapNotNull { checkGetOrCreateNote(it) } +
|
||||
event.badgeAwardDefinitions().map { getOrCreateAddressableNote(it) }
|
||||
}
|
||||
|
||||
is ProfileBadgesEvent -> {
|
||||
event.badgeAwardEvents().mapNotNull { checkGetOrCreateNote(it) } +
|
||||
event.badgeAwardDefinitions().map { getOrCreateAddressableNote(it) }
|
||||
}
|
||||
@@ -2539,6 +2545,7 @@ object LocalCache : ILocalCache, ICacheProvider {
|
||||
): Boolean =
|
||||
try {
|
||||
when (event) {
|
||||
is AcceptedBadgeSetEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
is AdvertisedRelayListEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
is AppDefinitionEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
is AppRecommendationEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
@@ -2551,7 +2558,6 @@ object LocalCache : ILocalCache, ICacheProvider {
|
||||
is AudioTrackEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
is BadgeAwardEvent -> consumeRegularEvent(event, relay, wasVerified)
|
||||
is BadgeDefinitionEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
is BadgeProfilesEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
is BlockedRelayListEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
is BlossomServersEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
is BroadcastRelayListEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
@@ -2635,6 +2641,7 @@ object LocalCache : ILocalCache, ICacheProvider {
|
||||
is PictureEvent -> consumeRegularEvent(event, relay, wasVerified)
|
||||
is PrivateDmEvent -> consumeRegularEvent(event, relay, wasVerified)
|
||||
is PrivateOutboxRelayListEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
is ProfileBadgesEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
is ProxyRelayListEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
is PinListEvent -> consumeBaseReplaceable(event, relay, wasVerified)
|
||||
is PublicMessageEvent -> consumeRegularEvent(event, relay, wasVerified)
|
||||
|
||||
+4
-2
@@ -30,14 +30,16 @@ import com.vitorpamplona.quartz.nip30CustomEmoji.selection.EmojiPackSelectionEve
|
||||
import com.vitorpamplona.quartz.nip51Lists.followList.FollowListEvent
|
||||
import com.vitorpamplona.quartz.nip51Lists.muteList.MuteListEvent
|
||||
import com.vitorpamplona.quartz.nip51Lists.peopleList.PeopleListEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.profiles.BadgeProfilesEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.accepted.AcceptedBadgeSetEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.profile.ProfileBadgesEvent
|
||||
|
||||
val FollowAndMutesFromKeyKinds =
|
||||
listOf(
|
||||
PeopleListEvent.KIND,
|
||||
FollowListEvent.KIND,
|
||||
MuteListEvent.KIND,
|
||||
BadgeProfilesEvent.KIND,
|
||||
AcceptedBadgeSetEvent.KIND,
|
||||
ProfileBadgesEvent.KIND,
|
||||
EmojiPackSelectionEvent.KIND,
|
||||
EphemeralChatListEvent.KIND,
|
||||
ChannelListEvent.KIND,
|
||||
|
||||
+4
-2
@@ -26,7 +26,8 @@ import com.vitorpamplona.quartz.nip01Core.relay.client.pool.RelayBasedFilter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.NormalizedRelayUrl
|
||||
import com.vitorpamplona.quartz.nip02FollowList.ContactListEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.profiles.BadgeProfilesEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.accepted.AcceptedBadgeSetEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.profile.ProfileBadgesEvent
|
||||
import com.vitorpamplona.quartz.nip65RelayList.AdvertisedRelayListEvent
|
||||
|
||||
val UserProfileMetadataKinds =
|
||||
@@ -34,7 +35,8 @@ val UserProfileMetadataKinds =
|
||||
MetadataEvent.KIND,
|
||||
AdvertisedRelayListEvent.KIND,
|
||||
ContactListEvent.KIND,
|
||||
BadgeProfilesEvent.KIND,
|
||||
AcceptedBadgeSetEvent.KIND,
|
||||
ProfileBadgesEvent.KIND,
|
||||
)
|
||||
|
||||
fun filterUserProfileMetadata(
|
||||
|
||||
+41
-14
@@ -32,13 +32,14 @@ import androidx.compose.runtime.produceState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.model.AddressableNote
|
||||
import com.vitorpamplona.amethyst.model.LocalCache
|
||||
import com.vitorpamplona.amethyst.model.Note
|
||||
import com.vitorpamplona.amethyst.model.User
|
||||
import com.vitorpamplona.amethyst.service.relayClient.reqCommand.event.EventFinderFilterAssemblerSubscription
|
||||
import com.vitorpamplona.amethyst.service.relayClient.reqCommand.event.observeNoteEvent
|
||||
import com.vitorpamplona.amethyst.service.relayClient.reqCommand.event.observeNoteEventAndMapNotNull
|
||||
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImage
|
||||
import com.vitorpamplona.amethyst.ui.components.RobohashFallbackAsyncImage
|
||||
import com.vitorpamplona.amethyst.ui.navigation.navs.INav
|
||||
@@ -49,11 +50,18 @@ import com.vitorpamplona.amethyst.ui.stringRes
|
||||
import com.vitorpamplona.amethyst.ui.theme.BadgePictureModifier
|
||||
import com.vitorpamplona.amethyst.ui.theme.Size35Modifier
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.events.ETag
|
||||
import com.vitorpamplona.quartz.nip58Badges.accepted.AcceptedBadgeSetEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.award.BadgeAwardEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.definition.BadgeDefinitionEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.profiles.BadgeProfilesEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.profile.ProfileBadgesEvent
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
|
||||
@Composable
|
||||
fun DisplayBadges(
|
||||
@@ -61,25 +69,44 @@ fun DisplayBadges(
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
) {
|
||||
LoadAddressableNote(
|
||||
BadgeProfilesEvent.createAddress(baseUser.pubkeyHex),
|
||||
accountViewModel,
|
||||
) { note ->
|
||||
if (note != null) {
|
||||
WatchAndRenderBadgeList(note, accountViewModel, nav)
|
||||
}
|
||||
}
|
||||
val oldDesign = AcceptedBadgeSetEvent.createAddress(baseUser.pubkeyHex)
|
||||
val newDesign = ProfileBadgesEvent.createAddress(baseUser.pubkeyHex)
|
||||
|
||||
val oldNote = accountViewModel.getOrCreateAddressableNote(oldDesign)
|
||||
val newNote = accountViewModel.getOrCreateAddressableNote(newDesign)
|
||||
|
||||
WatchAndRenderBadgeList(oldNote, newNote, accountViewModel, nav)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun WatchAndRenderBadgeList(
|
||||
note: AddressableNote,
|
||||
oldNote: AddressableNote,
|
||||
newNote: AddressableNote,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
) {
|
||||
val badgeList by observeNoteEventAndMapNotNull(note, accountViewModel) { event: BadgeProfilesEvent ->
|
||||
event.badgeAwardEvents().toImmutableList()
|
||||
}
|
||||
// Subscribe in the relay for changes in this note.
|
||||
EventFinderFilterAssemblerSubscription(oldNote, accountViewModel)
|
||||
EventFinderFilterAssemblerSubscription(newNote, accountViewModel)
|
||||
|
||||
// Subscribe in the LocalCache for changes that arrive in the device
|
||||
val flow =
|
||||
remember(oldNote, newNote) {
|
||||
combine(
|
||||
oldNote.flow().metadata.stateFlow,
|
||||
newNote.flow().metadata.stateFlow,
|
||||
) { oldNote, newNote ->
|
||||
val oldProfileBadgeEvent = oldNote.note.event as? AcceptedBadgeSetEvent
|
||||
val newProfileBadgeEvent = newNote.note.event as? ProfileBadgesEvent
|
||||
|
||||
newProfileBadgeEvent?.badgeAwardEvents()?.toImmutableList()
|
||||
?: oldProfileBadgeEvent?.badgeAwardEvents()?.toImmutableList()
|
||||
}.distinctUntilChanged()
|
||||
.flowOn(Dispatchers.IO)
|
||||
}
|
||||
|
||||
// Subscribe in the LocalCache for changes that arrive in the device
|
||||
val badgeList by flow.collectAsStateWithLifecycle(persistentListOf())
|
||||
|
||||
badgeList?.let { list -> RenderBadgeList(list, accountViewModel, nav) }
|
||||
}
|
||||
|
||||
+4
-2
@@ -233,9 +233,10 @@ import com.vitorpamplona.quartz.nip56Reports.ReportEvent
|
||||
import com.vitorpamplona.quartz.nip57Zaps.LnZapEvent
|
||||
import com.vitorpamplona.quartz.nip57Zaps.LnZapPrivateEvent
|
||||
import com.vitorpamplona.quartz.nip57Zaps.LnZapRequestEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.accepted.AcceptedBadgeSetEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.award.BadgeAwardEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.definition.BadgeDefinitionEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.profiles.BadgeProfilesEvent
|
||||
import com.vitorpamplona.quartz.nip58Badges.profile.ProfileBadgesEvent
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.seals.SealedRumorEvent
|
||||
import com.vitorpamplona.quartz.nip59Giftwrap.wraps.GiftWrapEvent
|
||||
import com.vitorpamplona.quartz.nip62RequestToVanish.RequestToVanishEvent
|
||||
@@ -552,6 +553,7 @@ fun RelayInformationBody(
|
||||
@Suppress("DEPRECATION")
|
||||
fun kindDisplayName(kind: Int): Int =
|
||||
when (kind) {
|
||||
AcceptedBadgeSetEvent.KIND -> R.string.kind_accepted_badge_set
|
||||
AdvertisedRelayListEvent.KIND -> R.string.kind_outbox_relays
|
||||
AppDefinitionEvent.KIND -> R.string.kind_apps
|
||||
AppRecommendationEvent.KIND -> R.string.kind_app_recommendations
|
||||
@@ -564,7 +566,6 @@ fun kindDisplayName(kind: Int): Int =
|
||||
AttestorProficiencyEvent.KIND -> R.string.attestor_proficiency
|
||||
BadgeAwardEvent.KIND -> R.string.kind_badge_awards
|
||||
BadgeDefinitionEvent.KIND -> R.string.kind_badge_definitions
|
||||
BadgeProfilesEvent.KIND -> R.string.kind_profile_badges
|
||||
BlockedRelayListEvent.KIND -> R.string.kind_blocked_relays
|
||||
BlossomServersEvent.KIND -> R.string.kind_blossom_servers
|
||||
BlossomAuthorizationEvent.KIND -> R.string.kind_blossom_auth
|
||||
@@ -651,6 +652,7 @@ fun kindDisplayName(kind: Int): Int =
|
||||
OtsEvent.KIND -> R.string.kind_ots
|
||||
PaymentTargetsEvent.KIND -> R.string.kind_pay_to
|
||||
PeopleListEvent.KIND -> R.string.kind_people_lists
|
||||
ProfileBadgesEvent.KIND -> R.string.kind_profile_badges
|
||||
PictureEvent.KIND -> R.string.kind_pictures
|
||||
PinListEvent.KIND -> R.string.kind_pins
|
||||
ZapPollEvent.KIND -> R.string.kind_zap_poll
|
||||
|
||||
@@ -1744,6 +1744,7 @@
|
||||
<string name="kind_audio_track">Audio Track</string>
|
||||
<string name="kind_badge_awards">Badge Awards</string>
|
||||
<string name="kind_badge_definitions">Badge Definitions</string>
|
||||
<string name="kind_accepted_badge_set">Accepted Badge Set</string>
|
||||
<string name="kind_profile_badges">Profile Badges</string>
|
||||
<string name="kind_blocked_relays">Blocked Relays</string>
|
||||
<string name="kind_blossom_servers">Blossom Servers</string>
|
||||
|
||||
Reference in New Issue
Block a user