Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -16,7 +16,11 @@ import MessageCollapsible from '../../../MessageCollapsible';
import MessageContentBody from '../../../MessageContentBody';
import AttachmentSize from '../structure/AttachmentSize';

export const GenericFileAttachment: FC<MessageAttachmentBase> = ({
const openDocumentViewer = window.RocketChatDesktop?.openDocumentViewer;

type GenericFileAttachmentProps = MessageAttachmentBase;

export const GenericFileAttachment = ({
title,
description,
descriptionMd,
Expand All @@ -25,9 +29,24 @@ export const GenericFileAttachment: FC<MessageAttachmentBase> = ({
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 ? <MessageContentBody md={descriptionMd} /> : <MarkdownText parseEmoji content={description} />}
Expand All @@ -36,7 +55,7 @@ export const GenericFileAttachment: FC<MessageAttachmentBase> = ({
<MessageGenericPreviewContent
thumb={<MessageGenericPreviewIcon name='attachment-file' type={format || getFileExtension(title)} />}
>
<MessageGenericPreviewTitle externalUrl={hasDownload && link ? getURL(link) : undefined} data-qa-type='attachment-title-link'>
<MessageGenericPreviewTitle externalUrl={getExternalUrl()} onClick={handleTitleClick} data-qa-type='attachment-title-link'>
{title}
</MessageGenericPreviewTitle>
{size && (
Expand Down
10 changes: 10 additions & 0 deletions apps/meteor/client/definitions/IRocketChatDesktop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type OutlookEventsResponse = { status: 'success' | 'canceled' };

export interface IRocketChatDesktop {
openInternalVideoChatWindow?: (url: string, options: { providerName: string | undefined }) => void;
getOutlookEvents?: (date: Date) => Promise<OutlookEventsResponse>;
setOutlookExchangeUrl?: (url: string, userId: string) => Promise<void>;
hasOutlookCredentials?: () => Promise<boolean>;
clearOutlookCredentials?: () => void;
openDocumentViewer?: (url: string, format: string, options: any) => void;
}
8 changes: 8 additions & 0 deletions apps/meteor/client/definitions/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { IRocketChatDesktop } from './IRocketChatDesktop';

declare global {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface Window {
RocketChatDesktop?: IRocketChatDesktop;
}
}
14 changes: 0 additions & 14 deletions apps/meteor/client/lib/utils/window.RocketChatDesktop.d.ts

This file was deleted.