chore: init nostr
This commit is contained in:
@@ -29,6 +29,7 @@ kotlin {
|
|||||||
implementation(libs.compose.uiToolingPreview)
|
implementation(libs.compose.uiToolingPreview)
|
||||||
implementation(libs.androidx.lifecycle.viewmodelCompose)
|
implementation(libs.androidx.lifecycle.viewmodelCompose)
|
||||||
implementation(libs.androidx.lifecycle.runtimeCompose)
|
implementation(libs.androidx.lifecycle.runtimeCompose)
|
||||||
|
implementation("org.rust-nostr:nostr-sdk-kmp:0.44.3")
|
||||||
}
|
}
|
||||||
commonTest.dependencies {
|
commonTest.dependencies {
|
||||||
implementation(libs.kotlin.test)
|
implementation(libs.kotlin.test)
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
package su.reya.coop.coop
|
package su.reya.coop.coop
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.safeContentPadding
|
import androidx.compose.foundation.layout.safeContentPadding
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@@ -14,10 +11,6 @@ import androidx.compose.runtime.*
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import org.jetbrains.compose.resources.painterResource
|
|
||||||
|
|
||||||
import coop.composeapp.generated.resources.Res
|
|
||||||
import coop.composeapp.generated.resources.compose_multiplatform
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@Preview
|
@Preview
|
||||||
@@ -34,16 +27,6 @@ fun App() {
|
|||||||
Button(onClick = { showContent = !showContent }) {
|
Button(onClick = { showContent = !showContent }) {
|
||||||
Text("Click me!")
|
Text("Click me!")
|
||||||
}
|
}
|
||||||
AnimatedVisibility(showContent) {
|
|
||||||
val greeting = remember { Greeting().greet() }
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
) {
|
|
||||||
Image(painterResource(Res.drawable.compose_multiplatform), null)
|
|
||||||
Text("Compose: $greeting")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package su.reya.coop.coop
|
|
||||||
|
|
||||||
class Greeting {
|
|
||||||
private val platform = getPlatform()
|
|
||||||
|
|
||||||
fun greet(): String {
|
|
||||||
return "Hello, ${platform.name}!"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,12 +6,28 @@ import androidx.activity.compose.setContent
|
|||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
|
private val nostr = Nostr()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
val dbDir = File(filesDir, "nostr")
|
||||||
|
dbDir.mkdirs()
|
||||||
|
|
||||||
|
// Initialize nostr client
|
||||||
|
nostr.init(dbDir.absolutePath)
|
||||||
|
|
||||||
|
// Connect to bootstrap relays
|
||||||
|
lifecycleScope.launch {
|
||||||
|
nostr.connect()
|
||||||
|
}
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
App()
|
App()
|
||||||
}
|
}
|
||||||
|
|||||||
23
composeApp/src/androidMain/kotlin/su/reya/coop/coop/Nostr.kt
Normal file
23
composeApp/src/androidMain/kotlin/su/reya/coop/coop/Nostr.kt
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package su.reya.coop.coop
|
||||||
|
|
||||||
|
import rust.nostr.sdk.*
|
||||||
|
|
||||||
|
class Nostr {
|
||||||
|
var client: Client? = null
|
||||||
|
private set
|
||||||
|
|
||||||
|
fun init(dbPath: String) {
|
||||||
|
val lmdb = NostrDatabase.lmdb(dbPath)
|
||||||
|
val gossip = NostrGossip.inMemory()
|
||||||
|
val opts = ClientOptions().automaticAuthentication(false)
|
||||||
|
|
||||||
|
client = ClientBuilder().database(lmdb).gossip(gossip).opts(opts).build()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun connect() {
|
||||||
|
this.client?.addRelay(RelayUrl.parse("wss://relay.damus.io"))
|
||||||
|
this.client?.addRelay(RelayUrl.parse("wss://relay.primal.net"))
|
||||||
|
this.client?.addRelay(RelayUrl.parse("wss://user.kindpag.es"))
|
||||||
|
this.client?.connect()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user