diff --git a/.screenshots/0_[Users]_[_users.setAvatar]_should_set_the_avatar_of_the_logged_user_by_a_local_image_(failed).png b/.screenshots/0_[Users]_[_users.setAvatar]_should_set_the_avatar_of_the_logged_user_by_a_local_image_(failed).png
new file mode 100644
index 000000000000..4d8af285564e
Binary files /dev/null and b/.screenshots/0_[Users]_[_users.setAvatar]_should_set_the_avatar_of_the_logged_user_by_a_local_image_(failed).png differ
diff --git a/packages/rocketchat-mentions/lib/Mentions.js b/packages/rocketchat-mentions/lib/Mentions.js
index b9773b847870..3a8e6b7f7799 100644
--- a/packages/rocketchat-mentions/lib/Mentions.js
+++ b/packages/rocketchat-mentions/lib/Mentions.js
@@ -2,6 +2,7 @@
* Mentions is a named function that will process Mentions
* @param {Object} message - The message object
*/
+import { RocketChat } from 'meteor/rocketchat:lib';
import s from 'underscore.string';
export default class {
constructor({ pattern, useRealName, me }) {
@@ -48,14 +49,14 @@ export default class {
return `${ prefix }${ name || `@${ username }` }`;
});
}
- replaceChannels(str, message) {
+ replaceChannels(str, message, externalRoom = undefined) {
// since apostrophe escaped contains # we need to unescape it
return str.replace(/'/g, '\'').replace(this.channelMentionRegex, (match, prefix, name) => {
if (!message.temp && !(message.channels && message.channels.find((c) => c.name === name))) {
return match;
}
-
- return `${ prefix }${ `#${ name }` }`;
+ const room = externalRoom || RocketChat.models.Rooms.findOne({ name });
+ return `${ prefix }${ `#${ name }` }`;
});
}
getUserMentions(str) {
@@ -64,13 +65,13 @@ export default class {
getChannelMentions(str) {
return (str.match(this.channelMentionRegex) || []).map((match) => match.trim());
}
- parse(message) {
+ parse(message, me, externalRoom = undefined) {
let msg = (message && message.html) || '';
if (!msg.trim()) {
return message;
}
msg = this.replaceUsers(msg, message, this.me);
- msg = this.replaceChannels(msg, message, this.me);
+ msg = this.replaceChannels(msg, message, externalRoom);
message.html = msg;
return message;
}
diff --git a/packages/rocketchat-mentions/tests/client.tests.js b/packages/rocketchat-mentions/tests/client.tests.js
index b7fb781ae9dd..4318860ae126 100644
--- a/packages/rocketchat-mentions/tests/client.tests.js
+++ b/packages/rocketchat-mentions/tests/client.tests.js
@@ -259,17 +259,17 @@ describe('replace methods', function() {
describe('replaceChannels', () => {
it('should render for #general', () => {
- const result = mention.replaceChannels('#general', message);
- assert.equal('#general', result);
+ const result = mention.replaceChannels('#general', message, { _id: 'GENERAL', name: 'general' });
+ assert.equal('#general', result);
});
const str2 = '#rocket.cat';
it(`should render for ${ str2 }`, () => {
- const result = mention.replaceChannels(str2, message);
- assert.equal(result, `${ str2 }`);
+ const result = mention.replaceChannels(str2, message, { _id: 'rocket.cat', name: 'rocket.cat' });
+ assert.equal(result, `${ str2 }`);
});
it(`should render for "hello ${ str2 }"`, () => {
- const result = mention.replaceChannels(`hello ${ str2 }`, message);
- assert.equal(result, `hello ${ str2 }`);
+ const result = mention.replaceChannels(`hello ${ str2 }`, message, { _id: 'rocket.cat', name: 'rocket.cat' });
+ assert.equal(result, `hello ${ str2 }`);
});
it('should render for unknow/private channel "hello #unknow"', () => {
const result = mention.replaceChannels('hello #unknow', message);
@@ -280,13 +280,13 @@ describe('replace methods', function() {
describe('parse all', () => {
it('should render for #general', () => {
message.html = '#general';
- const result = mention.parse(message, 'me');
- assert.equal('#general', result.html);
+ const result = mention.parse(message, 'me', { _id: 'GENERAL', name: 'general' });
+ assert.equal('#general', result.html);
});
it('should render for "#general and @rocket.cat', () => {
message.html = '#general and @rocket.cat';
- const result = mention.parse(message, 'me');
- assert.equal('#general and @rocket.cat', result.html);
+ const result = mention.parse(message, 'me', { _id: 'GENERAL', name: 'general' });
+ assert.equal('#general and @rocket.cat', result.html);
});
it('should render for "', () => {
message.html = '';
@@ -306,13 +306,13 @@ describe('replace methods', function() {
});
it('should render for #general', () => {
message.html = '#general';
- const result = mention.parse(message, 'me');
- assert.equal('#general', result.html);
+ const result = mention.parse(message, 'me', { _id: 'GENERAL', name: 'general' });
+ assert.equal('#general', result.html);
});
it('should render for "#general and @rocket.cat', () => {
message.html = '#general and @rocket.cat';
- const result = mention.parse(message, 'me');
- assert.equal('#general and Rocket.Cat', result.html);
+ const result = mention.parse(message, 'me', { _id: 'GENERAL', name: 'general' });
+ assert.equal('#general and Rocket.Cat', result.html);
});
it('should render for "', () => {
message.html = '';
diff --git a/packages/rocketchat-ui/client/views/app/room.js b/packages/rocketchat-ui/client/views/app/room.js
index 852250c49654..80abe02ef4ca 100644
--- a/packages/rocketchat-ui/client/views/app/room.js
+++ b/packages/rocketchat-ui/client/views/app/room.js
@@ -718,12 +718,13 @@ Template.room.events({
return;
}
const channel = $(e.currentTarget).data('channel');
+ const room = Rooms.findOne({ _id: channel });
if (channel != null) {
if (Layout.isEmbedded()) {
- fireGlobalEvent('click-mention-link', { path: FlowRouter.path('channel', { name: channel }), channel });
+ fireGlobalEvent('click-mention-link', { path: FlowRouter.path('channel', { name: room.name }), channel });
}
- FlowRouter.go('channel', { name: channel }, FlowRouter.current().queryParams);
+ FlowRouter.go('channel', { name: room.name }, FlowRouter.current().queryParams);
return;
}