chore: remove force unwraps #30
@@ -59,6 +59,7 @@ import coop.composeapp.generated.resources.ic_arrow_back
|
|||||||
import coop.composeapp.generated.resources.ic_cancel
|
import coop.composeapp.generated.resources.ic_cancel
|
||||||
import coop.composeapp.generated.resources.ic_check_circle
|
import coop.composeapp.generated.resources.ic_check_circle
|
||||||
import coop.composeapp.generated.resources.ic_send
|
import coop.composeapp.generated.resources.ic_send
|
||||||
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.jetbrains.compose.resources.painterResource
|
import org.jetbrains.compose.resources.painterResource
|
||||||
import rust.nostr.sdk.PublicKey
|
import rust.nostr.sdk.PublicKey
|
||||||
@@ -103,8 +104,13 @@ fun ChatScreen(id: Long, screening: Boolean = false) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val displayName by remember(room) { room!!.nameFlow(viewModel) }.collectAsStateWithLifecycle("Loading...")
|
val displayName by remember(room) {
|
||||||
val picture by remember(room) { room!!.pictureFlow(viewModel) }.collectAsStateWithLifecycle(null)
|
room?.nameFlow(viewModel) ?: flowOf("Loading...")
|
||||||
|
}.collectAsStateWithLifecycle("Loading...")
|
||||||
|
|
||||||
|
val picture by remember(room) {
|
||||||
|
room?.pictureFlow(viewModel) ?: flowOf(null)
|
||||||
|
}.collectAsStateWithLifecycle(null)
|
||||||
|
|
||||||
var text by remember { mutableStateOf("") }
|
var text by remember { mutableStateOf("") }
|
||||||
var loading by remember { mutableStateOf(true) }
|
var loading by remember { mutableStateOf(true) }
|
||||||
@@ -161,7 +167,7 @@ fun ChatScreen(id: Long, screening: Boolean = false) {
|
|||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier.clickable {
|
modifier = Modifier.clickable {
|
||||||
room!!.members.firstOrNull()?.let { pubkey ->
|
room?.members?.firstOrNull()?.let { pubkey ->
|
||||||
navigator.navigate(Screen.Profile(pubkey.toBech32()))
|
navigator.navigate(Screen.Profile(pubkey.toBech32()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -741,7 +741,7 @@ fun ChatRoom(room: Room, onClick: () -> Unit) {
|
|||||||
supportingContent = {
|
supportingContent = {
|
||||||
if (!room.lastMessage.isNullOrBlank()) {
|
if (!room.lastMessage.isNullOrBlank()) {
|
||||||
Text(
|
Text(
|
||||||
text = room.lastMessage!!,
|
text = room.lastMessage ?: "",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
|
|||||||
@@ -670,6 +670,8 @@ class Nostr {
|
|||||||
|
|
||||||
suspend fun setMsgRelays(urls: List<RelayUrl>) {
|
suspend fun setMsgRelays(urls: List<RelayUrl>) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
val event = EventBuilder.nip17RelayList(urls).finalizeAsync(signer)
|
val event = EventBuilder.nip17RelayList(urls).finalizeAsync(signer)
|
||||||
|
|
||||||
client?.sendEvent(
|
client?.sendEvent(
|
||||||
@@ -678,8 +680,12 @@ class Nostr {
|
|||||||
ackPolicy = AckPolicy.none(),
|
ackPolicy = AckPolicy.none(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val currentUser =
|
||||||
|
signer.getPublicKeyAsync() ?: throw IllegalStateException("User not signed in")
|
||||||
|
|
||||||
val kind = Kind.fromStd(KindStandard.INBOX_RELAYS)
|
val kind = Kind.fromStd(KindStandard.INBOX_RELAYS)
|
||||||
val filter = Filter().kind(kind).author(signer.currentUser!!).limit(1u)
|
val filter = Filter().kind(kind).author(currentUser).limit(1u)
|
||||||
|
|
||||||
val target = ReqTarget.auto(listOf(filter))
|
val target = ReqTarget.auto(listOf(filter))
|
||||||
val opts = SubscribeAutoCloseOptions().exitPolicy(ReqExitPolicy.ExitOnEose)
|
val opts = SubscribeAutoCloseOptions().exitPolicy(ReqExitPolicy.ExitOnEose)
|
||||||
|
|
||||||
@@ -833,9 +839,8 @@ class Nostr {
|
|||||||
)
|
)
|
||||||
|
|
||||||
stream?.next()?.let { res ->
|
stream?.next()?.let { res ->
|
||||||
if (res.event != null) {
|
val event = res.event ?: return@let
|
||||||
connectMsgRelays(res.event!!)
|
connectMsgRelays(event)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -919,7 +924,10 @@ class Nostr {
|
|||||||
if (output != null) {
|
if (output != null) {
|
||||||
// Keep track of sent events
|
// Keep track of sent events
|
||||||
sentEvents[output.id] = emptyList()
|
sentEvents[output.id] = emptyList()
|
||||||
if (rumor.id() != null) rumorMap[rumor.id()!!] = output.id
|
|
||||||
|
// Keep track of rumor IDs
|
||||||
|
val id = rumor.id() ?: throw IllegalStateException("Rumor ID is null")
|
||||||
|
rumorMap[id] = output.id
|
||||||
|
|
||||||
// Collect failed outputs
|
// Collect failed outputs
|
||||||
output.failed.forEach { (relayUrl, reason) ->
|
output.failed.forEach { (relayUrl, reason) ->
|
||||||
@@ -979,9 +987,8 @@ class Nostr {
|
|||||||
|
|
||||||
// Keep searching until the stream is closed or timeout
|
// Keep searching until the stream is closed or timeout
|
||||||
stream?.next()?.let { event ->
|
stream?.next()?.let { event ->
|
||||||
if (event.event != null) {
|
val event = event.event ?: return@let
|
||||||
results.add(event.event!!.author())
|
results.add(event.author())
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|||||||
@@ -436,8 +436,9 @@ class NostrViewModel(
|
|||||||
try {
|
try {
|
||||||
val avatarUrl = picture?.let { blossomUpload(it, contentType ?: "image/jpeg") }
|
val avatarUrl = picture?.let { blossomUpload(it, contentType ?: "image/jpeg") }
|
||||||
val newMetadata = nostr.updateProfile(name, bio, avatarUrl)
|
val newMetadata = nostr.updateProfile(name, bio, avatarUrl)
|
||||||
|
val currentUser = nostr.signer.getPublicKeyAsync() ?: throw Exception("User not found")
|
||||||
// Update the metadata state after successfully published
|
// Update the metadata state after successfully published
|
||||||
updateMetadata(nostr.signer.currentUser!!, newMetadata)
|
updateMetadata(currentUser, newMetadata)
|
||||||
// Update local state
|
// Update local state
|
||||||
_isBusy.value = false
|
_isBusy.value = false
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -581,7 +582,8 @@ class NostrViewModel(
|
|||||||
|
|
||||||
suspend fun currentUserRelayList(): Map<RelayUrl, RelayMetadata?> {
|
suspend fun currentUserRelayList(): Map<RelayUrl, RelayMetadata?> {
|
||||||
try {
|
try {
|
||||||
return nostr.getRelayList(nostr.signer.currentUser!!)
|
val currentUser = nostr.signer.getPublicKeyAsync() ?: throw Exception("User not found")
|
||||||
|
return nostr.getRelayList(currentUser)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showError("Error: ${e.message}")
|
showError("Error: ${e.message}")
|
||||||
return emptyMap()
|
return emptyMap()
|
||||||
@@ -626,7 +628,8 @@ class NostrViewModel(
|
|||||||
|
|
||||||
suspend fun currentUserMsgRelayList(): List<RelayUrl> {
|
suspend fun currentUserMsgRelayList(): List<RelayUrl> {
|
||||||
try {
|
try {
|
||||||
return nostr.getMsgRelays(nostr.signer.currentUser!!)
|
val currentUser = nostr.signer.getPublicKeyAsync() ?: throw Exception("User not found")
|
||||||
|
return nostr.getMsgRelays(currentUser)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showError("Error: ${e.message}")
|
showError("Error: ${e.message}")
|
||||||
return emptyList()
|
return emptyList()
|
||||||
@@ -710,7 +713,7 @@ class NostrViewModel(
|
|||||||
if (nostr.signer.currentUser == null) throw IllegalStateException("User not signed in")
|
if (nostr.signer.currentUser == null) throw IllegalStateException("User not signed in")
|
||||||
if (to.isEmpty()) throw IllegalArgumentException("At least one recipient is required")
|
if (to.isEmpty()) throw IllegalArgumentException("At least one recipient is required")
|
||||||
|
|
||||||
val currentUser = nostr.signer.currentUser!!
|
val currentUser = nostr.signer.currentUser ?: throw Exception("User not found")
|
||||||
|
|
||||||
// Construct the rumor event
|
// Construct the rumor event
|
||||||
val rumor = EventBuilder(Kind.fromStd(KindStandard.PRIVATE_DIRECT_MESSAGE), "")
|
val rumor = EventBuilder(Kind.fromStd(KindStandard.PRIVATE_DIRECT_MESSAGE), "")
|
||||||
|
|||||||
Reference in New Issue
Block a user