Skip to content

Commit

Permalink
Added support for thread_broadcast subtype
Browse files Browse the repository at this point in the history
  • Loading branch information
lpilz committed Apr 3, 2020
1 parent 7234412 commit 2e34181
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions app/importer-slack/server/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class SlackImporter extends Base {
});
}

processMessageSubType(message, room, msgDataDefaults, missedTypes) {
processMessageSubType(message, room, msgDataDefaults, missedTypes, slackChannel) {
const ignoreTypes = { bot_add: true, file_comment: true, file_mention: true };

let rocketUser = this.getRocketUserFromUserId(message.user);
Expand Down Expand Up @@ -349,6 +349,38 @@ export class SlackImporter extends Base {
this.uploadFile(details, message.file.url_private_download, rocketUser, room, new Date(parseInt(message.ts.split('.')[0]) * 1000));
}
break;
case 'thread_broadcast':
const user = this.getRocketUserFromUserId(message.user);
const msgObj = {
...msgDataDefaults,
msg: this.convertSlackMessageToRocketChat(message.text),
rid: room._id,
attachments: this.convertMessageAttachments(message.attachments),
u: {
_id: user._id,
username: user.username,
},
};

msgObj.tmid = `slack-${ slackChannel.id }-${ message.thread_ts.replace(/\./g, '-') }`;

if (message.edited) {
msgObj.editedAt = new Date(parseInt(message.edited.ts.split('.')[0]) * 1000);
const editedBy = this.getRocketUserFromUserId(message.edited.user);
if (editedBy) {
msgObj.editedBy = {
_id: editedBy._id,
username: editedBy.username,
};
}
}

try {
insertMessage(this.getRocketUserFromUserId(message.user), msgObj, room, this._anyExistingSlackMessage);
} catch (e) {
this.logger.warn(`Failed to import the message: ${ msgDataDefaults._id }`);
}
break;
default:
if (!missedTypes[message.subtype] && !ignoreTypes[message.subtype]) {
missedTypes[message.subtype] = message;
Expand Down Expand Up @@ -407,7 +439,7 @@ export class SlackImporter extends Base {
}

if (message.subtype) {
this.processMessageSubType(message, room, msgDataDefaults, missedTypes);
this.processMessageSubType(message, room, msgDataDefaults, missedTypes, slackChannel);
} else {
const user = this.getRocketUserFromUserId(message.user);
if (user) {
Expand Down

0 comments on commit 2e34181

Please sign in to comment.