From 25e017da56dd3d4c017742e3dd35fa2ccfcb8d58 Mon Sep 17 00:00:00 2001
From: Rodrigo Nascimento <rodrigoknascimento@gmail.com>
Date: Tue, 4 Aug 2015 13:44:38 -0300
Subject: [PATCH] Parse mentions to channels and add link to room

---
 client/views/app/room.coffee               |  7 +++++++
 packages/rocketchat-mentions/client.coffee | 12 ++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/client/views/app/room.coffee b/client/views/app/room.coffee
index 1c5235befcc..c3b4cb4f6db 100644
--- a/client/views/app/room.coffee
+++ b/client/views/app/room.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'))
 
diff --git a/packages/rocketchat-mentions/client.coffee b/packages/rocketchat-mentions/client.coffee
index d26a678eaf5..74097c073b5 100644
--- a/packages/rocketchat-mentions/client.coffee
+++ b/packages/rocketchat-mentions/client.coffee
@@ -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
 
-- 
GitLab