Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/chatty-insects-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes Smarsh integration to support multiple file attachments per message.
33 changes: 28 additions & 5 deletions apps/meteor/app/smarsh-connector/server/functions/generateEml.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { FileProp, MessageAttachment } from '@rocket.chat/core-typings';
import { MessageTypes } from '@rocket.chat/message-types';
import { Messages, SmarshHistory, Users, Rooms } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';
Expand Down Expand Up @@ -25,6 +26,19 @@ function _getLink(attachment: { title_link: string }): string {
return Meteor.absoluteUrl().replace(/\/$/, '') + __meteor_runtime_config__.ROOT_URL_PATH_PREFIX + url;
}

function _processMessageFiles(files: FileProp[], attachments: MessageAttachment[] | undefined): { fileIds: string[]; displayText: string } {
const fileIds = files.map((f) => f._id);

const fileLinks =
attachments
?.filter((a): a is MessageAttachment & { title: string } => 'title' in a && a.title !== undefined)
.map((a) => `${a.title} (${_getLink({ title_link: 'title_link' in a ? a.title_link || '' : '' })})`) || [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.map((a) => `${a.title} (${_getLink({ title_link: 'title_link' in a ? a.title_link || '' : '' })})`) || [];
.map((a) => `${a.title} (${_getLink({ title_link: a.title_link || '' })})`) || [];

:ape_think: was there a reason for the ternary?


const displayText = fileLinks.join(', ');

return { fileIds, displayText };
}

export const generateEml = async (): Promise<void> => {
setImmediate(async () => {
const smarshMissingEmail = settings.get('Smarsh_MissingEmail_Email');
Expand Down Expand Up @@ -93,9 +107,14 @@ export const generateEml = async (): Promise<void> => {
} else {
rows.push(`${message.msg} (${message.t})`);
}
} else if (message.files?.length) {
const fileResult = _processMessageFiles(message.files, message.attachments);
fileResult.fileIds.forEach((id) => data.files.push(id));
rows.push(fileResult.displayText);
} else if (message.file) {
data.files.push(message.file._id);
rows.push(`${message?.attachments?.[0].title} (${_getLink({ title_link: message?.attachments?.[0].title_link || '' })})})`);
const fileResult = _processMessageFiles([message.file], message.attachments);
fileResult.fileIds.forEach((id) => data.files.push(id));
rows.push(fileResult.displayText);
} else if (message.attachments) {
const attaches: string[] = [];
message.attachments.forEach((a) => {
Expand Down Expand Up @@ -123,9 +142,13 @@ export const generateEml = async (): Promise<void> => {
await SmarshHistory.updateOne(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would u b so kind to move this to the model? :please: (or create a task for doing it later)

{ _id: room._id },
{
_id: room._id,
lastRan: date,
lastResult: result,
$set: {
lastRan: date,
lastResult: result,
},
$setOnInsert: {
_id: room._id,
},
},
{ upsert: true },
);
Expand Down
Loading