diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt index fccb6c74b..0eb2d6a47 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/LocalCache.kt @@ -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()}") diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt index 50fb1a403..5ec963e7b 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/MainActivity.kt @@ -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 { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt index bc1c2bc36..181bcfd7c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt @@ -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 { ThreadScreen(it.id, accountViewModel, nav) } composableFromEndArgs { HashtagScreen(it, accountViewModel, nav) } composableFromEndArgs { GeoHashScreen(it, accountViewModel, nav) } - composableFromEndArgs { CommunityScreen(it.id, accountViewModel, nav) } + composableFromEndArgs { CommunityScreen(Address(it.kind, it.pubKeyHex, it.dTag), accountViewModel, nav) } composableFromEndArgs { ChatroomScreen(it.id.toString(), it.message, it.replyId, it.draftId, accountViewModel, nav) } composableFromEndArgs { ChatroomByAuthorScreen(it.id, null, accountViewModel, nav) } composableFromEndArgs { ChannelScreen(it.id, accountViewModel, nav) } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/RouteMaker.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/RouteMaker.kt index 13e608b3c..c48c8d834 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/RouteMaker.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/RouteMaker.kt @@ -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 { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/Routes.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/Routes.kt index 8a7a58c0b..14caf81b9 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/Routes.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/Routes.kt @@ -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( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt index a1fba8d9d..9fa960be4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Loaders.kt @@ -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(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) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UpdateReactionTypeDialog.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UpdateReactionTypeDialog.kt index 96acdded6..1f4fa9947 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UpdateReactionTypeDialog.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/UpdateReactionTypeDialog.kt @@ -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, + emojiCollections: ImmutableList
, accountViewModel: AccountViewModel, nav: INav, onClick: ((EmojiUrlTag) -> Unit)? = null, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/AddInboxRelayForDMCard.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/AddInboxRelayForDMCard.kt index fb58d929f..c5ba242ba 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/AddInboxRelayForDMCard.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/AddInboxRelayForDMCard.kt @@ -102,7 +102,7 @@ fun ObserveRelayListForDMs( inner: @Composable (relayListEvent: ChatMessageRelayListEvent?) -> Unit, ) { LoadAddressableNote( - ChatMessageRelayListEvent.createAddressTag(pubkey), + ChatMessageRelayListEvent.createAddress(pubkey), accountViewModel, ) { relayList -> if (relayList != null) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayCommunity.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayCommunity.kt index 2b56d6250..e27ef8051 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayCommunity.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/elements/DisplayCommunity.kt @@ -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( diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FollowListState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FollowListState.kt index 30e4f432c..aec8b1024 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FollowListState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/FollowListState.kt @@ -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), ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/communities/CommunityScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/communities/CommunityScreen.kt index 35d3691a7..665c55c89 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/communities/CommunityScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/communities/CommunityScreen.kt @@ -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) }, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/AddInboxRelayForSearchCard.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/AddInboxRelayForSearchCard.kt index 14b4f8c4a..f2b92ebf2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/AddInboxRelayForSearchCard.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/search/AddInboxRelayForSearchCard.kt @@ -101,7 +101,7 @@ fun ObserveRelayListForSearch( inner: @Composable (relayListEvent: SearchRelayListEvent?) -> Unit, ) { LoadAddressableNote( - SearchRelayListEvent.createAddressTag(pubkey), + SearchRelayListEvent.createAddress(pubkey), accountViewModel, ) { relayList -> if (relayList != null) {