Fix: Race condition in websocket emit
This commit is contained in:
@ -32,7 +32,7 @@ export default async function present(document: Document, options: ?Options) {
|
|||||||
publishedAt: document.publishedAt,
|
publishedAt: document.publishedAt,
|
||||||
archivedAt: document.archivedAt,
|
archivedAt: document.archivedAt,
|
||||||
deletedAt: document.deletedAt,
|
deletedAt: document.deletedAt,
|
||||||
team: document.teamId,
|
teamId: document.teamId,
|
||||||
collaborators: [],
|
collaborators: [],
|
||||||
starred: document.starred ? !!document.starred.length : undefined,
|
starred: document.starred ? !!document.starred.length : undefined,
|
||||||
revision: document.revisionCount,
|
revision: document.revisionCount,
|
||||||
|
@ -20,22 +20,26 @@ export default class Websockets {
|
|||||||
const document = await Document.findById(event.modelId, {
|
const document = await Document.findById(event.modelId, {
|
||||||
paranoid: false,
|
paranoid: false,
|
||||||
});
|
});
|
||||||
|
const documents = [await presentDocument(document)];
|
||||||
|
const collections = [await presentCollection(document.collection)];
|
||||||
|
|
||||||
return socketio
|
return socketio
|
||||||
.to(`collection-${document.collectionId}`)
|
.to(`collection-${document.collectionId}`)
|
||||||
.emit('entities', {
|
.emit('entities', {
|
||||||
event: event.name,
|
event: event.name,
|
||||||
documents: [await presentDocument(document)],
|
documents,
|
||||||
collections: [await presentCollection(document.collection)],
|
collections,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case 'documents.create': {
|
case 'documents.create': {
|
||||||
const document = await Document.findById(event.modelId);
|
const document = await Document.findById(event.modelId);
|
||||||
|
const documents = [await presentDocument(document)];
|
||||||
|
const collections = [await presentCollection(document.collection)];
|
||||||
|
|
||||||
return socketio.to(`user-${event.actorId}`).emit('entities', {
|
return socketio.to(`user-${event.actorId}`).emit('entities', {
|
||||||
event: event.name,
|
event: event.name,
|
||||||
documents: [await presentDocument(document)],
|
documents,
|
||||||
collections: [await presentCollection(document.collection)],
|
collections,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case 'documents.star':
|
case 'documents.star':
|
||||||
@ -58,15 +62,17 @@ export default class Websockets {
|
|||||||
paranoid: false,
|
paranoid: false,
|
||||||
});
|
});
|
||||||
documents.forEach(async document => {
|
documents.forEach(async document => {
|
||||||
|
const documents = [await presentDocument(document)];
|
||||||
socketio.to(`collection-${document.collectionId}`).emit('entities', {
|
socketio.to(`collection-${document.collectionId}`).emit('entities', {
|
||||||
event: event.name,
|
event: event.name,
|
||||||
documents: [await presentDocument(document)],
|
documents,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
collections.forEach(async collection => {
|
collections.forEach(async collection => {
|
||||||
|
const collections = [await presentCollection(collection)];
|
||||||
socketio.to(`collection-${collection.id}`).emit('entities', {
|
socketio.to(`collection-${collection.id}`).emit('entities', {
|
||||||
event: event.name,
|
event: event.name,
|
||||||
collections: [await presentCollection(collection)],
|
collections,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -75,6 +81,7 @@ export default class Websockets {
|
|||||||
const collection = await Collection.findById(event.modelId, {
|
const collection = await Collection.findById(event.modelId, {
|
||||||
paranoid: false,
|
paranoid: false,
|
||||||
});
|
});
|
||||||
|
const collections = [await presentCollection(collection)];
|
||||||
|
|
||||||
socketio
|
socketio
|
||||||
.to(
|
.to(
|
||||||
@ -84,7 +91,7 @@ export default class Websockets {
|
|||||||
)
|
)
|
||||||
.emit('entities', {
|
.emit('entities', {
|
||||||
event: event.name,
|
event: event.name,
|
||||||
collections: [await presentCollection(collection)],
|
collections,
|
||||||
});
|
});
|
||||||
return socketio
|
return socketio
|
||||||
.to(
|
.to(
|
||||||
@ -102,10 +109,11 @@ export default class Websockets {
|
|||||||
const collection = await Collection.findById(event.modelId, {
|
const collection = await Collection.findById(event.modelId, {
|
||||||
paranoid: false,
|
paranoid: false,
|
||||||
});
|
});
|
||||||
|
const collections = [await presentCollection(collection)];
|
||||||
|
|
||||||
return socketio.to(`collection-${collection.id}`).emit('entities', {
|
return socketio.to(`collection-${collection.id}`).emit('entities', {
|
||||||
event: event.name,
|
event: event.name,
|
||||||
collections: [await presentCollection(collection)],
|
collections,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case 'collections.add_user':
|
case 'collections.add_user':
|
||||||
|
Reference in New Issue
Block a user