-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: Room AI Actions #5999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: Room AI Actions #5999
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8c4c408
WIP: room actions
yash-rajpal d010f86
remove commented code
yash-rajpal e7b9e7e
Merge branch 'feat/persist-app-actions' into feat/room-app-actions
yash-rajpal 558a2f9
update stars icon
yash-rajpal 466f8c5
add translations
yash-rajpal 04792ec
filter only AI actions
yash-rajpal 1d58581
fix lint
yash-rajpal 58938ec
handle master stack
yash-rajpal ed54148
Merge branch 'feat/persist-app-actions' into feat/room-app-actions
yash-rajpal 40504ca
fix review
yash-rajpal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,86 @@ | ||
| import { useCallback } from 'react'; | ||
| import { shallowEqual } from 'react-redux'; | ||
|
|
||
| import { | ||
| isDirectRoom, | ||
| isMultipleDirectRoom, | ||
| isOmnichannelRoom, | ||
| isPrivateDiscussion, | ||
| isPrivateRoom, | ||
| isPrivateTeamRoom, | ||
| isPublicDiscussion, | ||
| isPublicRoom, | ||
| isPublicTeamRoom | ||
| } from '../methods/helpers'; | ||
| import { UIActionButtonContext, IAppActionButton, ISubscription, RoomTypeFilter } from '../../definitions'; | ||
| import { TSupportedPermissions } from '../../reducers/permissions'; | ||
| import { getUserSelector } from '../../selectors/login'; | ||
| import { useSubscriptionRoles } from './useSubscriptionRoles'; | ||
| import { useAppSelector } from './useAppSelector'; | ||
|
|
||
| const enumToFilter: { [k in RoomTypeFilter]: (room: ISubscription) => boolean } = { | ||
| [RoomTypeFilter.DIRECT]: isDirectRoom, | ||
| [RoomTypeFilter.DIRECT_MULTIPLE]: isMultipleDirectRoom, | ||
| [RoomTypeFilter.PUBLIC_CHANNEL]: isPublicRoom, | ||
| [RoomTypeFilter.PRIVATE_CHANNEL]: isPrivateRoom, | ||
| [RoomTypeFilter.PUBLIC_TEAM]: isPublicTeamRoom, | ||
| [RoomTypeFilter.PRIVATE_TEAM]: isPrivateTeamRoom, | ||
| [RoomTypeFilter.PUBLIC_DISCUSSION]: isPublicDiscussion, | ||
| [RoomTypeFilter.PRIVATE_DISCUSSION]: isPrivateDiscussion, | ||
| [RoomTypeFilter.LIVE_CHAT]: isOmnichannelRoom | ||
| }; | ||
|
|
||
| const applyRoomFilter = (button: IAppActionButton, room?: ISubscription): boolean => { | ||
| if (!room) { | ||
| return true; | ||
| } | ||
|
|
||
| const { roomTypes } = button.when || {}; | ||
| return !roomTypes || roomTypes.some((filter): boolean => enumToFilter[filter]?.(room)); | ||
| }; | ||
|
|
||
| const useApplyAuthfilter = (rid?: string) => { | ||
| const userRoles = useAppSelector(state => getUserSelector(state).roles || [], shallowEqual); | ||
| const allPermissions = useAppSelector(state => state.permissions, shallowEqual); | ||
| const subscriptionRoles = useSubscriptionRoles(rid); | ||
| const mergedRoles = [...new Set([...subscriptionRoles || [], ...userRoles])]; | ||
|
|
||
| return (button: IAppActionButton) => { | ||
| const { hasOnePermission, hasAllPermissions, hasOneRole, hasAllRoles } = button.when || {}; | ||
|
|
||
| const hasOnePermissionResult = hasOnePermission | ||
| ? hasOnePermission | ||
| .map(permission => (allPermissions[permission as TSupportedPermissions] ?? []).some(r => mergedRoles.includes(r))) | ||
| .includes(true) | ||
| : true; | ||
| const hasAllPermissionsResult = hasAllPermissions | ||
| ? hasAllPermissions | ||
| .map(permission => (allPermissions[permission as TSupportedPermissions] ?? []).every(r => mergedRoles.includes(r))) | ||
| .reduce((acc, value) => value && acc, true) | ||
| : true; | ||
| const hasOneRoleResult = hasOneRole ? hasOneRole.some(role => mergedRoles.includes(role)) : true; | ||
| const hasAllRolesResult = hasAllRoles ? hasAllRoles.every(role => mergedRoles.includes(role)) : true; | ||
|
|
||
| return hasOnePermissionResult && hasAllPermissionsResult && hasOneRoleResult && hasAllRolesResult; | ||
| }; | ||
| }; | ||
|
|
||
| const useApplyButtonFilters = (room?: ISubscription) => { | ||
| const applyAuthFilter = useApplyAuthfilter(room?.rid); | ||
|
|
||
| return useCallback( | ||
| (button: IAppActionButton) => applyAuthFilter(button) && applyRoomFilter(button, room), | ||
| [applyAuthFilter, room] | ||
| ); | ||
| }; | ||
|
|
||
| export const useAppActionButtons = (room?: ISubscription, context?: UIActionButtonContext, category?: string) => { | ||
| const appActionButtons = useAppSelector(state => state.appActionButtons); | ||
| const applyButtonFilters = useApplyButtonFilters(room); | ||
| const parsedButtons = Object.values(appActionButtons); | ||
|
|
||
| return parsedButtons.filter( | ||
| button => | ||
| (!context || button.context === context) && (!category || button.category === category) && applyButtonFilters(button) | ||
| ); | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/RocketChat/Rocket.Chat/blob/726cfbe2889d155314436f12bbe02f94daf467a8/apps/meteor/client/hooks/useApplyButtonFilters.ts#L72
future reference