Schedule negentropy sync
This commit is contained in:
@@ -468,12 +468,17 @@ class DatabaseNostrRepository(
|
||||
override suspend fun queueSynchronizeNostrEvent(
|
||||
synchronizeNostrEventRequests: List<SynchronizeNostrEventRequest>,
|
||||
) {
|
||||
// Save synchronizationResult
|
||||
database.synchronizeNostrEventRequestDao().insert(
|
||||
synchronizeNostrEventRequests
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun queueNegentropySynchronizeRequest(negentropySynchronizeRequests: List<NegentropySynchronizeRequest>) {
|
||||
database.negentropySynchronizeRequestDao().insert(
|
||||
negentropySynchronizeRequests
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun observeSynchronizeNostrEventRequestByPurposeAndStatusCount(purpose: String): Flow<Int> {
|
||||
return database.synchronizeNostrEventRequestDao().observeSynchronizeNostrEventRequestByPurposeAndStatusCount(
|
||||
"feed",
|
||||
|
||||
@@ -28,6 +28,7 @@ fun String.parseIncomingMessage(): NostrIncomingMessage? {
|
||||
NostrVerb.Incoming.AUTH -> jsonArray.takeAsAuthIncomingMessage()
|
||||
NostrVerb.Incoming.COUNT -> jsonArray.takeAsCountIncomingMessage()
|
||||
NostrVerb.Incoming.EVENTS -> jsonArray.takeAsEventsIncomingMessage()
|
||||
else -> null
|
||||
}
|
||||
} catch (error: Exception) {
|
||||
Logger.withTag("String.parseIncomingMessage").w(error) { "Unable to parse incoming message." }
|
||||
@@ -136,7 +137,7 @@ private fun JsonArray.takeAsOkIncomingMessage(): NostrIncomingMessage? {
|
||||
}
|
||||
}
|
||||
|
||||
private fun JsonElement.toIncomingMessageType(): NostrVerb.Incoming {
|
||||
private fun JsonElement.toIncomingMessageType(): NostrVerb.Incoming? {
|
||||
return when (this.jsonPrimitive.content) {
|
||||
"EVENT" -> NostrVerb.Incoming.EVENT
|
||||
"EOSE" -> NostrVerb.Incoming.EOSE
|
||||
@@ -144,7 +145,11 @@ private fun JsonElement.toIncomingMessageType(): NostrVerb.Incoming {
|
||||
"AUTH" -> NostrVerb.Incoming.AUTH
|
||||
"COUNT" -> NostrVerb.Incoming.COUNT
|
||||
"EVENTS" -> NostrVerb.Incoming.EVENTS
|
||||
else -> NostrVerb.Incoming.NOTICE
|
||||
"NOTICE" -> NostrVerb.Incoming.NOTICE
|
||||
else -> {
|
||||
Logger.d("Unsupported incomingMessageType: ${this.jsonPrimitive.content}")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,6 +91,10 @@ interface NostrRepository {
|
||||
synchronizeNostrEventRequests: List<SynchronizeNostrEventRequest>,
|
||||
)
|
||||
|
||||
suspend fun queueNegentropySynchronizeRequest(
|
||||
negentropySynchronizeRequests: List<NegentropySynchronizeRequest>
|
||||
)
|
||||
|
||||
suspend fun observeSynchronizeNostrEventRequestByPurposeAndStatusCount(purpose: String): Flow<Int>
|
||||
|
||||
|
||||
@@ -227,6 +231,10 @@ interface NostrRepository {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun queueNegentropySynchronizeRequest(negentropySynchronizeRequests: List<NegentropySynchronizeRequest>) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun observeSynchronizeNostrEventRequestByPurposeAndStatusCount(purpose: String): Flow<Int> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ac.cord.auxiliary.compose.ui.view.model
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.NegentropySynchronizeRequest
|
||||
import ac.cord.auxiliary.compose.database.model.SynchronizeNostrEventRequest
|
||||
import ac.cord.auxiliary.compose.database.model.types.SynchronizationFilter
|
||||
import ac.cord.auxiliary.compose.nostr.Relays
|
||||
@@ -74,15 +75,13 @@ class FeedListViewModel(
|
||||
logger.d("scheduleSynchronization")
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
// Sync Notifications... might want to also run this in the background
|
||||
nostrRepository.queueSynchronizeNostrEvent(
|
||||
Relays.eventPublishRelaySet.take(1).map { normalizedRelay -> // TODO: Sync from all the publish relays...
|
||||
SynchronizeNostrEventRequest(
|
||||
nostrRepository.queueNegentropySynchronizeRequest(
|
||||
Relays.eventPublishRelaySet.take(1).map { normalizedRelayUrl ->
|
||||
NegentropySynchronizeRequest(
|
||||
purpose = "feed",
|
||||
synchronizationFilters = arrayOf(
|
||||
synchronizationFilter
|
||||
),
|
||||
relayURL = normalizedRelay.url,
|
||||
level = 0,
|
||||
synchronizationFilter = synchronizationFilter,
|
||||
relayURL = normalizedRelayUrl.url,
|
||||
level = 0
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ac.cord.auxiliary.compose.ui.view.model
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.NegentropySynchronizeRequest
|
||||
import ac.cord.auxiliary.compose.database.model.SynchronizeNostrEventRequest
|
||||
import ac.cord.auxiliary.compose.database.model.types.SynchronizationFilter
|
||||
import ac.cord.auxiliary.compose.nostr.Relays
|
||||
@@ -74,14 +75,12 @@ class FollowersListViewModel(
|
||||
logger.d("scheduleSynchronization")
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
// Sync Notifications... might want to also run this in the background
|
||||
nostrRepository.queueSynchronizeNostrEvent(
|
||||
Relays.eventPublishRelaySet.take(1).map { normalizedRelay -> // TODO: Sync from all the publish relays...
|
||||
SynchronizeNostrEventRequest(
|
||||
purpose = "feed",
|
||||
synchronizationFilters = arrayOf(
|
||||
synchronizationFilter
|
||||
),
|
||||
relayURL = normalizedRelay.url,
|
||||
nostrRepository.queueNegentropySynchronizeRequest(
|
||||
Relays.eventPublishRelaySet.take(1).map { normalizedRelayUrl ->
|
||||
NegentropySynchronizeRequest(
|
||||
purpose = "followers",
|
||||
synchronizationFilter = synchronizationFilter,
|
||||
relayURL = normalizedRelayUrl.url,
|
||||
level = 0
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ac.cord.auxiliary.compose.ui.view.model
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.NegentropySynchronizeRequest
|
||||
import ac.cord.auxiliary.compose.database.model.SynchronizeNostrEventRequest
|
||||
import ac.cord.auxiliary.compose.database.model.types.SynchronizationFilter
|
||||
import ac.cord.auxiliary.compose.nostr.Relays
|
||||
@@ -73,14 +74,12 @@ class FollowingListViewModel(
|
||||
logger.d("scheduleSynchronization")
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
// Sync Notifications... might want to also run this in the background
|
||||
nostrRepository.queueSynchronizeNostrEvent(
|
||||
Relays.eventPublishRelaySet.take(1).map { normalizedRelay -> // TODO: Sync from all the publish relays...
|
||||
SynchronizeNostrEventRequest(
|
||||
purpose = "feed",
|
||||
synchronizationFilters = arrayOf(
|
||||
synchronizationFilter
|
||||
),
|
||||
relayURL = normalizedRelay.url,
|
||||
nostrRepository.queueNegentropySynchronizeRequest(
|
||||
Relays.eventPublishRelaySet.take(1).map { normalizedRelayUrl ->
|
||||
NegentropySynchronizeRequest(
|
||||
purpose = "following",
|
||||
synchronizationFilter = synchronizationFilter,
|
||||
relayURL = normalizedRelayUrl.url,
|
||||
level = 0
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package ac.cord.auxiliary.compose.ui.view.model
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.NegentropySynchronizeRequest
|
||||
import ac.cord.auxiliary.compose.database.model.SynchronizeNostrEventRequest
|
||||
import ac.cord.auxiliary.compose.database.model.types.SynchronizationFilter
|
||||
import ac.cord.auxiliary.compose.nostr.Relays
|
||||
@@ -78,15 +79,13 @@ class InReplyToViewModel(
|
||||
logger.d("scheduleSynchronization")
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
// Sync Notifications... might want to also run this in the background
|
||||
nostrRepository.queueSynchronizeNostrEvent(
|
||||
Relays.eventPublishRelaySet.take(1).map { normalizedRelay -> // TODO: Sync from all the publish relays...
|
||||
SynchronizeNostrEventRequest(
|
||||
purpose = "feed",
|
||||
synchronizationFilters = arrayOf(
|
||||
synchronizationFilter
|
||||
),
|
||||
relayURL = normalizedRelay.url,
|
||||
level = 0,
|
||||
nostrRepository.queueNegentropySynchronizeRequest(
|
||||
Relays.eventPublishRelaySet.take(1).map { normalizedRelayUrl ->
|
||||
NegentropySynchronizeRequest(
|
||||
purpose = "inReplyTo",
|
||||
synchronizationFilter = synchronizationFilter,
|
||||
relayURL = normalizedRelayUrl.url,
|
||||
level = 0
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ac.cord.auxiliary.compose.ui.view.model
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.NostrEvent
|
||||
import ac.cord.auxiliary.compose.database.model.SynchronizeNostrEventRequest
|
||||
import ac.cord.auxiliary.compose.managers.SeedManager
|
||||
import ac.cord.auxiliary.compose.network.dto.RelayDTO
|
||||
import ac.cord.auxiliary.compose.network.relays.RelayPool.Companion.PUBLISH_TIMEOUT
|
||||
@@ -304,6 +305,19 @@ class NavigationViewModel(
|
||||
negentropySynchronizeRequest.relayURL
|
||||
)
|
||||
}
|
||||
// TODO: Handle negentropy error...
|
||||
// nostrRepository.queueSynchronizeNostrEvent(
|
||||
// Relays.eventPublishRelaySet.take(1).map { normalizedRelay -> // TODO: Sync from all the publish relays...
|
||||
// SynchronizeNostrEventRequest(
|
||||
// purpose = "feed",
|
||||
// synchronizationFilters = arrayOf(
|
||||
// synchronizationFilter
|
||||
// ),
|
||||
// relayURL = normalizedRelay.url,
|
||||
// level = 0,
|
||||
// )
|
||||
// }
|
||||
// )
|
||||
else -> {
|
||||
logger.d("Unhandled message ${negentropySynchronizeRequest.relayURL}: $nostrIncomingMessage")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user