Skip to content

Commit 9a378d4

Browse files
authored
Merge pull request #104 from Automattic/improve/sync-collection-support
Support for collection syncing
2 parents ea74c5a + 3d0e28c commit 9a378d4

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

inc/Auth/SyncPermissions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ public static function can_sync(
4646
// Extract Gutenberg entity kind and name from sync object type
4747
[ $entity_kind, $entity_name ] = $parts;
4848

49-
// Handle post type entities
50-
if ( 'postType' === $entity_kind ) {
49+
// Handle post type entities (not collections)
50+
if ( 'postType' === $entity_kind && 'collection' !== $sync_object_id ) {
5151
/**
5252
* For post entities, we only need the sync object ID (post ID) for permission checking.
5353
* The entity_name is Gutenberg's entity name which maps to post type name instead of

src/websocket-client.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,16 @@ export function createWebSocketConnection( serverUrl: string ): ProviderCreator
176176

177177
return async function (
178178
objectType: ObjectType,
179-
objectId: ObjectID,
179+
objectId: ObjectID | null,
180180
doc: Y.Doc,
181181
awareness?: Awareness
182182
) {
183183
try {
184-
// For now, we only support traditional post types.
185-
if ( ! objectType.startsWith( 'postType/' ) || ! parseInt( objectId, 10 ) ) {
184+
// For now, we only support collections and traditional post types.
185+
if (
186+
null !== objectId &&
187+
( ! objectType.startsWith( 'postType/' ) || ! parseInt( objectId, 10 ) )
188+
) {
186189
logger.debug( 'WebSocket connection skipped for unsupported object', {
187190
objectType,
188191
objectId,
@@ -198,10 +201,10 @@ export function createWebSocketConnection( serverUrl: string ): ProviderCreator
198201
* multisite. We don't sync entities like those yet. When we do, we'll need to revisit
199202
* adding the blog ID to the room name as that won't be needed.
200203
*/
201-
const roomName = `site-${ BLOG_ID ?? 1 }/${ objectType }-${ objectId }`;
204+
const roomName = `site-${ BLOG_ID ?? 1 }/${ objectType }-${ objectId ?? 'collection' }`;
202205
const options = { ...config.options, awareness };
203206
const provider = new WebsocketProvider( config.serverUrl, roomName, doc, options );
204-
const connect = createConnect( provider, objectType, objectId );
207+
const connect = createConnect( provider, objectType, objectId ?? 'collection' );
205208

206209
provider.on( 'connection-close', connect );
207210
provider.on( 'connection-error', () => {

0 commit comments

Comments
 (0)