diff --git a/lib/BaseSlackHandler.js b/lib/BaseSlackHandler.js index 5e23e4c7..f3e377bf 100644 --- a/lib/BaseSlackHandler.js +++ b/lib/BaseSlackHandler.js @@ -113,8 +113,7 @@ BaseSlackHandler.prototype.replaceUserIdsWithNames = function(message, token) { if (response && response.user && response.user.name) { log.info("users.info: " + id + " mapped to " + response.user.name); const pill = ``; - message.text = message.text.replace(USER_ID_REGEX_FIRST, response.user.name); - message.markdownText = message.markdownText.replace( + message.text = message.text.replace( USER_ID_REGEX_FIRST, pill ); @@ -134,8 +133,7 @@ BaseSlackHandler.prototype.replaceUserIdsWithNames = function(message, token) { // It's possible not to have a displayname set. name = result[0].display_name || result[0].id; } - message.text = message.text.replace(USER_ID_REGEX_FIRST, name); - message.markdownText = message.markdownText.replace( + message.text = message.text.replace( USER_ID_REGEX_FIRST, `` ); diff --git a/lib/BridgedRoom.js b/lib/BridgedRoom.js index 3c600be6..c554fbdd 100644 --- a/lib/BridgedRoom.js +++ b/lib/BridgedRoom.js @@ -246,25 +246,21 @@ BridgedRoom.prototype._handleSlackMessage = function(message, ghost) { var subtype = message.subtype; - if (!subtype || subtype === "bot_message") { - let text = substitutions.slackToMatrix(message.text); - let markdownText = null; - if (message.markdownText) { - markdownText = substitutions.slackToMatrix(message.markdownText); - } - return ghost.sendText(roomID, text, markdownText); + if (message.text) { + const text = substitutions.slackToMatrix(message.text, + subtype === "file_comment" ? message.file : undefined); + } + + if ([undefined, "bot_message", "file_comment"].includes(subtype)) { + return ghost.sendText(roomID, message.text); } else if (subtype === "me_message") { - var message = { + const message = { msgtype: "m.emote", - body: substitutions.slackToMatrix(message.text) + body: message.text }; return ghost.sendMessage(roomID, message); } - else if (subtype === "file_comment") { - var text = substitutions.slackToMatrix(message.text, message.file); - return ghost.sendText(roomID, text); - } else if (message.files) { for (var i = 0; i < message.files.length; i++) { const file = message.files[i]; @@ -298,8 +294,7 @@ BridgedRoom.prototype._handleSlackMessage = function(message, ghost) { // so we just send a separate `m.image` and `m.text` message // See https://github.com/matrix-org/matrix-doc/issues/906 if (message.text) { - const text = substitutions.slackToMatrix(message.text); - return ghost.sendText(roomID, text); + return ghost.sendText(roomID, message.text); } }); } diff --git a/lib/SlackEventHandler.js b/lib/SlackEventHandler.js index 214363b6..e6721219 100644 --- a/lib/SlackEventHandler.js +++ b/lib/SlackEventHandler.js @@ -205,8 +205,6 @@ SlackEventHandler.prototype.handleMessageEvent = function (params) { result = Promise.resolve(); } - msg.markdownText = msg.text; - return result.then(() => msg) .then((msg) => this.replaceChannelIdsWithNames(msg, token)) .then((msg) => this.replaceUserIdsWithNames(msg, token)) diff --git a/lib/SlackGhost.js b/lib/SlackGhost.js index 27227689..9d6e820c 100644 --- a/lib/SlackGhost.js +++ b/lib/SlackGhost.js @@ -3,7 +3,7 @@ var url = require('url'); var https = require('https'); var rp = require('request-promise'); -var slackdown = require('Slackdown'); +const slackdown = require('Slackdown'); const substitutions = require("./substitutions"); const log = require("matrix-appservice-bridge").Logging.get("SlackGhost"); @@ -157,14 +157,15 @@ SlackGhost.prototype.updateAvatar = function(message, room) { }); }; -SlackGhost.prototype.sendText = function(room_id, text, markdownText=null) { - if (markdownText === null) { - markdownText = text; - } +SlackGhost.prototype.sendText = function(room_id, text) { + // TODO: Slack's markdown is their own thing that isn't really markdown, + // but the only parser we have for it is slackdown. However, Matrix expects + // a variant of markdown that is in the realm of sanity. Currently text + // will be slack's markdown until we've got a slack -> markdown parser. const content = { body: text, msgtype: "m.text", - formatted_body: slackdown.parse(markdownText), + formatted_body: Slackdown.parse(text), format: "org.matrix.custom.html" }; return this.getIntent().sendMessage(room_id, content).then(() => { diff --git a/lib/SlackHookHandler.js b/lib/SlackHookHandler.js index 09313a7a..f7c12d57 100644 --- a/lib/SlackHookHandler.js +++ b/lib/SlackHookHandler.js @@ -237,7 +237,6 @@ SlackHookHandler.prototype.handlePost = function(room, params) { // Restore the original parameters, because we've forgotten a lot of // them by now PRESERVE_KEYS.forEach((k) => msg[k] = params[k]); - msg.markdownText = msg.text; return this.replaceChannelIdsWithNames(msg, token); }).then((msg) => { return this.replaceUserIdsWithNames(msg, token);