Bug fix on npub login (which should hopefully cover nsec login as it's the same outside of first saving the private key)
This commit is contained in:
@@ -84,6 +84,7 @@ abstract class NostrDao(
|
||||
) {
|
||||
logger.i("Store Nostr Event: $nostrEvent")
|
||||
if (nostrEvent.unsignedNostrEventId == null) {
|
||||
logger.i("Store Nostr Event: $nostrEvent")
|
||||
// Find or create profile with the pubKey... if not found submit a sync request...
|
||||
val profile = database.profileDao().getProfileByPublicKey(nostrEvent.pubKey)
|
||||
|
||||
@@ -105,6 +106,7 @@ abstract class NostrDao(
|
||||
database.profileDao().upsert(placeHolderProfile)
|
||||
|
||||
synchronizationRelayURLs.forEach { synchronizationRelayURL ->
|
||||
logger.i("Sync Profile with PubKey: ${nostrEvent.pubKey}")
|
||||
database.synchronizeNostrEventRequestDao().upsert(
|
||||
SynchronizeNostrEventRequest(
|
||||
authorPublicKeys = arrayOf(nostrEvent.pubKey),
|
||||
|
||||
@@ -2,6 +2,7 @@ package ac.aux.compose.database.dao
|
||||
|
||||
import ac.aux.compose.database.model.SynchronizeNostrEventRequest
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.Query
|
||||
import androidx.room.Upsert
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -14,6 +15,6 @@ interface SynchronizeNostrEventRequestDao {
|
||||
@Upsert
|
||||
fun upsert(synchronizeNostrEventRequest: SynchronizeNostrEventRequest)
|
||||
|
||||
@Upsert
|
||||
@Insert
|
||||
fun insert(synchronizeNostrEventRequests: List<SynchronizeNostrEventRequest>)
|
||||
}
|
||||
@@ -168,7 +168,6 @@ class DatabaseNostrRepository(
|
||||
updatedAt = Clock.System.now()
|
||||
)
|
||||
)
|
||||
logger.i("Processed: $synchronizeNostrEventRequest")
|
||||
}
|
||||
|
||||
override suspend fun saveBroadcastReceipt(broadcastNostrEventReceipt: BroadcastNostrEventReceipt) {
|
||||
|
||||
@@ -137,10 +137,13 @@ class NavigationViewModel(
|
||||
private fun observePendingSyncNostrEventRequests() {
|
||||
logger.i { "observePendingSyncNostrEventRequests" }
|
||||
|
||||
val syncEventCache = mutableMapOf<String, NostrEvent>()
|
||||
|
||||
scope.launch(Dispatchers.IO) {
|
||||
nostrRepository.observePendingSynchronizeNostrEventRequests().collect { synchronizeNostrEventRequestOrNull ->
|
||||
synchronizeNostrEventRequestOrNull?.let { synchronizeNostrEventRequest ->
|
||||
try {
|
||||
logger.i("synchronizeNostrEventRequest: $synchronizeNostrEventRequest")
|
||||
val reqCommand = ReqCmd(
|
||||
subId = synchronizeNostrEventRequest.id,
|
||||
filters = listOf(
|
||||
@@ -189,22 +192,27 @@ class NavigationViewModel(
|
||||
jsonText
|
||||
)
|
||||
|
||||
val nostrEvent = NostrEvent(
|
||||
id = event.id,
|
||||
pubKey = event.pubKey,
|
||||
kind = event.kind,
|
||||
content = event.content,
|
||||
tags = event.tags,
|
||||
createdAt = Instant.fromEpochMilliseconds(event.createdAt),
|
||||
unsignedNostrEventId = synchronizeNostrEventRequest.unsignedNostrEventId,
|
||||
sig = event.sig
|
||||
)
|
||||
// TODO: Do profile specific cache (to avoid wiping an updated profile)
|
||||
syncEventCache.getOrPut(event.id, {
|
||||
val nostrEvent = NostrEvent(
|
||||
id = event.id,
|
||||
pubKey = event.pubKey,
|
||||
kind = event.kind,
|
||||
content = event.content,
|
||||
tags = event.tags,
|
||||
createdAt = Instant.fromEpochMilliseconds(event.createdAt),
|
||||
unsignedNostrEventId = synchronizeNostrEventRequest.unsignedNostrEventId,
|
||||
sig = event.sig
|
||||
)
|
||||
|
||||
nostrRepository.saveNostrEvent(
|
||||
nostrEvent = nostrEvent,
|
||||
synchronizeNostrEventRequest,
|
||||
synchronizationRelayURLs = Relays.eventPublishRelaySet.map { normalizedRelayUrl -> normalizedRelayUrl.url }
|
||||
)
|
||||
nostrRepository.saveNostrEvent(
|
||||
nostrEvent = nostrEvent,
|
||||
synchronizeNostrEventRequest,
|
||||
synchronizationRelayURLs = Relays.eventPublishRelaySet.map { normalizedRelayUrl -> normalizedRelayUrl.url }
|
||||
)
|
||||
|
||||
nostrEvent
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
@@ -309,7 +317,7 @@ class NavigationViewModel(
|
||||
NavigationUIState.ProfileLoaded(
|
||||
publicKey = localProfile.unsignedNostrEvent.pubKey
|
||||
)
|
||||
} else if (localProfile.unsignedNostrEvent.signedAt != null && localProfile.profile!= null) {
|
||||
} else if (localProfile.unsignedNostrEvent.signedAt != null && localProfile.profile != null) {
|
||||
logger.i("We have successfully synced a profile: ${localProfile.profile}")
|
||||
NavigationUIState.ProfileLoaded(
|
||||
publicKey = localProfile.unsignedNostrEvent.pubKey
|
||||
@@ -334,7 +342,7 @@ class NavigationViewModel(
|
||||
NavigationUIState.UnqueuedProfileSynchronization(
|
||||
unsignedNostrEvent = localProfile.unsignedNostrEvent
|
||||
)
|
||||
} else if (localProfile.unsignedNostrEvent.signedAt != null) {
|
||||
} else if (localProfile.unsignedNostrEvent.signedAt != null && localProfile.synchronizeNostrEventRequests.isEmpty()) {
|
||||
logger.i("We should be syncing the profile: ${localProfile.unsignedNostrEvent}")
|
||||
NavigationUIState.UnsyncedProfile(
|
||||
unsignedNostrEvent = localProfile.unsignedNostrEvent
|
||||
|
||||
Reference in New Issue
Block a user