-
Notifications
You must be signed in to change notification settings - Fork 72
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
Implement bridging of plain text matrix mentions #99
Conversation
My concern with this as implemented is the potential effect on performance. This matrix-appservice-slack/lib/substitutions.js Lines 248 to 254 in 9975146
block of code is being executed for each message, irrespective of if there is a match or not (this was not the case when matching @ ), which means that this:matrix-appservice-slack/lib/substitutions.js Lines 197 to 210 in 9975146
function, which calls out to room state and the user store is also being hit on each message. I don't know enough about the way the bridge lib handles caching of both the room state store or the user store to know if this is an issue. |
This does also have the downside of being unable to handle the situation where you have two users on slack with the same display name. I guess the only way to semi-guard against this is to do some crazy regex on nicks of the form |
(merged develop to make review easier - don't mind me) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks largely okay to me, but @Half-Shot probably knows what is going on here more than I do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the var
s and one name change, I'm happy :)
lib/SlackGhost.js
Outdated
@@ -3,7 +3,7 @@ | |||
var url = require('url'); | |||
var https = require('https'); | |||
var rp = require('request-promise'); | |||
const Slackdown = require('Slackdown'); | |||
const slackdown = require('Slackdown'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why? :(
lib/BridgedRoom.js
Outdated
substitutions.matrixToSlack(message, this._main).then(body => { | ||
var uri = (this._slack_bot_token) ? "https://slack.com/api/chat.postMessage" : this._slack_webhook_uri; | ||
|
||
var sendMessageParams = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😟
lib/BridgedRoom.js
Outdated
sendMessageParams.headers = { | ||
Authorization: 'Bearer ' + this._slack_bot_token | ||
substitutions.matrixToSlack(message, this._main).then(body => { | ||
var uri = (this._slack_bot_token) ? "https://slack.com/api/chat.postMessage" : this._slack_webhook_uri; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😟
lib/substitutions.js
Outdated
// Note: This slower plainTextSlackMentions call is only used if there is not a pill in the message, | ||
// meaning if we can we use the much simpler pill subs rather than this. | ||
return plainTextSlackMentions(main, string, event.room_id).then(string => { | ||
var ret = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😟
lib/substitutions.js
Outdated
link_names: 1 //This no longer works for nicks but is needed to make @channel work. | ||
}; | ||
if (event.content.msgtype == "m.image" && event.content.url.indexOf("mxc://") === 0) { | ||
var url = main.getUrlForMxc(event.content.url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😟
tests/test-subsitutions.spec.js
Outdated
expect(new_string).toBe("<@U2222>"); | ||
}); | ||
it("replace shortest non-unique", () => { | ||
var new_string = subsitutions.replacementFromDisplayMap("@Stuart", displaymap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😟
tests/test-subsitutions.spec.js
Outdated
expect(new_string).toBe("<@U1111>"); | ||
}); | ||
it("replace longest non-unique", () => { | ||
var new_string = subsitutions.replacementFromDisplayMap("@Stuart Mumford", displaymap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😟
tests/test-subsitutions.spec.js
Outdated
}) | ||
|
||
describe ("Make First Word Map", () => { | ||
var displaymap = {Stuart: "U1111", Cadair: "U2222", "Stuart Mumford": "U3333"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😟
tests/test-subsitutions.spec.js
Outdated
|
||
describe ("Make First Word Map", () => { | ||
var displaymap = {Stuart: "U1111", Cadair: "U2222", "Stuart Mumford": "U3333"} | ||
var expectedfirstwords = {Stuart: [{Stuart: "U1111"}, {"Stuart Mumford": "U3333"}], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😟
tests/test-subsitutions.spec.js
Outdated
var expectedfirstwords = {Stuart: [{Stuart: "U1111"}, {"Stuart Mumford": "U3333"}], | ||
Cadair: [{Cadair: "U2222"}]}; | ||
it("Make the First Word Map", () => { | ||
var firstwords = subsitutions.makeFirstWordMap(displaymap); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😟
Thank you! |
The Slack API removed the ability to just send slack
@Cadair
text and have slack convert it into a mention. This is an attempt to do this substitution automatically in the bridge.I would like to remove the need for the@
here as well, which I have an idea how to do, but I am a little concerned about the performance impacts of all this.This now correctly bridges plain text matrix mentions as slack mentions. This means that all matrix clients should give the correct behaviour on slack, making the bridge truly transparent. 🎉
This also builds on #98 because of many many conflicts.