bug fix on negentropy sync
This commit is contained in:
@@ -8,6 +8,7 @@ import androidx.room3.RawQuery
|
||||
import androidx.room3.RoomRawQuery
|
||||
import androidx.room3.Transaction
|
||||
import androidx.room3.Upsert
|
||||
import at.torch.compose.database.model.MarmotGroupEvent
|
||||
import at.torch.compose.database.model.NostrEvent
|
||||
import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
@@ -105,6 +106,14 @@ interface NostrEventDao {
|
||||
limit: Int
|
||||
): List<NostrEvent>
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM MarmotGroupEvent WHERE nostrEventId IS NOT NULL AND chatRoomId in (:chatRoomIds) AND createdAt > :since ORDER BY createdAt ASC LIMIT :limit")
|
||||
fun getMarmotGroupEvents(
|
||||
chatRoomIds: Array<HexKey>,
|
||||
since: Instant,
|
||||
limit: Int
|
||||
): List<MarmotGroupEvent>
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM NostrEvent WHERE kind in (:kinds) AND pubKey in (:authors) AND createdAt > :since ORDER BY createdAt ASC LIMIT :limit")
|
||||
fun getAuthoredNostrEvents(
|
||||
|
||||
@@ -38,6 +38,8 @@ data class MarmotGroupEvent(
|
||||
|
||||
val chatRoomId: String,
|
||||
|
||||
// val signature: String, // TODO: Add signature...
|
||||
|
||||
val encryptedContent: String,
|
||||
val expiresAt: Instant? = null,
|
||||
|
||||
@@ -69,7 +71,7 @@ data class MarmotGroupEvent(
|
||||
chatRoomId = chatRoomId,
|
||||
userPublicKey = userPublicKey,
|
||||
publicKey = groupEvent.pubKey,
|
||||
expiresAt = groupEvent.expiration()?.let { Instant.fromEpochSeconds(it) }
|
||||
expiresAt = groupEvent.expiration()?.let { Instant.fromEpochSeconds(it) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import at.torch.compose.database.model.types.SynchronizationFilter
|
||||
import at.torch.compose.nostr.Relays
|
||||
import co.touchlab.kermit.Logger
|
||||
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageRelayListEvent
|
||||
import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEvent
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Kind
|
||||
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
|
||||
@@ -687,14 +688,25 @@ class DatabaseNostrRepository(
|
||||
val chatRoomIds = synchronizationFilter.tags["h"]?.toTypedArray() ?: emptyArray()
|
||||
logger.d("ChatRoomIds: ${chatRoomIds.contentToString()}")
|
||||
logger.d("getMLSGroupEvents($applyLimits): $synchronizationFilter")
|
||||
database.nostrEventDao().getMLSGroupEvents(
|
||||
database.nostrEventDao().getMarmotGroupEvents(
|
||||
chatRoomIds = chatRoomIds,
|
||||
since = synchronizationFilter.since ?: GENESIS_AT,
|
||||
limit = if (applyLimits) {
|
||||
synchronizationFilter.limit ?: 50
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
)
|
||||
).map { marmotGroupEvent ->
|
||||
NostrEvent(
|
||||
id = marmotGroupEvent.nostrEventId,
|
||||
content = marmotGroupEvent.encryptedContent,
|
||||
kind = GroupEvent.KIND,
|
||||
tags = emptyArray(),
|
||||
createdAt = marmotGroupEvent.createdAt,
|
||||
sig = "", // TODO: Use marmotGroupEvent.signature...
|
||||
pubKey = marmotGroupEvent.publicKey
|
||||
)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
logger.d("getNostrEvents($applyLimits): $synchronizationFilter")
|
||||
|
||||
@@ -209,8 +209,8 @@ class SynchronizationViewModel(
|
||||
val storage = StorageVector().apply {
|
||||
events.forEach { event ->
|
||||
insert(
|
||||
event.createdAt.toEpochMilliseconds(),
|
||||
event.id
|
||||
timestamp = event.createdAt.toEpochMilliseconds(),
|
||||
idHex = event.id
|
||||
)
|
||||
}
|
||||
|
||||
@@ -338,10 +338,10 @@ class SynchronizationViewModel(
|
||||
)
|
||||
}
|
||||
logger.d("broadcastNostrEventRequests: $broadcastNostrEventRequests")
|
||||
// TODO: Schedule broadcastNostrEventRequests
|
||||
// nostrRepository.scheduleBroadcastNostrEventRequests(
|
||||
// broadcastNostrEventRequests
|
||||
// )
|
||||
// Schedule broadcastNostrEventRequests
|
||||
nostrRepository.scheduleBroadcastNostrEventRequests(
|
||||
broadcastNostrEventRequests
|
||||
)
|
||||
|
||||
relaysSocketManager.closeNegentropySync(
|
||||
negCloseCmd,
|
||||
|
||||
Reference in New Issue
Block a user