Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only mark sync state enabled when entire group is enabled #785

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/sync/sync-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ function getRemoteDevicesSyncState(namespaceSyncState, peerSyncControllers) {
for (const psc of peerSyncControllers) {
const { peerId } = psc

/** @type {undefined | boolean} */ let isInitialEnabled
/** @type {undefined | boolean} */ let isDataEnabled

for (const namespace of NAMESPACES) {
const isBlocked = psc.syncCapability[namespace] === 'blocked'
if (isBlocked) continue
Expand Down Expand Up @@ -556,13 +559,24 @@ function getRemoteDevicesSyncState(namespaceSyncState, peerSyncControllers) {
}
}

const namespaceGroup = PRESYNC_NAMESPACES.includes(namespace)
? 'initial'
: 'data'
result[peerId][namespaceGroup].isSyncEnabled = isSyncEnabled
/** @type {'initial' | 'data'} */ let namespaceGroup
const isPresyncNamespace = PRESYNC_NAMESPACES.includes(namespace)
if (isPresyncNamespace) {
namespaceGroup = 'initial'
isInitialEnabled = (isInitialEnabled ?? true) && isSyncEnabled
} else {
namespaceGroup = 'data'
isDataEnabled = (isDataEnabled ?? true) && isSyncEnabled
}

result[peerId][namespaceGroup].want += peerNamespaceState.want
result[peerId][namespaceGroup].wanted += peerNamespaceState.wanted
}

if (Object.hasOwn(result, peerId)) {
result[peerId].initial.isSyncEnabled = Boolean(isInitialEnabled)
result[peerId].data.isSyncEnabled = Boolean(isDataEnabled)
}
}

return result
Expand Down
Loading