-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
converted rocketchat-mentions coffee to js #6467
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Mentions is a named function that will process Mentions | ||
* @param {Object} message - The message object | ||
*/ | ||
|
||
const MentionsClient = function MentionsClient(message) { | ||
let msg = message.html; | ||
if (!msg.trim()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this parameter will not be undefined, but... I put a test |
||
return message; | ||
} | ||
const msgMentionRegex = new RegExp(`(?:^|\\s|\\n)(@(${ RocketChat.settings.get('UTF8_Names_Validation') }):?)[:.,\s]?`, 'g'); | ||
|
||
let me = Meteor.user(); | ||
me = me ? me.username : null; | ||
|
||
msg = msg.replace(msgMentionRegex, function(match, mention, username) { | ||
if (['all', 'here'].includes(username)) { | ||
return match.replace(mention, `<a class="mention-link mention-link-me mention-link-all background-attention-color">${ mention }</a>`); | ||
} | ||
if (message.temp == null && _.findWhere(message.mentions, {username}) == null) { | ||
return match; | ||
} | ||
return match.replace(mention, `<a class="mention-link ${ username === me ? 'mention-link-me background-primary-action-color':'' }" data-username="${ username }">${ mention }</a>`); | ||
}); | ||
|
||
const msgChannelRegex = new RegExp(`(?:^|\\s|\\n)(#(${ RocketChat.settings.get('UTF8_Names_Validation') }))[:.,\s]?`, 'g'); | ||
|
||
msg = msg.replace(msgChannelRegex, function(match, mention, name) { | ||
if (message.temp == null && _.findWhere(message.channels, {name}) == null) { | ||
return match; | ||
} | ||
return match.replace(mention, `<a class="mention-link" data-channel="${ name }">${ mention }</a>`); | ||
}); | ||
message.html = msg; | ||
return message; | ||
}; | ||
|
||
|
||
RocketChat.callbacks.add('renderMessage', MentionsClient, RocketChat.callbacks.priority.MEDIUM, 'mentions-message'); | ||
|
||
RocketChat.callbacks.add('renderMentions', MentionsClient, RocketChat.callbacks.priority.MEDIUM, 'mentions-mentions'); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Mentions is a named function that will process Mentions | ||
* @param {Object} message - The message object | ||
*/ | ||
|
||
const MentionsServer = function(message) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use named function instead of var declaration |
||
const msgMentionRegex = new RegExp(`(?:^|\\s|\\n)(?:@)(${ RocketChat.settings.get('UTF8_Names_Validation') })`, 'g'); | ||
const mentionsAll = []; | ||
const userMentions = []; | ||
let mentions = message.msg.match(msgMentionRegex); | ||
if (mentions) { | ||
mentions.forEach((m) => { | ||
const mention = m.trim().substr(1); | ||
if (mention !== 'all' && mention !== 'here') { | ||
return userMentions.push(mention); | ||
} | ||
if (mention === 'all') { | ||
const messageMaxAll = RocketChat.settings.get('Message_MaxAll'); | ||
const allChannel = RocketChat.models.Rooms.findOneById(message.rid); | ||
if (messageMaxAll !== 0 && allChannel.usernames.length >= messageMaxAll) { | ||
return; | ||
} | ||
} | ||
mentionsAll.push({ | ||
_id: mention, | ||
username: mention | ||
}); | ||
}); | ||
mentions = userMentions.length ? Meteor.users.find({ username: {$in: _.unique(userMentions)}}, { fields: {_id: true, username: true }}).fetch() : []; | ||
|
||
const verifiedMentions = [...mentionsAll, ...mentions]; | ||
if (verifiedMentions.length !== 0) { | ||
message.mentions = verifiedMentions; | ||
} | ||
} | ||
|
||
const msgChannelRegex = new RegExp(`(?:^|\\s|\\n)(?:#)(${ RocketChat.settings.get('UTF8_Names_Validation') })`, 'g'); | ||
let channels = message.msg.match(msgChannelRegex); | ||
if (channels) { | ||
channels = channels.map(c => c.trim().substr(1)); | ||
const verifiedChannels = RocketChat.models.Rooms.find({ name: {$in: _.unique(channels)}, t: 'c' }, { fields: {_id: 1, name: 1 }}).fetch(); | ||
if (verifiedChannels.length !== 0) { | ||
message.channels = verifiedChannels; | ||
} | ||
} | ||
return message; | ||
}; | ||
|
||
RocketChat.callbacks.add('beforeSaveMessage', MentionsServer, RocketChat.callbacks.priority.HIGH, 'mentions'); |
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.
Remove the var declaration