Parse mentions to channels and add link to room

pull/401/head
Rodrigo Nascimento 11 years ago
parent 574cb84511
commit 25e017da56
  1. 7
      client/views/app/room.coffee
  2. 12
      packages/rocketchat-mentions/client.coffee

@ -456,6 +456,13 @@ Template.room.events
# $('.input-message-editing').select()
"click .mention-link": (e) ->
channel = $(e.currentTarget).data('channel')
if channel?
channelObj = ChatSubscription.findOne name: channel
if channelObj?
FlowRouter.go 'room', {_id: channelObj.rid}
return
Session.set('flexOpened', true)
Session.set('showUserInfo', $(e.currentTarget).data('username'))

@ -11,6 +11,7 @@ class MentionsClient
mentions = []
message.msg.replace /(?:^|\s|\n)(?:@)([A-Za-z0-9-_.]+)/g, (match, mention) ->
mentions.push mention
if mentions.length isnt 0
mentions = _.unique mentions
mentions = mentions.join('|')
@ -24,6 +25,17 @@ class MentionsClient
return match.replace mention, "<a href=\"\" class=\"mention-link\" data-username=\"#{username}\">#{mention}</a>"
channels = []
message.msg.replace /(?:^|\s|\n)(?:#)([A-Za-z0-9-_.]+)/g, (match, mention) ->
channels.push mention
if channels.length isnt 0
channels = _.unique channels
channels = channels.join('|')
msg = msg.replace new RegExp("(?:^|\\s)(#(#{channels}))(?:\\s|$)", 'g'), (match, mention, channel) ->
return match.replace mention, "<a href=\"\" class=\"mention-link\" data-channel=\"#{channel}\">#{mention}</a>"
message.html = msg
return message

Loading…
Cancel
Save