diff --git a/apps/meteor/client/components/message/content/attachments/file/GenericFileAttachment.tsx b/apps/meteor/client/components/message/content/attachments/file/GenericFileAttachment.tsx index cbf1749b9dcd9..8610ae26ff6f4 100644 --- a/apps/meteor/client/components/message/content/attachments/file/GenericFileAttachment.tsx +++ b/apps/meteor/client/components/message/content/attachments/file/GenericFileAttachment.tsx @@ -7,7 +7,7 @@ import { MessageGenericPreviewDescription, } from '@rocket.chat/fuselage'; import { useMediaUrl } from '@rocket.chat/ui-contexts'; -import type { FC } from 'react'; +import type { UIEvent } from 'react'; import React from 'react'; import { getFileExtension } from '../../../../../../lib/utils/getFileExtension'; @@ -16,7 +16,11 @@ import MessageCollapsible from '../../../MessageCollapsible'; import MessageContentBody from '../../../MessageContentBody'; import AttachmentSize from '../structure/AttachmentSize'; -export const GenericFileAttachment: FC = ({ +const openDocumentViewer = window.RocketChatDesktop?.openDocumentViewer; + +type GenericFileAttachmentProps = MessageAttachmentBase; + +export const GenericFileAttachment = ({ title, description, descriptionMd, @@ -25,9 +29,24 @@ export const GenericFileAttachment: FC = ({ size, format, collapsed, -}) => { +}: GenericFileAttachmentProps) => { const getURL = useMediaUrl(); + const handleTitleClick = (event: UIEvent): void => { + if (openDocumentViewer && link && format === 'PDF') { + event.preventDefault(); + openDocumentViewer(getURL(link), format, ''); + } + }; + + const getExternalUrl = () => { + if (!hasDownload || !link) return undefined; + + if (openDocumentViewer) return `${getURL(link)}?download`; + + return getURL(link); + }; + return ( <> {descriptionMd ? : } @@ -36,7 +55,7 @@ export const GenericFileAttachment: FC = ({ } > - + {title} {size && ( diff --git a/apps/meteor/client/definitions/IRocketChatDesktop.ts b/apps/meteor/client/definitions/IRocketChatDesktop.ts new file mode 100644 index 0000000000000..52bc172d719b1 --- /dev/null +++ b/apps/meteor/client/definitions/IRocketChatDesktop.ts @@ -0,0 +1,10 @@ +type OutlookEventsResponse = { status: 'success' | 'canceled' }; + +export interface IRocketChatDesktop { + openInternalVideoChatWindow?: (url: string, options: { providerName: string | undefined }) => void; + getOutlookEvents?: (date: Date) => Promise; + setOutlookExchangeUrl?: (url: string, userId: string) => Promise; + hasOutlookCredentials?: () => Promise; + clearOutlookCredentials?: () => void; + openDocumentViewer?: (url: string, format: string, options: any) => void; +} diff --git a/apps/meteor/client/definitions/global.d.ts b/apps/meteor/client/definitions/global.d.ts new file mode 100644 index 0000000000000..8b20108e8e489 --- /dev/null +++ b/apps/meteor/client/definitions/global.d.ts @@ -0,0 +1,8 @@ +import type { IRocketChatDesktop } from './IRocketChatDesktop'; + +declare global { + // eslint-disable-next-line @typescript-eslint/naming-convention + interface Window { + RocketChatDesktop?: IRocketChatDesktop; + } +} diff --git a/apps/meteor/client/lib/utils/window.RocketChatDesktop.d.ts b/apps/meteor/client/lib/utils/window.RocketChatDesktop.d.ts deleted file mode 100644 index a7f625fc07058..0000000000000 --- a/apps/meteor/client/lib/utils/window.RocketChatDesktop.d.ts +++ /dev/null @@ -1,14 +0,0 @@ -type OutlookEventsResponse = { status: 'success' | 'canceled' }; - -// eslint-disable-next-line @typescript-eslint/naming-convention -interface Window { - RocketChatDesktop: - | { - openInternalVideoChatWindow?: (url: string, options: { providerName: string | undefined }) => void; - getOutlookEvents?: (date: Date) => Promise; - setOutlookExchangeUrl?: (url: string, userId: string) => Promise; - hasOutlookCredentials?: () => Promise; - clearOutlookCredentials?: () => void; - } - | undefined; -}