-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
// ["[email protected]", "[email protected]"] | ||
// 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()) | ||
} |