mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-28 06:57:10 +02:00
Finishes the migration of adressable ids on the local cache.
This commit is contained in:
@@ -21,10 +21,12 @@
|
|||||||
package com.vitorpamplona.amethyst.ui.actions
|
package com.vitorpamplona.amethyst.ui.actions
|
||||||
|
|
||||||
import androidx.compose.runtime.Immutable
|
import androidx.compose.runtime.Immutable
|
||||||
|
import com.vitorpamplona.amethyst.model.AddressableNote
|
||||||
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.quartz.nip01Core.core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||||
import com.vitorpamplona.quartz.nip01Core.crypto.Nip01
|
import com.vitorpamplona.quartz.nip01Core.crypto.Nip01
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.tags.addressables.Address
|
||||||
import com.vitorpamplona.quartz.nip19Bech32.Nip19Parser
|
import com.vitorpamplona.quartz.nip19Bech32.Nip19Parser
|
||||||
import com.vitorpamplona.quartz.nip19Bech32.bech32.Bech32
|
import com.vitorpamplona.quartz.nip19Bech32.bech32.Bech32
|
||||||
import com.vitorpamplona.quartz.nip19Bech32.bech32.bechToBytes
|
import com.vitorpamplona.quartz.nip19Bech32.bech32.bechToBytes
|
||||||
@@ -77,7 +79,7 @@ class NewMessageTagger(
|
|||||||
is NEmbed -> addNoteToReplyTos(dao.getOrCreateNote(entity.event.id))
|
is NEmbed -> addNoteToReplyTos(dao.getOrCreateNote(entity.event.id))
|
||||||
|
|
||||||
is NAddress -> {
|
is NAddress -> {
|
||||||
val note = dao.checkGetOrCreateAddressableNote(entity.aTag())
|
val note = dao.getOrCreateAddressableNote(entity.address())
|
||||||
if (note != null) {
|
if (note != null) {
|
||||||
addNoteToReplyTos(note)
|
addNoteToReplyTos(note)
|
||||||
}
|
}
|
||||||
@@ -114,9 +116,9 @@ class NewMessageTagger(
|
|||||||
}
|
}
|
||||||
|
|
||||||
is NAddress -> {
|
is NAddress -> {
|
||||||
val note = dao.checkGetOrCreateAddressableNote(entity.aTag())
|
val note = dao.getOrCreateAddressableNote(entity.address())
|
||||||
if (note != null) {
|
if (note != null) {
|
||||||
getNostrAddress(note.idNote(), results.restOfWord)
|
getNostrAddress(note.toNAddr(), results.restOfWord)
|
||||||
} else {
|
} else {
|
||||||
word
|
word
|
||||||
}
|
}
|
||||||
@@ -234,5 +236,5 @@ interface Dao {
|
|||||||
|
|
||||||
suspend fun getOrCreateNote(hex: String): Note
|
suspend fun getOrCreateNote(hex: String): Note
|
||||||
|
|
||||||
suspend fun checkGetOrCreateAddressableNote(hex: String): Note?
|
suspend fun getOrCreateAddressableNote(address: Address): AddressableNote?
|
||||||
}
|
}
|
||||||
|
@@ -205,7 +205,7 @@ private fun DisplayAddress(
|
|||||||
|
|
||||||
if (noteBase == null) {
|
if (noteBase == null) {
|
||||||
LaunchedEffect(key1 = nip19) {
|
LaunchedEffect(key1 = nip19) {
|
||||||
accountViewModel.checkGetOrCreateAddressableNote(nip19.aTag()) { noteBase = it }
|
noteBase = accountViewModel.getOrCreateAddressableNote(nip19.address())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1056,16 +1056,7 @@ class AccountViewModel(
|
|||||||
|
|
||||||
fun getNoteIfExists(hex: HexKey): Note? = LocalCache.getNoteIfExists(hex)
|
fun getNoteIfExists(hex: HexKey): Note? = LocalCache.getNoteIfExists(hex)
|
||||||
|
|
||||||
override suspend fun checkGetOrCreateAddressableNote(key: HexKey): AddressableNote? = LocalCache.checkGetOrCreateAddressableNote(key)
|
override suspend fun getOrCreateAddressableNote(address: Address): AddressableNote = LocalCache.getOrCreateAddressableNote(address)
|
||||||
|
|
||||||
fun checkGetOrCreateAddressableNote(
|
|
||||||
key: HexKey,
|
|
||||||
onResult: (AddressableNote?) -> Unit,
|
|
||||||
) {
|
|
||||||
viewModelScope.launch(Dispatchers.IO) { onResult(checkGetOrCreateAddressableNote(key)) }
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun getOrCreateAddressableNote(key: Address): AddressableNote = LocalCache.getOrCreateAddressableNote(key)
|
|
||||||
|
|
||||||
fun getOrCreateAddressableNote(
|
fun getOrCreateAddressableNote(
|
||||||
key: Address,
|
key: Address,
|
||||||
|
Reference in New Issue
Block a user