MCPcopy
hub / github.com/directus/directus / join

Method join

api/src/websocket/collab/room.ts:364–447  ·  view source on GitHub ↗

* Client requesting to join a room. If the client hasn't entered the room already, add a new client. * Otherwise all users just will be informed again that the user has joined.

(client: WebSocketClient, color?: JoinMessage['color'])

Source from the content-addressed store, hash-verified

362 * Otherwise all users just will be informed again that the user has joined.
363 */
364 async join(client: WebSocketClient, color?: JoinMessage['color']) {
365 this.messenger.addClient(client);
366
367 let added = false;
368 let clientColor: Color | undefined;
369
370 if (!(await this.hasClient(client.uid))) {
371 await this.store(async (store) => {
372 const clients = await store.get('clients');
373 added = true;
374
375 const existingColors = clients.map((c) => c.color);
376 const colorsAvailable = COLORS.filter((color) => !existingColors.includes(color));
377
378 if (colorsAvailable.length === 0) {
379 colorsAvailable.push(...COLORS);
380 }
381
382 if (color && colorsAvailable.includes(color)) {
383 clientColor = color;
384 } else {
385 clientColor = colorsAvailable[random(colorsAvailable.length - 1)]!;
386 }
387
388 clients.push({
389 uid: client.uid,
390 accountability: client.accountability!,
391 color: clientColor,
392 });
393
394 await store.set('clients', clients);
395 });
396 }
397
398 if (added && clientColor) {
399 await this.sendExcluding(
400 {
401 action: ACTION.SERVER.JOIN,
402 user: client.accountability!.user!,
403 connection: client.uid,
404 color: clientColor,
405 },
406 client.uid,
407 );
408 }
409
410 const { changes, focuses, clients } = await this.store(async (store) => {
411 return {
412 changes: await store.get('changes'),
413 focuses: await store.get('focuses'),
414 clients: await store.get('clients'),
415 };
416 });
417
418 const schema = await getSchema();
419 const knex = getDatabase();
420
421 const allowedFields = await verifyPermissions(client.accountability, this.collection, this.item, 'read', {

Callers 15

addFunction · 0.80
toConvertSourceUrlFunction · 0.80
createFunction · 0.80
createBundleExtensionFunction · 0.80
createExtensionFunction · 0.80
linkFunction · 0.80
buildFunction · 0.80
buildExtensionFunction · 0.80
generateBundleEntrypointFunction · 0.80
copyTemplateFileFunction · 0.80
getFilesInDirFunction · 0.80
getLanguageTemplateFilesFunction · 0.80

Calls 12

hasClientMethod · 0.95
sendExcludingMethod · 0.95
sendMethod · 0.95
getSchemaFunction · 0.85
getDatabaseFunction · 0.85
verifyPermissionsFunction · 0.85
sanitizePayloadFunction · 0.85
addClientMethod · 0.80
fromMethod · 0.80
getMethod · 0.65
setMethod · 0.65
isFieldAllowedFunction · 0.50

Tested by 4

flattenFunction · 0.64
getNonIndexFileNamesInFunction · 0.64
getFileLinesFunction · 0.64