Skip to content

Commit 84754bb

Browse files
fix: slack importer not importing messages correctly (RocketChat#40053)
1 parent a298a27 commit 84754bb

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

.changeset/mean-mails-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/meteor': patch
3+
---
4+
5+
Fixes Slack messages being incorrectly saved on import

apps/meteor/app/importer/server/classes/converters/MessageConverter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { IImportMessageRecord, IMessage as IDBMessage, IImportMessage, IImportMessageReaction } from '@rocket.chat/core-typings';
22
import { Rooms } from '@rocket.chat/models';
3+
import { removeEmpty } from '@rocket.chat/tools';
34
import limax from 'limax';
45

56
import type { UserIdentification, MentionedChannel } from './ConverterCache';
@@ -84,7 +85,7 @@ export class MessageConverter extends RecordConverter<IImportMessageRecord> {
8485
const mentions = data.mentions && (await this.convertMessageMentions(data));
8586
const channels = data.channels && (await this.convertMessageChannels(data));
8687

87-
return {
88+
return removeEmpty({
8889
rid,
8990
u: {
9091
_id: creator._id,
@@ -110,7 +111,7 @@ export class MessageConverter extends RecordConverter<IImportMessageRecord> {
110111
alias: data.alias,
111112
...(data._id ? { _id: data._id } : {}),
112113
...(data.reactions ? { reactions: await this.convertMessageReactions(data.reactions) } : {}),
113-
};
114+
});
114115
}
115116

116117
protected async convertMessageChannels(message: IImportMessage): Promise<MentionedChannel[] | undefined> {

apps/meteor/tests/unit/app/importer/server/messageConverter.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ describe('Message Converter', () => {
9292
});
9393
});
9494

95+
it('should not have properties with undefined values', async () => {
96+
const converter = new MessageConverter({ workInMemory: true });
97+
98+
const converted = await converter.buildMessageObject(messageToImport, 'general', { _id: 'rocket.cat', username: 'rocket.cat' });
99+
100+
Object.entries(converted).forEach(([key, value]) => {
101+
expect(value, `Property "${key}" should not be undefined`).to.not.be.undefined;
102+
});
103+
});
104+
95105
// #TODO: Validate all message attributes
96106
});
97107

0 commit comments

Comments
 (0)