Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix user pills #93

Merged
merged 8 commits into from
Oct 5, 2018
Merged
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
6 changes: 2 additions & 4 deletions lib/BaseSlackHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<https://matrix.to/#/${user_id}|${response.user.name}>`;
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
);
Expand All @@ -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,
`<https://matrix.to/#/${user_id}|${name}>`
);
Expand Down
25 changes: 10 additions & 15 deletions lib/BridgedRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
}
});
}
Expand Down
2 changes: 0 additions & 2 deletions lib/SlackEventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 7 additions & 6 deletions lib/SlackGhost.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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(() => {
Expand Down
1 change: 0 additions & 1 deletion lib/SlackHookHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down