Refactor syncing
This commit is contained in:
@@ -50,6 +50,24 @@ data class NegentropySynchronizeRequest(
|
||||
override val updatedAt: Instant = createdAt,
|
||||
): OptionalNostrEventEntity, TimestampedEntity {
|
||||
|
||||
fun toSynchronizeNostrEventRequest(): SynchronizeNostrEventRequest {
|
||||
val since = synchronizationFilter.since // TODO: Update since -> until based on what we have in the local db...
|
||||
val until = synchronizationFilter.until
|
||||
|
||||
val synchronizationFilter = synchronizationFilter.copy(
|
||||
since = since,
|
||||
until = until
|
||||
)
|
||||
|
||||
return SynchronizeNostrEventRequest(
|
||||
purpose = purpose,
|
||||
synchronizationFilters = arrayOf(
|
||||
synchronizationFilter
|
||||
),
|
||||
relayURL = relayURL,
|
||||
level = level,
|
||||
)
|
||||
}
|
||||
companion object {
|
||||
fun computeId(
|
||||
relayURL: String,
|
||||
|
||||
@@ -120,6 +120,7 @@ class ChatRoomDetailMessageListViewModel(
|
||||
|
||||
} else {
|
||||
isReceiverChatMessageRelayListMissing.value = true
|
||||
// TODO: compute the timestamp for when list we sent messages and use that as since...
|
||||
Pair(
|
||||
Relays.negentropicRelaySet,
|
||||
SynchronizationFilter(
|
||||
|
||||
@@ -258,24 +258,9 @@ class SynchronizationViewModel(
|
||||
logger.d("Negentropy Error (need to synchronize like normal): ${nostrIncomingMessage.negentropyReason}")
|
||||
|
||||
// TODO: Don't schedule a sync when on mobile internet.
|
||||
val since = negentropySynchronizeRequest.synchronizationFilter.since // TODO: Update since -> until based on what we have in the local db...
|
||||
val until = negentropySynchronizeRequest.synchronizationFilter.until
|
||||
|
||||
val synchronizationFilter = negentropySynchronizeRequest.synchronizationFilter.copy(
|
||||
since = since,
|
||||
until = until
|
||||
)
|
||||
|
||||
nostrRepository.queueSynchronizeNostrEvent(
|
||||
listOf(
|
||||
SynchronizeNostrEventRequest(
|
||||
purpose = negentropySynchronizeRequest.purpose,
|
||||
synchronizationFilters = arrayOf(
|
||||
synchronizationFilter
|
||||
),
|
||||
relayURL = negentropySynchronizeRequest.relayURL,
|
||||
level = negentropySynchronizeRequest.level,
|
||||
)
|
||||
negentropySynchronizeRequest.toSynchronizeNostrEventRequest()
|
||||
)
|
||||
)
|
||||
return@collect
|
||||
@@ -328,6 +313,16 @@ class SynchronizationViewModel(
|
||||
|
||||
return@collect
|
||||
}
|
||||
is NostrIncomingMessage.NoticeMessage -> {
|
||||
logger.d("Notice message ${negentropySynchronizeRequest.relayURL}: $nostrIncomingMessage")
|
||||
if (nostrIncomingMessage.subscriptionId?.contains("negentropy disabled") == true) {
|
||||
nostrRepository.queueSynchronizeNostrEvent(
|
||||
listOf(
|
||||
negentropySynchronizeRequest.toSynchronizeNostrEventRequest()
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
logger.d("Unhandled message ${negentropySynchronizeRequest.relayURL}: $nostrIncomingMessage")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user