Unwrapps the reply message if the GiftWrap was tagged and not the inner message id.
This commit is contained in:
@@ -46,6 +46,7 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.produceState
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@@ -492,8 +493,14 @@ private fun RenderReply(
|
|||||||
onWantsToReply: (Note) -> Unit,
|
onWantsToReply: (Note) -> Unit,
|
||||||
) {
|
) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
val replyTo by remember { derivedStateOf { note.replyTo?.lastOrNull() } }
|
val replyTo =
|
||||||
replyTo?.let { note ->
|
produceState(initialValue = note.replyTo?.lastOrNull()) {
|
||||||
|
accountViewModel.unwrapIfNeeded(value) {
|
||||||
|
value = it
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
replyTo.value?.let { note ->
|
||||||
ChatroomMessageCompose(
|
ChatroomMessageCompose(
|
||||||
note,
|
note,
|
||||||
null,
|
null,
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ import com.vitorpamplona.quartz.encoders.Nip19
|
|||||||
import com.vitorpamplona.quartz.events.ChatroomKey
|
import com.vitorpamplona.quartz.events.ChatroomKey
|
||||||
import com.vitorpamplona.quartz.events.ChatroomKeyable
|
import com.vitorpamplona.quartz.events.ChatroomKeyable
|
||||||
import com.vitorpamplona.quartz.events.Event
|
import com.vitorpamplona.quartz.events.Event
|
||||||
|
import com.vitorpamplona.quartz.events.EventInterface
|
||||||
import com.vitorpamplona.quartz.events.GiftWrapEvent
|
import com.vitorpamplona.quartz.events.GiftWrapEvent
|
||||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
import com.vitorpamplona.quartz.events.LnZapEvent
|
import com.vitorpamplona.quartz.events.LnZapEvent
|
||||||
@@ -1175,6 +1176,55 @@ class AccountViewModel(val account: Account, val settings: SettingsState) : View
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun unwrapIfNeeded(
|
||||||
|
event: EventInterface?,
|
||||||
|
onReady: (Note) -> Unit,
|
||||||
|
) {
|
||||||
|
when (event) {
|
||||||
|
is GiftWrapEvent -> {
|
||||||
|
event.cachedGift(account.signer) {
|
||||||
|
val existingNote = LocalCache.getNoteIfExists(it.id)
|
||||||
|
if (existingNote != null) {
|
||||||
|
unwrapIfNeeded(existingNote.event, onReady)
|
||||||
|
} else {
|
||||||
|
LocalCache.verifyAndConsume(it, null)
|
||||||
|
unwrapIfNeeded(it, onReady)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is SealedGossipEvent -> {
|
||||||
|
event.cachedGossip(account.signer) {
|
||||||
|
val existingNote = LocalCache.getNoteIfExists(it.id)
|
||||||
|
if (existingNote != null) {
|
||||||
|
unwrapIfNeeded(existingNote.event, onReady)
|
||||||
|
} else {
|
||||||
|
// this is not verifiable
|
||||||
|
LocalCache.justConsume(it, null)
|
||||||
|
unwrapIfNeeded(it, onReady)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
event?.id()?.let {
|
||||||
|
LocalCache.getNoteIfExists(it)?.let {
|
||||||
|
onReady(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unwrapIfNeeded(
|
||||||
|
note: Note?,
|
||||||
|
onReady: (Note) -> Unit,
|
||||||
|
) {
|
||||||
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
unwrapIfNeeded(note?.event) {
|
||||||
|
onReady(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class HasNotificationDot(bottomNavigationItems: ImmutableList<Route>) {
|
class HasNotificationDot(bottomNavigationItems: ImmutableList<Route>) {
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ class GiftWrapEvent(
|
|||||||
) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
|
) : Event(id, pubKey, createdAt, KIND, tags, content, sig) {
|
||||||
@Transient private var cachedInnerEvent: Map<HexKey, Event?> = mapOf()
|
@Transient private var cachedInnerEvent: Map<HexKey, Event?> = mapOf()
|
||||||
|
|
||||||
|
fun preCachedGift(signer: NostrSigner): Event? {
|
||||||
|
return cachedInnerEvent[signer.pubKey]
|
||||||
|
}
|
||||||
|
|
||||||
fun cachedGift(
|
fun cachedGift(
|
||||||
signer: NostrSigner,
|
signer: NostrSigner,
|
||||||
onReady: (Event) -> Unit,
|
onReady: (Event) -> Unit,
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ class SealedGossipEvent(
|
|||||||
) : WrappedEvent(id, pubKey, createdAt, KIND, tags, content, sig) {
|
) : WrappedEvent(id, pubKey, createdAt, KIND, tags, content, sig) {
|
||||||
@Transient private var cachedInnerEvent: Map<HexKey, Event?> = mapOf()
|
@Transient private var cachedInnerEvent: Map<HexKey, Event?> = mapOf()
|
||||||
|
|
||||||
|
fun preCachedGossip(signer: NostrSigner): Event? {
|
||||||
|
return cachedInnerEvent[signer.pubKey]
|
||||||
|
}
|
||||||
|
|
||||||
fun cachedGossip(
|
fun cachedGossip(
|
||||||
signer: NostrSigner,
|
signer: NostrSigner,
|
||||||
onReady: (Event) -> Unit,
|
onReady: (Event) -> Unit,
|
||||||
|
|||||||
Reference in New Issue
Block a user