mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-25 21:36:56 +02:00
Continues the migration to use full parsed Addresses instead of just addressIds on the Local Cache. Moves the community route to take a full address.
This commit is contained in:
@@ -313,7 +313,7 @@ object LocalCache : ILocalCache {
|
||||
|
||||
fun getAddressableNoteIfExists(key: String): AddressableNote? = Address.parse(key)?.let { addressables.get(it) }
|
||||
|
||||
fun getAddressableNoteIfExists(address: Address): AddressableNote? = getAddressableNoteIfExists(address)
|
||||
fun getAddressableNoteIfExists(address: Address): AddressableNote? = addressables.get(address)
|
||||
|
||||
fun getNoteIfExists(key: String): Note? = if (key.length == 64) notes.get(key) else Address.parse(key)?.let { addressables.get(it) }
|
||||
|
||||
@@ -2968,7 +2968,7 @@ object LocalCache : ILocalCache {
|
||||
|
||||
if (event is AddressableEvent && relay != null) {
|
||||
// updates relay with a new event.
|
||||
getAddressableNoteIfExists(event.addressTag())?.let { note ->
|
||||
getAddressableNoteIfExists(event.address())?.let { note ->
|
||||
note.event?.let { existingEvent ->
|
||||
if (existingEvent.createdAt > event.createdAt && !note.hasRelay(relay.url)) {
|
||||
Log.d("LocalCache", "Updating ${relay.url.url} with a new version of ${event.toJson()} to ${existingEvent.toJson()}")
|
||||
|
@@ -180,7 +180,7 @@ fun uriToRoute(
|
||||
|
||||
is NAddress -> {
|
||||
if (nip19.kind == CommunityDefinitionEvent.KIND) {
|
||||
Route.Community(nip19.aTag())
|
||||
Route.Community(nip19.kind, nip19.author, nip19.dTag)
|
||||
} else if (nip19.kind == LiveActivitiesEvent.KIND) {
|
||||
Route.Channel(nip19.aTag())
|
||||
} else {
|
||||
|
@@ -91,6 +91,7 @@ import com.vitorpamplona.amethyst.ui.screen.loggedOff.AddAccountDialog
|
||||
import com.vitorpamplona.amethyst.ui.uriToRoute
|
||||
import com.vitorpamplona.quartz.experimental.ephemChat.chat.RoomId
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.normalizer.RelayUrlNormalizer
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip19Bech32.Nip19Parser
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -134,7 +135,7 @@ fun AppNavigation(
|
||||
composableFromEndArgs<Route.Note> { ThreadScreen(it.id, accountViewModel, nav) }
|
||||
composableFromEndArgs<Route.Hashtag> { HashtagScreen(it, accountViewModel, nav) }
|
||||
composableFromEndArgs<Route.Geohash> { GeoHashScreen(it, accountViewModel, nav) }
|
||||
composableFromEndArgs<Route.Community> { CommunityScreen(it.id, accountViewModel, nav) }
|
||||
composableFromEndArgs<Route.Community> { CommunityScreen(Address(it.kind, it.pubKeyHex, it.dTag), accountViewModel, nav) }
|
||||
composableFromEndArgs<Route.Room> { ChatroomScreen(it.id.toString(), it.message, it.replyId, it.draftId, accountViewModel, nav) }
|
||||
composableFromEndArgs<Route.RoomByAuthor> { ChatroomByAuthorScreen(it.id, null, accountViewModel, nav) }
|
||||
composableFromEndArgs<Route.Channel> { ChannelScreen(it.id, accountViewModel, nav) }
|
||||
|
@@ -102,7 +102,7 @@ fun routeFor(
|
||||
loggedIn.createChatroom(room)
|
||||
return Route.Room(room.hashCode())
|
||||
} else if (noteEvent is CommunityDefinitionEvent) {
|
||||
return Route.Community(noteEvent.aTag().toTag())
|
||||
return Route.Community(noteEvent.kind, noteEvent.pubKey, noteEvent.dTag())
|
||||
} else if (noteEvent is AddressableEvent) {
|
||||
return Route.Note(noteEvent.aTag().toTag())
|
||||
} else {
|
||||
|
@@ -80,7 +80,9 @@ sealed class Route {
|
||||
) : Route()
|
||||
|
||||
@Serializable data class Community(
|
||||
val id: String,
|
||||
val kind: Int,
|
||||
val pubKeyHex: HexKey,
|
||||
val dTag: String,
|
||||
) : Route()
|
||||
|
||||
@Serializable data class Channel(
|
||||
|
@@ -88,30 +88,6 @@ fun LoadDecryptedContentOrNull(
|
||||
inner(decryptedContent)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LoadAddressableNote(
|
||||
aTagHex: String,
|
||||
accountViewModel: AccountViewModel,
|
||||
content: @Composable (AddressableNote?) -> Unit,
|
||||
) {
|
||||
var note by
|
||||
remember(aTagHex) {
|
||||
mutableStateOf<AddressableNote?>(accountViewModel.getAddressableNoteIfExists(aTagHex))
|
||||
}
|
||||
|
||||
if (note == null) {
|
||||
LaunchedEffect(key1 = aTagHex) {
|
||||
accountViewModel.checkGetOrCreateAddressableNote(aTagHex) { newNote ->
|
||||
if (newNote != note) {
|
||||
note = newNote
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
content(note)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun LoadAddressableNote(
|
||||
address: Address,
|
||||
@@ -120,7 +96,7 @@ fun LoadAddressableNote(
|
||||
) {
|
||||
var note by
|
||||
remember(address) {
|
||||
mutableStateOf(accountViewModel.getAddressableNoteIfExists(address.toValue()))
|
||||
mutableStateOf(accountViewModel.getAddressableNoteIfExists(address))
|
||||
}
|
||||
|
||||
if (note == null) {
|
||||
|
@@ -93,6 +93,7 @@ import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
import com.vitorpamplona.amethyst.ui.theme.placeholderText
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
import com.vitorpamplona.quartz.nip30CustomEmoji.CustomEmoji
|
||||
import com.vitorpamplona.quartz.nip30CustomEmoji.EmojiUrlTag
|
||||
import com.vitorpamplona.quartz.nip30CustomEmoji.selection.EmojiPackSelectionEvent
|
||||
@@ -386,7 +387,7 @@ private fun EmojiSelector(
|
||||
) { emptyNote ->
|
||||
emptyNote?.let { usersEmojiList ->
|
||||
val collections by observeNoteEventAndMap(usersEmojiList, accountViewModel) { event: EmojiPackSelectionEvent ->
|
||||
event.emojiPackIds().toImmutableList()
|
||||
event.emojiPacks().toImmutableList()
|
||||
}
|
||||
|
||||
collections?.let { EmojiCollectionGallery(it, accountViewModel, nav, onClick) }
|
||||
@@ -396,7 +397,7 @@ private fun EmojiSelector(
|
||||
|
||||
@Composable
|
||||
fun EmojiCollectionGallery(
|
||||
emojiCollections: ImmutableList<String>,
|
||||
emojiCollections: ImmutableList<Address>,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
onClick: ((EmojiUrlTag) -> Unit)? = null,
|
||||
|
@@ -102,7 +102,7 @@ fun ObserveRelayListForDMs(
|
||||
inner: @Composable (relayListEvent: ChatMessageRelayListEvent?) -> Unit,
|
||||
) {
|
||||
LoadAddressableNote(
|
||||
ChatMessageRelayListEvent.createAddressTag(pubkey),
|
||||
ChatMessageRelayListEvent.createAddress(pubkey),
|
||||
accountViewModel,
|
||||
) { relayList ->
|
||||
if (relayList != null) {
|
||||
|
@@ -59,7 +59,7 @@ private fun DisplayCommunity(
|
||||
|
||||
val displayTag =
|
||||
remember(note) {
|
||||
buildLinkString(getCommunityShortName(communityTag)) { nav.nav(Route.Community(communityTag.toTag())) }
|
||||
buildLinkString(getCommunityShortName(communityTag)) { nav.nav(Route.Community(communityTag.kind, communityTag.pubKeyHex, communityTag.dTag)) }
|
||||
}
|
||||
|
||||
Text(
|
||||
|
@@ -170,7 +170,7 @@ class FollowListState(
|
||||
"Community/${communityNote.idHex}",
|
||||
CommunityName(communityNote),
|
||||
CodeNameType.ROUTE,
|
||||
route = Route.Community(communityNote.idHex),
|
||||
route = Route.Community(communityNote.address.kind, communityNote.address.pubKeyHex, communityNote.address.dTag),
|
||||
kinds = DEFAULT_COMMUNITY_FEEDS,
|
||||
aTags = listOf(communityNote.idHex),
|
||||
)
|
||||
|
@@ -42,16 +42,15 @@ import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.communities.dal.CommunityFeedViewModel
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.communities.datasource.CommunityFilterAssemblerSubscription
|
||||
import com.vitorpamplona.amethyst.ui.theme.BottomTopHeight
|
||||
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||
|
||||
@Composable
|
||||
fun CommunityScreen(
|
||||
aTagHex: String?,
|
||||
aTagHex: Address,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
) {
|
||||
if (aTagHex == null) return
|
||||
|
||||
LoadAddressableNote(aTagHex = aTagHex, accountViewModel) {
|
||||
LoadAddressableNote(aTagHex, accountViewModel) {
|
||||
it?.let {
|
||||
PrepareViewModelsCommunityScreen(
|
||||
note = it,
|
||||
@@ -94,7 +93,7 @@ fun CommunityScreen(
|
||||
DisappearingScaffold(
|
||||
isInvertedLayout = false,
|
||||
topBar = {
|
||||
CommunityTopBar(note.idHex, accountViewModel, nav)
|
||||
CommunityTopBar(note.address, accountViewModel, nav)
|
||||
},
|
||||
floatingButton = {
|
||||
NewCommunityNoteButton(note.idHex, accountViewModel, nav)
|
||||
@@ -116,11 +115,11 @@ fun CommunityScreen(
|
||||
|
||||
@Composable
|
||||
fun CommunityTopBar(
|
||||
id: String,
|
||||
id: Address,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
) {
|
||||
LoadAddressableNote(aTagHex = id, accountViewModel) { baseNote ->
|
||||
LoadAddressableNote(id, accountViewModel) { baseNote ->
|
||||
if (baseNote != null) {
|
||||
TopBarExtensibleWithBackButton(
|
||||
title = { ShortCommunityHeader(baseNote, accountViewModel, nav) },
|
||||
|
@@ -101,7 +101,7 @@ fun ObserveRelayListForSearch(
|
||||
inner: @Composable (relayListEvent: SearchRelayListEvent?) -> Unit,
|
||||
) {
|
||||
LoadAddressableNote(
|
||||
SearchRelayListEvent.createAddressTag(pubkey),
|
||||
SearchRelayListEvent.createAddress(pubkey),
|
||||
accountViewModel,
|
||||
) { relayList ->
|
||||
if (relayList != null) {
|
||||
|
Reference in New Issue
Block a user