Add pubKey to UnsignedNostrEvent.kt to support multi account.
This commit is contained in:
1 parent
d116e85247
commit
3d045fbf8d
9 files changed
+51
-23
No files matched your search
@@ -2,7 +2,7 @@
|
|||||||
"formatVersion": 1,
|
"formatVersion": 1,
|
||||||
"database": {
|
"database": {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"identityHash": "80c7032502d17a1893ea8dc67debd365",
|
"identityHash": "3d48904218bb18d9efb6dba14449f27c",
|
||||||
"entities": [
|
"entities": [
|
||||||
{
|
{
|
||||||
"tableName": "BroadcastNostrEventReceipt",
|
"tableName": "BroadcastNostrEventReceipt",
|
||||||
@@ -836,7 +836,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"tableName": "UnsignedNostrEvent",
|
"tableName": "UnsignedNostrEvent",
|
||||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `signedNostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, FOREIGN KEY(`signedNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `pubKey` TEXT NOT NULL, `kind` INTEGER NOT NULL, `tags` TEXT NOT NULL, `content` TEXT NOT NULL, `signedNostrEventId` TEXT, `createdAt` INTEGER NOT NULL, `updatedAt` INTEGER NOT NULL, `savedAt` INTEGER NOT NULL, `deletedAt` INTEGER, `broadcastedAt` INTEGER, FOREIGN KEY(`signedNostrEventId`) REFERENCES `NostrEvent`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"fieldPath": "id",
|
"fieldPath": "id",
|
||||||
@@ -844,6 +844,12 @@
|
|||||||
"affinity": "INTEGER",
|
"affinity": "INTEGER",
|
||||||
"notNull": true
|
"notNull": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fieldPath": "pubKey",
|
||||||
|
"columnName": "pubKey",
|
||||||
|
"affinity": "TEXT",
|
||||||
|
"notNull": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fieldPath": "kind",
|
"fieldPath": "kind",
|
||||||
"columnName": "kind",
|
"columnName": "kind",
|
||||||
@@ -1095,7 +1101,7 @@
|
|||||||
],
|
],
|
||||||
"setupQueries": [
|
"setupQueries": [
|
||||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '80c7032502d17a1893ea8dc67debd365')"
|
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '3d48904218bb18d9efb6dba14449f27c')"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,7 @@ interface ProfileDao {
|
|||||||
@Upsert
|
@Upsert
|
||||||
suspend fun upsert(profile: Profile)
|
suspend fun upsert(profile: Profile)
|
||||||
|
|
||||||
@Query("SELECT * FROM NostrEvent WHERE kind = 0 AND pubKey = :publicKey")
|
@Query("SELECT * FROM UnsignedNostrEvent WHERE kind = 0 AND pubKey = :publicKey")
|
||||||
fun observeProfile(publicKey: String): Flow<LocalProfile?>
|
fun observeProfile(publicKey: String): Flow<LocalProfile?>
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,7 @@ data class UnsignedNostrEvent(
|
|||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
val id: Long = 0,
|
val id: Long = 0,
|
||||||
|
|
||||||
|
val pubKey: HexKey,
|
||||||
val kind: Kind,
|
val kind: Kind,
|
||||||
val tags: TagArray,
|
val tags: TagArray,
|
||||||
val content: String,
|
val content: String,
|
||||||
|
|||||||
+8
-1
@@ -2,11 +2,18 @@ package ac.aux.compose.database.model.intermdiate
|
|||||||
|
|
||||||
import ac.aux.compose.database.model.NostrEvent
|
import ac.aux.compose.database.model.NostrEvent
|
||||||
import ac.aux.compose.database.model.Profile
|
import ac.aux.compose.database.model.Profile
|
||||||
|
import ac.aux.compose.database.model.UnsignedNostrEvent
|
||||||
import androidx.room.Embedded
|
import androidx.room.Embedded
|
||||||
import androidx.room.Relation
|
import androidx.room.Relation
|
||||||
|
|
||||||
data class LocalProfile(
|
data class LocalProfile(
|
||||||
@Embedded val nostrEvent: NostrEvent,
|
@Embedded val unsignedNostrEvent: UnsignedNostrEvent,
|
||||||
|
|
||||||
|
@Relation(
|
||||||
|
parentColumn = "signedNostrEventId",
|
||||||
|
entityColumn = "id"
|
||||||
|
)
|
||||||
|
val nostrEvent: NostrEvent?,
|
||||||
|
|
||||||
@Relation(
|
@Relation(
|
||||||
parentColumn = "pubKey",
|
parentColumn = "pubKey",
|
||||||
|
|||||||
+2
@@ -20,6 +20,7 @@ class DatabaseNostrRepository(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun createNewProfile(
|
override suspend fun createNewProfile(
|
||||||
|
publicKey: HexKey,
|
||||||
name: String,
|
name: String,
|
||||||
biography: String,
|
biography: String,
|
||||||
onError: () -> Unit,
|
onError: () -> Unit,
|
||||||
@@ -34,6 +35,7 @@ class DatabaseNostrRepository(
|
|||||||
|
|
||||||
val unsignedNostrEvent = saveUnsignedNostrEvent(
|
val unsignedNostrEvent = saveUnsignedNostrEvent(
|
||||||
UnsignedNostrEvent(
|
UnsignedNostrEvent(
|
||||||
|
pubKey = publicKey,
|
||||||
kind = profileEventTemplate.kind,
|
kind = profileEventTemplate.kind,
|
||||||
createdAt = Instant.fromEpochMilliseconds(profileEventTemplate.createdAt),
|
createdAt = Instant.fromEpochMilliseconds(profileEventTemplate.createdAt),
|
||||||
tags = profileEventTemplate.tags,
|
tags = profileEventTemplate.tags,
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package ac.aux.compose.managers
|
||||||
|
|
||||||
|
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
object SeedManager {
|
||||||
|
|
||||||
|
private val tempDevelopmentKeyPair = KeyPair(
|
||||||
|
privKey = Random(21_012_256L).nextBytes(32)
|
||||||
|
)
|
||||||
|
|
||||||
|
fun activePublicKey(): ByteArray {
|
||||||
|
// TODO: Actually set and get a pair...
|
||||||
|
return tempDevelopmentKeyPair.pubKey
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
package ac.aux.compose.repository
|
package ac.aux.compose.repository
|
||||||
|
|
||||||
import ac.aux.compose.database.dao.ProfileDao
|
|
||||||
import ac.aux.compose.database.model.NostrEvent
|
import ac.aux.compose.database.model.NostrEvent
|
||||||
import ac.aux.compose.database.model.Profile
|
import ac.aux.compose.database.model.Profile
|
||||||
import ac.aux.compose.database.model.UnsignedNostrEvent
|
import ac.aux.compose.database.model.UnsignedNostrEvent
|
||||||
import ac.aux.compose.database.model.intermdiate.LocalProfile
|
import ac.aux.compose.database.model.intermdiate.LocalProfile
|
||||||
import ac.aux.compose.ui.view.state.CreateProfileUIState
|
|
||||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@@ -13,6 +11,7 @@ interface NostrRepository {
|
|||||||
suspend fun observeProfile(publicKey: HexKey): Flow<LocalProfile?>
|
suspend fun observeProfile(publicKey: HexKey): Flow<LocalProfile?>
|
||||||
|
|
||||||
suspend fun createNewProfile(
|
suspend fun createNewProfile(
|
||||||
|
publicKey: HexKey,
|
||||||
name: String,
|
name: String,
|
||||||
biography: String,
|
biography: String,
|
||||||
onError: () -> Unit,
|
onError: () -> Unit,
|
||||||
@@ -32,6 +31,7 @@ interface NostrRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun createNewProfile(
|
override suspend fun createNewProfile(
|
||||||
|
publicKey: HexKey,
|
||||||
name: String,
|
name: String,
|
||||||
biography: String,
|
biography: String,
|
||||||
onError: () -> Unit,
|
onError: () -> Unit,
|
||||||
|
|||||||
+8
-12
@@ -1,8 +1,6 @@
|
|||||||
package ac.aux.compose.ui.view.model
|
package ac.aux.compose.ui.view.model
|
||||||
|
|
||||||
import ac.aux.compose.database.model.NostrEvent
|
import ac.aux.compose.managers.SeedManager
|
||||||
import ac.aux.compose.database.model.Profile
|
|
||||||
import ac.aux.compose.database.model.UnsignedNostrEvent
|
|
||||||
import ac.aux.compose.repository.NostrRepository
|
import ac.aux.compose.repository.NostrRepository
|
||||||
import ac.aux.compose.ui.view.state.CreateProfileUIState
|
import ac.aux.compose.ui.view.state.CreateProfileUIState
|
||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
@@ -14,12 +12,10 @@ import androidx.lifecycle.viewmodel.viewModelFactory
|
|||||||
import ac.aux.compose.ui.view.state.form.CreateProfileFormState
|
import ac.aux.compose.ui.view.state.form.CreateProfileFormState
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import co.touchlab.kermit.Logger
|
import co.touchlab.kermit.Logger
|
||||||
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
|
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.IO
|
import kotlinx.coroutines.IO
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlin.time.Instant
|
|
||||||
|
|
||||||
class CreateProfileViewModel(
|
class CreateProfileViewModel(
|
||||||
val initialCreateProfileUIState: CreateProfileUIState,
|
val initialCreateProfileUIState: CreateProfileUIState,
|
||||||
@@ -75,6 +71,7 @@ class CreateProfileViewModel(
|
|||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
|
||||||
nostrRepository.createNewProfile(
|
nostrRepository.createNewProfile(
|
||||||
|
SeedManager.activePublicKey().toHexKey(),
|
||||||
name = createProfileFormState.nameField.text.value,
|
name = createProfileFormState.nameField.text.value,
|
||||||
biography = createProfileFormState.biographyField.text.value,
|
biography = createProfileFormState.biographyField.text.value,
|
||||||
onError = {
|
onError = {
|
||||||
@@ -91,13 +88,12 @@ class CreateProfileViewModel(
|
|||||||
createProfileUIState.value = CreateProfileUIState.UnbroadcastedProfile(
|
createProfileUIState.value = CreateProfileUIState.UnbroadcastedProfile(
|
||||||
nostrEvent = unbroadcastedNostrEvent,
|
nostrEvent = unbroadcastedNostrEvent,
|
||||||
)
|
)
|
||||||
},
|
|
||||||
onProfileReady = { profile ->
|
|
||||||
createProfileUIState.value = CreateProfileUIState.ProfileReady(
|
|
||||||
profile = profile
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
)
|
) { profile ->
|
||||||
|
createProfileUIState.value = CreateProfileUIState.ProfileReady(
|
||||||
|
profile = profile
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -1,5 +1,6 @@
|
|||||||
package ac.aux.compose.ui.view.model
|
package ac.aux.compose.ui.view.model
|
||||||
|
|
||||||
|
import ac.aux.compose.managers.SeedManager
|
||||||
import ac.aux.compose.repository.NostrRepository
|
import ac.aux.compose.repository.NostrRepository
|
||||||
import ac.aux.compose.ui.view.state.NavigationUIState
|
import ac.aux.compose.ui.view.state.NavigationUIState
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
@@ -41,9 +42,6 @@ class NavigationViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val tempDevelopmentKeyPair = KeyPair(
|
|
||||||
privKey = Random(21_000_000L).nextBytes(32)
|
|
||||||
)
|
|
||||||
private val _navigationUIState = MutableStateFlow(
|
private val _navigationUIState = MutableStateFlow(
|
||||||
initialNavigationUIState
|
initialNavigationUIState
|
||||||
)
|
)
|
||||||
@@ -63,7 +61,9 @@ class NavigationViewModel(
|
|||||||
_navigationUIState.getAndUpdate {
|
_navigationUIState.getAndUpdate {
|
||||||
NavigationUIState.Landing
|
NavigationUIState.Landing
|
||||||
}
|
}
|
||||||
nostrRepository.observeProfile(tempDevelopmentKeyPair.pubKey.toHexKey()).map { localProfile ->
|
nostrRepository.observeProfile(
|
||||||
|
publicKey = SeedManager.activePublicKey().toHexKey()
|
||||||
|
).map { localProfile ->
|
||||||
_navigationUIState.getAndUpdate {
|
_navigationUIState.getAndUpdate {
|
||||||
if (localProfile == null) {
|
if (localProfile == null) {
|
||||||
NavigationUIState.Landing
|
NavigationUIState.Landing
|
||||||
|
|||||||
Reference in new issue
Block a user