Skip to content
Snippets Groups Projects
Commit ee302062 authored by Gabriel Engel's avatar Gabriel Engel
Browse files

Merge pull request #816 from gmsecrieru/master

Avoid turning hashtags clickable if not related to channels
parents 3ff55fad 5a640a52
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