diff --git a/editor/liveblocks.config.ts b/editor/liveblocks.config.ts index 9e5331c943eb..9f1ac88ae817 100644 --- a/editor/liveblocks.config.ts +++ b/editor/liveblocks.config.ts @@ -134,42 +134,46 @@ export const { return [] } - const room = liveblocksClient.getRoom(projectIdToRoomId(projectId)) - if (room == null) { - return [] - } - - const storage = await room.getStorage() - - const collabs = storage.root.get('collaborators') as LiveObject<{ [userId: string]: User }> - if (collabs == null) { - return [] - } - - const users = Object.values(collabs.toObject()).map((u) => u.toObject()) + const users = await getAllUsersFromRoom(projectIdToRoomId(projectId)) return users.filter((u) => userIds.includes(u.id)) }, async resolveMentionSuggestions({ text, roomId }) { - // Used only for Comments. Return a list of userIds that match `text`. + // Used only for Comments. Return a list of userIds where the name matches `text`. // These userIds are used to create a mention list when typing in the // composer. // // For example when you type "@jo", `text` will be `"jo"`, and - // you should to return an array with John and Joanna's userIds: - // ["john@example.com", "joanna@example.com"] + // you should to return an array with John and Joanna's userIds. - // const userIds = await __fetchAllUserIdsFromDB__(roomId); - // - // Return all userIds if no `text` - // if (!text) { - // return userIds; - // } - // - // Otherwise, filter userIds for the search `text` and return - // return userIds.filter((userId) => - // userId.toLowerCase().includes(text.toLowerCase()) - // ); + const users = await getAllUsersFromRoom(roomId) - return [] + if (text == null) { + return users.map((u) => u.id) + } + + // Otherwise, filter user names for the search `text` and return + return users + .filter((u) => { + if (u.name == null) { + return false + } + return u.name.toLowerCase().includes(text.toLowerCase()) + }) + .map((u) => u.id) }, }) + +async function getAllUsersFromRoom(roomId: string) { + const room = liveblocksClient.getRoom(roomId) + if (room == null) { + return [] + } + + const storage = await room.getStorage() + + const collabs = storage.root.get('collaborators') as LiveObject<{ [userId: string]: User }> + if (collabs == null) { + return [] + } + return Object.values(collabs.toObject()).map((u) => u.toObject()) +}