Merge pull request #862 from believethehype/NIP90-ContentDiscovery
NIP90: cleanup, potential fix endless loop
This commit is contained in:
+21
-30
@@ -31,7 +31,9 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.livedata.observeAsState
|
import androidx.compose.runtime.livedata.observeAsState
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
|
import com.vitorpamplona.amethyst.R
|
||||||
import com.vitorpamplona.amethyst.model.LocalCache
|
import com.vitorpamplona.amethyst.model.LocalCache
|
||||||
import com.vitorpamplona.amethyst.service.relays.Client
|
import com.vitorpamplona.amethyst.service.relays.Client
|
||||||
import com.vitorpamplona.amethyst.ui.screen.FeedEmptywithStatus
|
import com.vitorpamplona.amethyst.ui.screen.FeedEmptywithStatus
|
||||||
@@ -40,7 +42,6 @@ import com.vitorpamplona.amethyst.ui.screen.NostrNIP90StatusFeedViewModel
|
|||||||
import com.vitorpamplona.amethyst.ui.screen.RefresheableBox
|
import com.vitorpamplona.amethyst.ui.screen.RefresheableBox
|
||||||
import com.vitorpamplona.amethyst.ui.screen.RenderFeedState
|
import com.vitorpamplona.amethyst.ui.screen.RenderFeedState
|
||||||
import com.vitorpamplona.amethyst.ui.screen.SaveableFeedState
|
import com.vitorpamplona.amethyst.ui.screen.SaveableFeedState
|
||||||
import com.vitorpamplona.quartz.events.AppDefinitionEvent
|
|
||||||
import com.vitorpamplona.quartz.events.NIP90ContentDiscoveryRequestEvent
|
import com.vitorpamplona.quartz.events.NIP90ContentDiscoveryRequestEvent
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -90,7 +91,7 @@ fun NIP90ContentDiscoveryScreen(
|
|||||||
@Composable
|
@Composable
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
fun RenderNostrNIP90ContentDiscoveryScreen(
|
fun RenderNostrNIP90ContentDiscoveryScreen(
|
||||||
DVMID: String?,
|
dvmID: String?,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
nav: (String) -> Unit,
|
nav: (String) -> Unit,
|
||||||
resultFeedViewModel: NostrNIP90ContentDiscoveryFeedViewModel,
|
resultFeedViewModel: NostrNIP90ContentDiscoveryFeedViewModel,
|
||||||
@@ -99,54 +100,43 @@ fun RenderNostrNIP90ContentDiscoveryScreen(
|
|||||||
Column(Modifier.fillMaxHeight()) {
|
Column(Modifier.fillMaxHeight()) {
|
||||||
val pagerState = rememberPagerState { 2 }
|
val pagerState = rememberPagerState { 2 }
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
// TODO 1 Render a nice header with image and DVM name from the id
|
|
||||||
// TODO How do we get the event information here?
|
|
||||||
|
|
||||||
var dvminfo = "DVM " + DVMID
|
// TODO (Optional) this now shows the first status update but there might be a better way
|
||||||
if (DVMID != null) {
|
var dvmState = stringResource(R.string.dvm_waiting_status)
|
||||||
val thread =
|
var dvmNoState = stringResource(R.string.dvm_no_status)
|
||||||
Thread {
|
|
||||||
try {
|
|
||||||
var note = LocalCache.checkGetOrCreateNote(DVMID)
|
|
||||||
if (note != null) {
|
|
||||||
dvminfo = ((note.event as AppDefinitionEvent).appMetaData()?.name ?: "DVM from note")
|
|
||||||
} else {
|
|
||||||
dvminfo = "DVM from not found"
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
thread.start()
|
|
||||||
thread.join()
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO this shows the status but there might be a better way
|
|
||||||
var dvmStatus = "DVM is processing..."
|
|
||||||
val thread =
|
val thread =
|
||||||
Thread {
|
Thread {
|
||||||
println(dvmStatus)
|
var count = 0
|
||||||
while (resultFeedViewModel.localFilter.feed().isEmpty()) {
|
while (resultFeedViewModel.localFilter.feed().isEmpty()) {
|
||||||
try {
|
try {
|
||||||
if (statusFeedViewModel.localFilter.feed().isNotEmpty()) {
|
if (statusFeedViewModel.localFilter.feed().isNotEmpty()) {
|
||||||
statusFeedViewModel.localFilter.feed()[0].event?.let { dvmStatus = it.content() }
|
statusFeedViewModel.localFilter.feed()[0].event?.let { dvmState = it.content() }
|
||||||
println(dvmStatus)
|
println(dvmState)
|
||||||
break
|
break
|
||||||
|
} else if (count > 1000) {
|
||||||
|
dvmState = dvmNoState
|
||||||
|
// Might not be the best way, but we want to avoid hanging in the loop forever
|
||||||
} else {
|
} else {
|
||||||
|
count++
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thread.start()
|
thread.start()
|
||||||
thread.join()
|
thread.join()
|
||||||
|
|
||||||
|
// TODO (Optional) Maybe render a nice header with image and DVM name from the dvmID
|
||||||
|
// TODO (Optional) How do we get the event information here?, LocalCache.checkGetOrCreateNote() returns note but event is empty
|
||||||
|
// TODO (Optional) otherwise we have the NIP89 info in (note.event as AppDefinitionEvent).appMetaData()
|
||||||
|
// Text(text = dvminfo)
|
||||||
|
|
||||||
HorizontalPager(state = pagerState) {
|
HorizontalPager(state = pagerState) {
|
||||||
RefresheableBox(resultFeedViewModel, false) {
|
RefresheableBox(resultFeedViewModel, false) {
|
||||||
SaveableFeedState(resultFeedViewModel, null) { listState ->
|
SaveableFeedState(resultFeedViewModel, null) { listState ->
|
||||||
|
// TODO (Optional) Instead of a like reaction, do a Kind 31989 NIP89 App recommendation
|
||||||
RenderFeedState(
|
RenderFeedState(
|
||||||
resultFeedViewModel,
|
resultFeedViewModel,
|
||||||
accountViewModel,
|
accountViewModel,
|
||||||
@@ -154,7 +144,8 @@ fun RenderNostrNIP90ContentDiscoveryScreen(
|
|||||||
nav,
|
nav,
|
||||||
null,
|
null,
|
||||||
onEmpty = {
|
onEmpty = {
|
||||||
FeedEmptywithStatus(status = dvmStatus) {
|
// TODO (Optional) Maybe also show some dvm image/text while waiting for the notes in this custom component
|
||||||
|
FeedEmptywithStatus(status = dvmState) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -846,4 +846,7 @@
|
|||||||
<string name="draft_note">Draft Note</string>
|
<string name="draft_note">Draft Note</string>
|
||||||
|
|
||||||
<string name="load_from_text">From Msg</string>
|
<string name="load_from_text">From Msg</string>
|
||||||
|
|
||||||
|
<string name="dvm_waiting_status">Waiting for DVM to reply</string>
|
||||||
|
<string name="dvm_no_status">DVM seems not to reply</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user