-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add endpoint rooms.membersOrderedByRole (#34153)
Co-authored-by: Martin Schoeler <20868078+MartinSchoeler@users.noreply.github.com>
- Loading branch information
1 parent
3c237b2
commit c8e8518
Showing
30 changed files
with
1,233 additions
and
19 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@rocket.chat/i18n': minor | ||
'@rocket.chat/meteor': minor | ||
--- | ||
|
||
Groups members by their roles in the room's member list for improved clarity |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@rocket.chat/meteor': minor | ||
'@rocket.chat/rest-typings': minor | ||
--- | ||
|
||
Adds `rooms.membersOrderedByRole` endpoint to retrieve members of groups and channels sorted according to their respective role in the room. |
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
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
68 changes: 68 additions & 0 deletions
68
apps/meteor/app/lib/server/functions/syncRolePrioritiesForRoomIfRequired.ts
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import type { IRoom, IUser } from '@rocket.chat/core-typings'; | ||
import { Subscriptions, Users, Rooms } from '@rocket.chat/models'; | ||
|
||
import { calculateRoomRolePriorityFromRoles } from '../../../../server/lib/roles/syncRoomRolePriority'; | ||
|
||
const READ_BATCH_SIZE = 1000; | ||
|
||
async function assignRoomRolePrioritiesFromMap(userIdAndRoomRolePrioritiesMap: Map<IUser['_id'], IUser['roomRolePriorities']>) { | ||
const bulk = Users.col.initializeUnorderedBulkOp(); | ||
|
||
userIdAndRoomRolePrioritiesMap.forEach((roomRolePriorities, userId) => { | ||
userIdAndRoomRolePrioritiesMap.delete(userId); | ||
|
||
if (roomRolePriorities) { | ||
const updateFields = Object.entries(roomRolePriorities).reduce( | ||
(operations, rolePriorityData) => { | ||
const [rid, rolePriority] = rolePriorityData; | ||
operations[`roomRolePriorities.${rid}`] = rolePriority; | ||
return operations; | ||
}, | ||
{} as Record<string, number>, | ||
); | ||
|
||
bulk.find({ _id: userId }).updateOne({ | ||
$set: updateFields, | ||
}); | ||
} | ||
}); | ||
|
||
if (bulk.length > 0) { | ||
await bulk.execute(); | ||
} | ||
} | ||
|
||
export const syncRolePrioritiesForRoomIfRequired = async (rid: IRoom['_id']) => { | ||
const userIdAndRoomRolePrioritiesMap = new Map<IUser['_id'], IUser['roomRolePriorities']>(); | ||
|
||
if (await Rooms.hasCreatedRolePrioritiesForRoom(rid)) { | ||
return; | ||
} | ||
|
||
const cursor = Subscriptions.find( | ||
{ rid, roles: { $exists: true } }, | ||
{ | ||
projection: { 'rid': 1, 'roles': 1, 'u._id': 1 }, | ||
sort: { _id: 1 }, | ||
}, | ||
).batchSize(READ_BATCH_SIZE); | ||
|
||
for await (const sub of cursor) { | ||
if (!sub.roles?.length) { | ||
continue; | ||
} | ||
|
||
const userId = sub.u._id; | ||
const roomId = sub.rid; | ||
const priority = calculateRoomRolePriorityFromRoles(sub.roles); | ||
|
||
const existingPriorities = userIdAndRoomRolePrioritiesMap.get(userId) || {}; | ||
existingPriorities[roomId] = priority; | ||
userIdAndRoomRolePrioritiesMap.set(userId, existingPriorities); | ||
} | ||
|
||
// Flush any remaining priorities in the map | ||
await assignRoomRolePrioritiesFromMap(userIdAndRoomRolePrioritiesMap); | ||
|
||
await Rooms.markRolePrioritesCreatedForRoom(rid); | ||
}; |
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
32 changes: 32 additions & 0 deletions
32
apps/meteor/client/views/room/contextualBar/RoomMembers/MembersListDivider.tsx
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Box } from '@rocket.chat/fuselage'; | ||
import type { TranslationKey } from '@rocket.chat/ui-contexts'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
type MembersListDividerProps = { | ||
title: TranslationKey; | ||
count: number; | ||
}; | ||
|
||
export const MembersListDivider = ({ title, count }: MembersListDividerProps) => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<Box | ||
key={title} | ||
backgroundColor='room' | ||
height={36} | ||
fontScale='p2m' | ||
color='defaut' | ||
paddingBlock={8} | ||
paddingInline={24} | ||
display='flex' | ||
flexDirection='row' | ||
justifyContent='space-between' | ||
borderBlockEndWidth={1} | ||
borderBlockEndColor='extra-light' | ||
> | ||
<Box>{t(title)}</Box> | ||
<Box>{count}</Box> | ||
</Box> | ||
); | ||
}; |
Oops, something went wrong.