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.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.produceState
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
@@ -492,8 +493,14 @@ private fun RenderReply(
|
||||
onWantsToReply: (Note) -> Unit,
|
||||
) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
val replyTo by remember { derivedStateOf { note.replyTo?.lastOrNull() } }
|
||||
replyTo?.let { note ->
|
||||
val replyTo =
|
||||
produceState(initialValue = note.replyTo?.lastOrNull()) {
|
||||
accountViewModel.unwrapIfNeeded(value) {
|
||||
value = it
|
||||
}
|
||||
}
|
||||
|
||||
replyTo.value?.let { note ->
|
||||
ChatroomMessageCompose(
|
||||
note,
|
||||
null,
|
||||
|
||||
@@ -73,6 +73,7 @@ import com.vitorpamplona.quartz.encoders.Nip19
|
||||
import com.vitorpamplona.quartz.events.ChatroomKey
|
||||
import com.vitorpamplona.quartz.events.ChatroomKeyable
|
||||
import com.vitorpamplona.quartz.events.Event
|
||||
import com.vitorpamplona.quartz.events.EventInterface
|
||||
import com.vitorpamplona.quartz.events.GiftWrapEvent
|
||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||
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>) {
|
||||
|
||||
Reference in New Issue
Block a user