Skip to content
Merged
10 changes: 0 additions & 10 deletions apps/meteor/app/autotranslate/client/lib/autotranslate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ export const AutoTranslate = {
}
}

if (attachment.description && attachment.translations && attachment.translations[language]) {
attachment.translations.original = attachment.description;

if (autoTranslateShowInverse) {
attachment.description = attachment.translations.original;
} else {
attachment.description = attachment.translations[language];
}
}

// @ts-expect-error - not sure what to do with this
if (attachment.attachments && attachment.attachments.length > 0) {
// @ts-expect-error - not sure what to do with this
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/autotranslate/server/autotranslate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export abstract class AutoTranslate {
if (message.attachments && message.attachments.length > 0) {
setImmediate(async () => {
for (const [index, attachment] of message.attachments?.entries() ?? []) {
if (attachment.description || attachment.text) {
if (attachment.text) {
// Removes the initial link `[ ](quoterl)` from quote message before translation
const translatedText = attachment?.text?.replace(/\[(.*?)\]\(.*?\)/g, '$1') || attachment?.text;
const attachmentMessage = { ...attachment, text: translatedText };
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/autotranslate/server/deeplTranslate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class DeeplAutoTranslate extends AutoTranslate {
params: {
auth_key: this.apiKey,
target_lang: language,
text: attachment.description || attachment.text || '',
text: attachment.text || '',
},
});
if (!result.ok) {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/autotranslate/server/googleTranslate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class GoogleAutoTranslate extends AutoTranslate {
key: this.apiKey,
target: language,
format: 'text',
q: attachment.description || attachment.text || '',
q: attachment.text || '',
},
});
if (!result.ok) {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/autotranslate/server/msTranslate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class MsAutoTranslate extends AutoTranslate {
return this._translate(
[
{
Text: attachment.description || attachment.text || '',
Text: attachment.text || '',
},
],
targetLanguages,
Expand Down
9 changes: 2 additions & 7 deletions apps/meteor/app/lib/server/functions/notifications/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,8 @@ export async function getEmailContent({ message, user, room }) {
}

if (hasFiles) {
const attachments = message.attachments || [];
const fileParts = files.map((file, index) => {
let part = escapeHTML(file.name);
if (attachments[index]?.description) {
part += `<br/><br/>${escapeHTML(attachments[index].description)}`;
}
return part;
const fileParts = files.map((file) => {
return escapeHTML(file.name);
});
contentParts.push(fileParts.join('<br/><br/>'));
}
Expand Down
2 changes: 0 additions & 2 deletions apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,6 @@ export const sendNotification = async ({
const firstAttachment = message.attachments?.length && message.attachments.shift();

if (firstAttachment) {
firstAttachment.description =
typeof firstAttachment.description === 'string' ? emojione.shortnameToUnicode(firstAttachment.description) : undefined;
firstAttachment.text = typeof firstAttachment.text === 'string' ? emojione.shortnameToUnicode(firstAttachment.text) : undefined;
}

Expand Down
9 changes: 1 addition & 8 deletions apps/meteor/app/lib/server/methods/updateMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function executeUpdateMessage(
// IF the message has custom fields, always update
// Ideally, we'll compare the custom fields to check for change, but since we don't know the shape of
// custom fields, as it's user defined, we're gonna update
const msgText = originalMessage?.attachments?.[0]?.description ?? originalMessage.msg;
const msgText = originalMessage.msg;
if (msgText === message.msg && !previewUrls && !message.customFields) {
return;
}
Expand Down Expand Up @@ -86,13 +86,6 @@ export async function executeUpdateMessage(
}
await canSendMessageAsync(message.rid, { uid: user._id, username: user.username ?? undefined, ...user });

// It is possible to have an empty array as the attachments property, so ensure both things exist
if (originalMessage.attachments && originalMessage.attachments.length > 0 && originalMessage.attachments[0].description !== undefined) {
originalMessage.attachments[0].description = message.msg;
message.attachments = originalMessage.attachments;
message.msg = originalMessage.msg;
}

message.u = originalMessage.u;

return updateMessage(message, user, originalMessage, previewUrls);
Expand Down
5 changes: 1 addition & 4 deletions apps/meteor/app/livechat/server/lib/sendTranscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,14 @@ export async function sendTranscript({

const messageType = MessageTypes.getType(message);

let messageContent = messageType?.system
const messageContent = messageType?.system
? DOMPurify.sanitize(`
<i>${messageType.text(i18n.cloneInstance({ interpolation: { escapeValue: false } }).t, message)}}</i>`)
: escapeHtml(message.msg);

let filesHTML = '';

if (message.attachments && message.attachments?.length > 0) {
messageContent = message.attachments[0].description || '';
escapeHtml(messageContent);

for await (const attachment of message.attachments) {
if (!isFileAttachment(attachment)) {
continue;
Expand Down
5 changes: 1 addition & 4 deletions apps/meteor/app/slackbridge/server/RocketAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,11 @@ export default class RocketAdapter {

if (rocketMessage.file.name) {
let fileName = rocketMessage.file.name;
let text = rocketMessage.msg;
const text = rocketMessage.msg;

const attachment = this.getMessageAttachment(rocketMessage);
if (attachment) {
fileName = Meteor.absoluteUrl(attachment.title_link);
if (!text) {
text = attachment.description;
}
}

await slack.postMessage(slack.getSlackChannel(rocketMessage.rid), { ...rocketMessage, msg: `${text} ${fileName}` });
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/ui/client/lib/ChatMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class ChatMessages implements ChatAPI {
},
editMessage: async (message: IMessage, { cursorAtStart = false }: { cursorAtStart?: boolean } = {}) => {
this.composer?.uploads.clear();
const text = (await this.data.getDraft(message._id)) || message.attachments?.[0]?.description || message.msg;
const text = (await this.data.getDraft(message._id)) || message.msg;

await this.currentEditingMessage.stop();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import { useMediaUrl } from '@rocket.chat/ui-contexts';
import { useMemo } from 'react';

import { useReloadOnError } from './hooks/useReloadOnError';
import MarkdownText from '../../../../MarkdownText';
import MessageCollapsible from '../../../MessageCollapsible';
import MessageContentBody from '../../../MessageContentBody';

const AudioAttachment = ({
title,
audio_url: url,
audio_type: type,
audio_size: size,
description,
descriptionMd,
title_link: link,
title_link_download: hasDownload,
collapsed,
Expand All @@ -25,7 +21,6 @@ const AudioAttachment = ({

return (
<>
{descriptionMd ? <MessageContentBody md={descriptionMd} /> : <MarkdownText parseEmoji content={description} />}
<MessageCollapsible title={title} hasDownload={hasDownload} link={getURL(link || url)} size={size} isCollapsed={collapsed}>
<AudioPlayer src={src} type={type} ref={mediaRef} />
</MessageCollapsible>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import { useTranslation } from 'react-i18next';

import { getFileExtension } from '../../../../../../lib/utils/getFileExtension';
import { forAttachmentDownload, registerDownloadForUid } from '../../../../../hooks/useDownloadFromServiceWorker';
import MarkdownText from '../../../../MarkdownText';
import MessageCollapsible from '../../../MessageCollapsible';
import MessageContentBody from '../../../MessageContentBody';
import AttachmentSize from '../structure/AttachmentSize';

const openDocumentViewer = window.RocketChatDesktop?.openDocumentViewer;
Expand All @@ -24,8 +22,6 @@ type GenericFileAttachmentProps = MessageAttachmentBase;

const GenericFileAttachment = ({
title,
description,
descriptionMd,
title_link: link,
title_link_download: hasDownload,
size,
Expand Down Expand Up @@ -72,7 +68,6 @@ const GenericFileAttachment = ({

return (
<>
{descriptionMd ? <MessageContentBody md={descriptionMd} /> : <MarkdownText parseEmoji content={description} />}
<MessageCollapsible title={title} hasDownload={hasDownload} link={link} isCollapsed={collapsed}>
<MessageGenericPreview style={{ maxWidth: 368, width: '100%' }}>
<MessageGenericPreviewContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import type { ImageAttachmentProps } from '@rocket.chat/core-typings';
import { useMediaUrl } from '@rocket.chat/ui-contexts';

import { useLoadImage } from './hooks/useLoadImage';
import MarkdownText from '../../../../MarkdownText';
import MessageCollapsible from '../../../MessageCollapsible';
import MessageContentBody from '../../../MessageContentBody';
import AttachmentImage from '../structure/AttachmentImage';

const ImageAttachment = ({
Expand All @@ -17,8 +15,6 @@ const ImageAttachment = ({
width: 368,
height: 368,
},
description,
descriptionMd,
title_link: link,
title_link_download: hasDownload,
collapsed,
Expand All @@ -28,7 +24,6 @@ const ImageAttachment = ({

return (
<>
{descriptionMd ? <MessageContentBody md={descriptionMd} /> : <MarkdownText parseEmoji content={description} />}
<MessageCollapsible title={title} hasDownload={hasDownload} link={getURL(link || url)} size={size} isCollapsed={collapsed}>
<AttachmentImage
{...imageDimensions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ import { useMemo } from 'react';

import { useReloadOnError } from './hooks/useReloadOnError';
import { userAgentMIMETypeFallback } from '../../../../../lib/utils/userAgentMIMETypeFallback';
import MarkdownText from '../../../../MarkdownText';
import MessageCollapsible from '../../../MessageCollapsible';
import MessageContentBody from '../../../MessageContentBody';

const VideoAttachment = ({
title,
video_url: url,
video_type: type,
video_size: size,
description,
descriptionMd,
title_link: link,
title_link_download: hasDownload,
collapsed,
Expand All @@ -26,7 +22,6 @@ const VideoAttachment = ({

return (
<>
{descriptionMd ? <MessageContentBody md={descriptionMd} /> : <MarkdownText parseEmoji content={description} />}
<MessageCollapsible title={title} hasDownload={hasDownload} link={getURL(link || url)} size={size} isCollapsed={collapsed}>
<MessageGenericPreview style={{ maxWidth: 368, width: '100%' }}>
<Box is='video' controls preload='metadata' ref={mediaRef}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type { MessageActionConfig } from '../../../../app/ui-utils/client/lib/Me

const getMainMessageText = (message: IMessage): IMessage => {
const newMessage = { ...message };
newMessage.msg = newMessage.msg || newMessage.attachments?.[0]?.description || newMessage.attachments?.[0]?.title || '';
newMessage.md = newMessage.md || newMessage.attachments?.[0]?.descriptionMd || undefined;
newMessage.msg = newMessage.msg || newMessage.attachments?.[0]?.title || '';
newMessage.md = newMessage.md || undefined;
return { ...newMessage };
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import ReportMessageModal from '../../../views/room/modals/ReportMessageModal';

const getMainMessageText = (message: IMessage): IMessage => {
const newMessage = { ...message };
newMessage.msg = newMessage.msg || newMessage.attachments?.[0]?.description || newMessage.attachments?.[0]?.title || '';
newMessage.md = newMessage.md || newMessage.attachments?.[0]?.descriptionMd || undefined;
newMessage.msg = newMessage.msg || newMessage.attachments?.[0]?.title || '';
newMessage.md = newMessage.md || undefined;
return { ...newMessage };
};

Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/client/hooks/useDecryptedMessage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('useDecryptedMessage', () => {
it('should handle E2EE messages with attachments', async () => {
(isE2EEMessage as jest.MockedFunction<typeof isE2EEMessage>).mockReturnValue(true);
(e2e.decryptMessage as jest.Mock).mockResolvedValue({
attachments: [{ description: 'Attachment description' }],
attachments: [{ title: 'Attachment title' }],
});
const message = { msg: 'Encrypted message with attachment' };

Expand All @@ -63,7 +63,6 @@ describe('useDecryptedMessage', () => {
expect(result.current).toBe('E2E_message_encrypted_placeholder');
});

expect(result.current).toBe('Attachment description');
expect(e2e.decryptMessage).toHaveBeenCalledWith(message);
});

Expand Down
9 changes: 3 additions & 6 deletions apps/meteor/client/hooks/useDecryptedMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ export const useDecryptedMessage = (message: IMessage): string => {
e2e.decryptMessage(message).then((decryptedMsg) => {
if (decryptedMsg.msg) {
setDecryptedMessage(decryptedMsg.msg);
return;
}

if (decryptedMsg.attachments && decryptedMsg.attachments?.length > 0) {
if (decryptedMsg.attachments[0].description) {
setDecryptedMessage(decryptedMsg.attachments[0].description);
} else {
setDecryptedMessage(t('Message_with_attachment'));
}
if (decryptedMsg.attachments && decryptedMsg.attachments.length > 0) {
setDecryptedMessage(t('Message_with_attachment'));
}
});
}, [message, t, setDecryptedMessage]);
Expand Down
6 changes: 1 addition & 5 deletions apps/meteor/client/lib/normalizeThreadMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ export function normalizeThreadMessage({ ...message }: Readonly<Pick<IMessage, '
}

if (message.attachments) {
const attachment = message.attachments.find((attachment) => attachment.title || attachment.description);

if (attachment?.description) {
return <>{attachment.description}</>;
}
const attachment = message.attachments.find((attachment) => attachment.title);

if (attachment?.title) {
return <>{attachment.title}</>;
Expand Down
Loading
Loading