Refactor syncing
This commit is contained in:
1 parent
d39b567748
commit
0d4b517506
3 files changed
+30
-16
No files matched your search
+18
@@ -50,6 +50,24 @@ data class NegentropySynchronizeRequest(
|
|||||||
override val updatedAt: Instant = createdAt,
|
override val updatedAt: Instant = createdAt,
|
||||||
): OptionalNostrEventEntity, TimestampedEntity {
|
): 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 {
|
companion object {
|
||||||
fun computeId(
|
fun computeId(
|
||||||
relayURL: String,
|
relayURL: String,
|
||||||
|
|||||||
+1
@@ -120,6 +120,7 @@ class ChatRoomDetailMessageListViewModel(
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
isReceiverChatMessageRelayListMissing.value = true
|
isReceiverChatMessageRelayListMissing.value = true
|
||||||
|
// TODO: compute the timestamp for when list we sent messages and use that as since...
|
||||||
Pair(
|
Pair(
|
||||||
Relays.negentropicRelaySet,
|
Relays.negentropicRelaySet,
|
||||||
SynchronizationFilter(
|
SynchronizationFilter(
|
||||||
|
|||||||
+11
-16
@@ -258,24 +258,9 @@ class SynchronizationViewModel(
|
|||||||
logger.d("Negentropy Error (need to synchronize like normal): ${nostrIncomingMessage.negentropyReason}")
|
logger.d("Negentropy Error (need to synchronize like normal): ${nostrIncomingMessage.negentropyReason}")
|
||||||
|
|
||||||
// TODO: Don't schedule a sync when on mobile internet.
|
// 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(
|
nostrRepository.queueSynchronizeNostrEvent(
|
||||||
listOf(
|
listOf(
|
||||||
SynchronizeNostrEventRequest(
|
negentropySynchronizeRequest.toSynchronizeNostrEventRequest()
|
||||||
purpose = negentropySynchronizeRequest.purpose,
|
|
||||||
synchronizationFilters = arrayOf(
|
|
||||||
synchronizationFilter
|
|
||||||
),
|
|
||||||
relayURL = negentropySynchronizeRequest.relayURL,
|
|
||||||
level = negentropySynchronizeRequest.level,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return@collect
|
return@collect
|
||||||
@@ -328,6 +313,16 @@ class SynchronizationViewModel(
|
|||||||
|
|
||||||
return@collect
|
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 -> {
|
else -> {
|
||||||
logger.d("Unhandled message ${negentropySynchronizeRequest.relayURL}: $nostrIncomingMessage")
|
logger.d("Unhandled message ${negentropySynchronizeRequest.relayURL}: $nostrIncomingMessage")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user