Skip to content
Snippets Groups Projects
Commit 2be255a4 authored by George Secrieru's avatar George Secrieru
Browse files

Only converting into link the strings starting with a hash (#) that are...

Only converting into link the strings starting with a hash (#) that are currently naming a channel (should close #807)
parent 6c186a56
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,9 @@ class MentionsClient
channels = _.unique channels
channels = channels.join('|')
msg = msg.replace new RegExp("(?:^|\\s|\\n)(#(#{channels}))\\b", 'g'), (match, mention, channel) ->
if not message.temp?
if not _.findWhere(message.channels, {name: channel})?
return match
return match.replace mention, "<a href=\"\" class=\"mention-link\" data-channel=\"#{channel}\">#{mention}</a>"
......
......@@ -23,6 +23,20 @@ class MentionsServer
verifiedMentions.push verifiedMention if verifiedMention?
if verifiedMentions.length isnt 0
message.mentions = verifiedMentions
channels = []
message.msg.replace /(?:^|\s|\n)(?:#)([A-Za-z0-9-_.]+)/g, (match, mention) ->
channels.push mention
if channels.length isnt 0
channels = _.unique channels
verifiedChannels = []
channels.forEach (mention) ->
verifiedChannel = ChatRoom.findOne({ name: mention, t: 'c' }, { fields: {_id: 1, name: 1 } })
verifiedChannels.push verifiedChannel if verifiedChannel?
if verifiedChannels.length isnt 0
message.channels = verifiedChannels
return message
RocketChat.callbacks.add 'beforeSaveMessage', MentionsServer
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment