Skip to content

Commit 9760d84

Browse files
authored
refactor: Remove unused description from attachments render (RocketChat#40067)
1 parent 68927b8 commit 9760d84

File tree

34 files changed

+38
-283
lines changed

34 files changed

+38
-283
lines changed

apps/meteor/app/autotranslate/client/lib/autotranslate.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,6 @@ export const AutoTranslate = {
7070
}
7171
}
7272

73-
if (attachment.description && attachment.translations && attachment.translations[language]) {
74-
attachment.translations.original = attachment.description;
75-
76-
if (autoTranslateShowInverse) {
77-
attachment.description = attachment.translations.original;
78-
} else {
79-
attachment.description = attachment.translations[language];
80-
}
81-
}
82-
8373
// @ts-expect-error - not sure what to do with this
8474
if (attachment.attachments && attachment.attachments.length > 0) {
8575
// @ts-expect-error - not sure what to do with this

apps/meteor/app/autotranslate/server/autotranslate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export abstract class AutoTranslate {
320320
if (message.attachments && message.attachments.length > 0) {
321321
setImmediate(async () => {
322322
for (const [index, attachment] of message.attachments?.entries() ?? []) {
323-
if (attachment.description || attachment.text) {
323+
if (attachment.text) {
324324
// Removes the initial link `[ ](quoterl)` from quote message before translation
325325
const translatedText = attachment?.text?.replace(/\[(.*?)\]\(.*?\)/g, '$1') || attachment?.text;
326326
const attachmentMessage = { ...attachment, text: translatedText };

apps/meteor/app/autotranslate/server/deeplTranslate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class DeeplAutoTranslate extends AutoTranslate {
196196
params: {
197197
auth_key: this.apiKey,
198198
target_lang: language,
199-
text: attachment.description || attachment.text || '',
199+
text: attachment.text || '',
200200
},
201201
});
202202
if (!result.ok) {

apps/meteor/app/autotranslate/server/googleTranslate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class GoogleAutoTranslate extends AutoTranslate {
195195
key: this.apiKey,
196196
target: language,
197197
format: 'text',
198-
q: attachment.description || attachment.text || '',
198+
q: attachment.text || '',
199199
},
200200
});
201201
if (!result.ok) {

apps/meteor/app/autotranslate/server/msTranslate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class MsAutoTranslate extends AutoTranslate {
192192
return this._translate(
193193
[
194194
{
195-
Text: attachment.description || attachment.text || '',
195+
Text: attachment.text || '',
196196
},
197197
],
198198
targetLanguages,

apps/meteor/app/lib/server/functions/notifications/email.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,8 @@ export async function getEmailContent({ message, user, room }) {
7777
}
7878

7979
if (hasFiles) {
80-
const attachments = message.attachments || [];
81-
const fileParts = files.map((file, index) => {
82-
let part = escapeHTML(file.name);
83-
if (attachments[index]?.description) {
84-
part += `<br/><br/>${escapeHTML(attachments[index].description)}`;
85-
}
86-
return part;
80+
const fileParts = files.map((file) => {
81+
return escapeHTML(file.name);
8782
});
8883
contentParts.push(fileParts.join('<br/><br/>'));
8984
}

apps/meteor/app/lib/server/lib/sendNotificationsOnMessage.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ export const sendNotification = async ({
195195
const firstAttachment = message.attachments?.length && message.attachments.shift();
196196

197197
if (firstAttachment) {
198-
firstAttachment.description =
199-
typeof firstAttachment.description === 'string' ? emojione.shortnameToUnicode(firstAttachment.description) : undefined;
200198
firstAttachment.text = typeof firstAttachment.text === 'string' ? emojione.shortnameToUnicode(firstAttachment.text) : undefined;
201199
}
202200

apps/meteor/app/lib/server/methods/updateMessage.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function executeUpdateMessage(
3434
// IF the message has custom fields, always update
3535
// Ideally, we'll compare the custom fields to check for change, but since we don't know the shape of
3636
// custom fields, as it's user defined, we're gonna update
37-
const msgText = originalMessage?.attachments?.[0]?.description ?? originalMessage.msg;
37+
const msgText = originalMessage.msg;
3838
if (msgText === message.msg && !previewUrls && !message.customFields) {
3939
return;
4040
}
@@ -86,13 +86,6 @@ export async function executeUpdateMessage(
8686
}
8787
await canSendMessageAsync(message.rid, { uid: user._id, username: user.username ?? undefined, ...user });
8888

89-
// It is possible to have an empty array as the attachments property, so ensure both things exist
90-
if (originalMessage.attachments && originalMessage.attachments.length > 0 && originalMessage.attachments[0].description !== undefined) {
91-
originalMessage.attachments[0].description = message.msg;
92-
message.attachments = originalMessage.attachments;
93-
message.msg = originalMessage.msg;
94-
}
95-
9689
message.u = originalMessage.u;
9790

9891
return updateMessage(message, user, originalMessage, previewUrls);

apps/meteor/app/livechat/server/lib/sendTranscript.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,14 @@ export async function sendTranscript({
108108

109109
const messageType = MessageTypes.getType(message);
110110

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

116116
let filesHTML = '';
117117

118118
if (message.attachments && message.attachments?.length > 0) {
119-
messageContent = message.attachments[0].description || '';
120-
escapeHtml(messageContent);
121-
122119
for await (const attachment of message.attachments) {
123120
if (!isFileAttachment(attachment)) {
124121
continue;

apps/meteor/app/slackbridge/server/RocketAdapter.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,11 @@ export default class RocketAdapter {
203203

204204
if (rocketMessage.file.name) {
205205
let fileName = rocketMessage.file.name;
206-
let text = rocketMessage.msg;
206+
const text = rocketMessage.msg;
207207

208208
const attachment = this.getMessageAttachment(rocketMessage);
209209
if (attachment) {
210210
fileName = Meteor.absoluteUrl(attachment.title_link);
211-
if (!text) {
212-
text = attachment.description;
213-
}
214211
}
215212

216213
await slack.postMessage(slack.getSlackChannel(rocketMessage.rid), { ...rocketMessage, msg: `${text} ${fileName}` });

0 commit comments

Comments
 (0)