-
Notifications
You must be signed in to change notification settings - Fork 13k
feat: Implement Call History contextual bar inside rooms #37773
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
edb07b4
custom action for opening the new contextualbar
gabriellsh 748fc92
Add contextualbar component
gabriellsh 3384e9f
Actions
gabriellsh e909844
Split code for external/internal items
gabriellsh b2c3873
Fix error info
gabriellsh 5e22ed1
Fix type narrowing
gabriellsh 800a348
Merge branch 'develop' into feat/callHistoryCore
gabriellsh d432ba3
Update apps/meteor/client/views/mediaCallHistory/useMediaCallInternal…
gabriellsh 66111bd
fix review
gabriellsh 6715392
Merge branch 'develop' into feat/callHistoryCore
gabriellsh 616dda8
Merge branch 'develop' into feat/callHistoryCore
kodiakhq[bot] 236470f
Merge branch 'develop' into feat/callHistoryCore
kodiakhq[bot] 601bfb0
Merge branch 'develop' into feat/callHistoryCore
kodiakhq[bot] 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
61 changes: 61 additions & 0 deletions
61
apps/meteor/client/views/mediaCallHistory/MediaCallHistoryContextualbar.tsx
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,61 @@ | ||
| import { | ||
| ContextualbarHeader, | ||
| ContextualbarIcon, | ||
| ContextualbarTitle, | ||
| ContextualbarClose, | ||
| ContextualbarEmptyContent, | ||
| ContextualbarDialog, | ||
| ContextualbarSkeleton, | ||
| } from '@rocket.chat/ui-client'; | ||
| import { useEndpoint, useRouteParameter, useRoomToolbox } from '@rocket.chat/ui-contexts'; | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| import MediaCallHistoryExternal, { isExternalCallHistoryItem } from './MediaCallHistoryExternal'; | ||
| import MediaCallHistoryInternal, { isInternalCallHistoryItem } from './MediaCallHistoryInternal'; | ||
| import { callHistoryQueryKeys } from '../../lib/queryKeys'; | ||
|
|
||
| export const MediaCallHistoryContextualbar = () => { | ||
| const context = useRouteParameter('context'); | ||
|
|
||
| const { closeTab } = useRoomToolbox(); | ||
| const { t } = useTranslation(); | ||
|
|
||
| const getCallHistory = useEndpoint('GET', '/v1/call-history.info'); | ||
| const { data, isPending, isSuccess } = useQuery({ | ||
| queryKey: callHistoryQueryKeys.info(context), | ||
| queryFn: async () => { | ||
| if (!context) { | ||
| throw new Error('Call ID is required'); | ||
| } | ||
| return getCallHistory({ callId: context } as any); // TODO fix this type | ||
| }, | ||
| staleTime: Infinity, // Call history should never change... | ||
| enabled: !!context, | ||
| }); | ||
|
|
||
| if (isPending) { | ||
| return <ContextualbarSkeleton />; | ||
| } | ||
|
|
||
| if (isSuccess && isInternalCallHistoryItem(data)) { | ||
| return <MediaCallHistoryInternal onClose={closeTab} data={data} />; | ||
| } | ||
|
|
||
| if (isSuccess && isExternalCallHistoryItem(data)) { | ||
| return <MediaCallHistoryExternal onClose={closeTab} data={data} />; | ||
| } | ||
|
|
||
| return ( | ||
| <ContextualbarDialog onClose={closeTab}> | ||
| <ContextualbarHeader> | ||
| <ContextualbarIcon name='info-circled' /> | ||
| <ContextualbarTitle>{t('Call_info')}</ContextualbarTitle> | ||
| <ContextualbarClose onClick={closeTab} /> | ||
| </ContextualbarHeader> | ||
| <ContextualbarEmptyContent icon='warning' title={t('Call_info_could_not_be_loaded')} subtitle={t('Please_try_again')} /> | ||
| </ContextualbarDialog> | ||
| ); | ||
| }; | ||
|
|
||
| export default MediaCallHistoryContextualbar; |
50 changes: 50 additions & 0 deletions
50
apps/meteor/client/views/mediaCallHistory/MediaCallHistoryExternal.tsx
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,50 @@ | ||
| import type { CallHistoryItem, IExternalMediaCallHistoryItem, IMediaCall, Serialized } from '@rocket.chat/core-typings'; | ||
| import { CallHistoryContextualBar, useMediaCallContext } from '@rocket.chat/ui-voip'; | ||
| import { useMemo } from 'react'; | ||
|
|
||
| type ExternalCallEndpointData = Serialized<{ | ||
| item: IExternalMediaCallHistoryItem; | ||
| call: IMediaCall; | ||
| }>; | ||
|
|
||
| type MediaCallHistoryExternalProps = { | ||
| data: ExternalCallEndpointData; | ||
| onClose: () => void; | ||
| }; | ||
|
|
||
| const getContact = (item: ExternalCallEndpointData['item']) => { | ||
| return { | ||
| number: item.contactExtension, | ||
| }; | ||
| }; | ||
|
|
||
| export const isExternalCallHistoryItem = (data: { item: Serialized<CallHistoryItem> }): data is ExternalCallEndpointData => { | ||
| return 'external' in data.item && data.item.external; | ||
| }; | ||
|
|
||
| const MediaCallHistoryExternal = ({ data, onClose }: MediaCallHistoryExternalProps) => { | ||
| const contact = useMemo(() => getContact(data.item), [data]); | ||
| const historyData = useMemo(() => { | ||
| return { | ||
| callId: data.call._id, | ||
| direction: data.item.direction, | ||
| duration: data.item.duration, | ||
| startedAt: new Date(data.item.ts), | ||
| state: data.item.state, | ||
| }; | ||
| }, [data]); | ||
| const { onToggleWidget } = useMediaCallContext(); | ||
|
|
||
| const actions = useMemo(() => { | ||
| if (!onToggleWidget) { | ||
| return {}; | ||
| } | ||
| return { | ||
| voiceCall: () => onToggleWidget(contact), | ||
| }; | ||
| }, [contact, onToggleWidget]); | ||
|
|
||
| return <CallHistoryContextualBar onClose={onClose} actions={actions} contact={contact} data={historyData} />; | ||
| }; | ||
|
|
||
| export default MediaCallHistoryExternal; |
49 changes: 49 additions & 0 deletions
49
apps/meteor/client/views/mediaCallHistory/MediaCallHistoryInternal.tsx
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,49 @@ | ||
| import type { CallHistoryItem, IInternalMediaCallHistoryItem, IMediaCall, Serialized } from '@rocket.chat/core-typings'; | ||
| import { CallHistoryContextualBar } from '@rocket.chat/ui-voip'; | ||
| import { useMemo } from 'react'; | ||
|
|
||
| import { useMediaCallInternalHistoryActions } from './useMediaCallInternalHistoryActions'; | ||
|
|
||
| type InternalCallEndpointData = Serialized<{ | ||
| item: IInternalMediaCallHistoryItem; | ||
| call: IMediaCall; | ||
| }>; | ||
|
|
||
| type MediaCallHistoryInternalProps = { | ||
| data: InternalCallEndpointData; | ||
| onClose: () => void; | ||
| }; | ||
|
|
||
| export const isInternalCallHistoryItem = (data: { item: Serialized<CallHistoryItem> }): data is InternalCallEndpointData => { | ||
| return 'external' in data.item && !data.item.external; | ||
| }; | ||
|
|
||
| const getContact = (item: InternalCallEndpointData['item'], call: InternalCallEndpointData['call']) => { | ||
| const { caller, callee } = call ?? {}; | ||
| const contact = caller?.id === item.contactId ? caller : callee; | ||
| const { id, sipExtension, username, ...rest } = contact; | ||
| return { | ||
| ...rest, | ||
| _id: id, | ||
| username: username ?? '', | ||
| voiceCallExtension: sipExtension, | ||
| }; | ||
| }; | ||
|
|
||
| const MediaCallHistoryInternal = ({ data, onClose }: MediaCallHistoryInternalProps) => { | ||
| const contact = useMemo(() => getContact(data.item, data.call), [data]); | ||
| const historyData = useMemo(() => { | ||
| return { | ||
| callId: data.call._id, | ||
| direction: data.item.direction, | ||
| duration: data.item.duration, | ||
| startedAt: new Date(data.item.ts), | ||
| state: data.item.state, | ||
| }; | ||
| }, [data]); | ||
| const actions = useMediaCallInternalHistoryActions(contact, data.item.messageId); | ||
|
|
||
| return <CallHistoryContextualBar onClose={onClose} actions={actions} contact={contact} data={historyData} />; | ||
| }; | ||
|
|
||
| export default MediaCallHistoryInternal; | ||
73 changes: 73 additions & 0 deletions
73
apps/meteor/client/views/mediaCallHistory/useMediaCallInternalHistoryActions.ts
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,73 @@ | ||
| import { useEffectEvent } from '@rocket.chat/fuselage-hooks'; | ||
| import type { LocationPathname } from '@rocket.chat/ui-contexts'; | ||
| import { useCurrentRoutePath, useRoomToolbox, useRouter, useUserAvatarPath } from '@rocket.chat/ui-contexts'; | ||
| import { useMediaCallContext } from '@rocket.chat/ui-voip'; | ||
| import { useMemo } from 'react'; | ||
|
|
||
| import { useRoom } from '../room/contexts/RoomContext'; | ||
| import { useDirectMessageAction } from '../room/hooks/useUserInfoActions/actions/useDirectMessageAction'; | ||
|
|
||
| export type InternalCallHistoryContact = { | ||
| _id: string; | ||
| name?: string; | ||
| username: string; | ||
| displayName?: string; | ||
| voiceCallExtension?: string; | ||
| avatarUrl?: string; | ||
| }; | ||
|
|
||
| export const useMediaCallInternalHistoryActions = (contact: InternalCallHistoryContact, messageId?: string) => { | ||
| const { onToggleWidget } = useMediaCallContext(); | ||
| const router = useRouter(); | ||
|
|
||
| const currentRoutePath = useCurrentRoutePath(); | ||
| const room = useRoom(); | ||
| const toolbox = useRoomToolbox(); | ||
| const getAvatarUrl = useUserAvatarPath(); | ||
|
|
||
| const voiceCall = useEffectEvent(() => { | ||
| if (!onToggleWidget) { | ||
| return; | ||
| } | ||
|
|
||
| onToggleWidget({ | ||
| userId: contact._id, | ||
| displayName: contact.displayName ?? '', | ||
| username: contact.username, | ||
| avatarUrl: getAvatarUrl({ username: contact.username }), | ||
| callerId: contact.voiceCallExtension, | ||
| }); | ||
| }); | ||
|
|
||
| const directMessage = useDirectMessageAction(contact, room._id); | ||
|
|
||
| const jumpToMessage = useEffectEvent(() => { | ||
| if (!messageId || !currentRoutePath) { | ||
| return; | ||
| } | ||
|
|
||
| const { msg: _, ...searchParams } = router.getSearchParameters(); | ||
|
|
||
| router.navigate( | ||
| { | ||
| pathname: currentRoutePath as LocationPathname, | ||
| search: messageId ? { ...searchParams, msg: messageId } : searchParams, | ||
| }, | ||
| { replace: true }, | ||
| ); | ||
| }); | ||
|
|
||
| const userInfo = useEffectEvent(() => { | ||
| toolbox.openTab('user-info', contact._id); | ||
| }); | ||
|
|
||
| return useMemo( | ||
| () => ({ | ||
| voiceCall, | ||
| directMessage: directMessage && 'onClick' in directMessage ? directMessage.onClick : undefined, | ||
| jumpToMessage, | ||
| userInfo, | ||
| }), | ||
| [voiceCall, directMessage, jumpToMessage, userInfo], | ||
| ); | ||
| }; |
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
19 changes: 19 additions & 0 deletions
19
apps/meteor/client/views/room/providers/hooks/useCoreRoomRoutes.ts
gabriellsh marked this conversation as resolved.
Show resolved
Hide resolved
|
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,19 @@ | ||
| import type { RoomToolboxActionConfig } from '@rocket.chat/ui-contexts'; | ||
|
|
||
| import MediaCallHistoryContextualbar from '../../../mediaCallHistory/MediaCallHistoryContextualbar'; | ||
|
|
||
| const mediaCallHistoryRoute: RoomToolboxActionConfig = { | ||
| id: 'media-call-history', | ||
| title: 'Call_Information', | ||
| tabComponent: MediaCallHistoryContextualbar, | ||
| icon: 'info-circled', | ||
| groups: ['direct'], | ||
| }; | ||
|
|
||
| const coreRoomRoutes = [mediaCallHistoryRoute]; | ||
|
|
||
| // This isn't really a proper hook, but it could be extended in the future | ||
| // So we're maitaning the same pattern as `useCoreRoomActions` | ||
gabriellsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export const useCoreRoomRoutes = (): Array<RoomToolboxActionConfig> => { | ||
| return coreRoomRoutes; | ||
| }; | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.