summaryrefslogtreecommitdiffstats
path: root/webapp/utils
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2016-09-30 14:19:00 +0100
committerenahum <nahumhbl@gmail.com>2016-09-30 10:19:00 -0300
commit29a3706ec3c3523ac8bf552c68e675f0c956986c (patch)
treecec4d9c338f3d33d3a17c8d68c2f3a9b0156840b /webapp/utils
parent49c6b42d381e5607a77c6c97761aabd38774b196 (diff)
downloadchat-29a3706ec3c3523ac8bf552c68e675f0c956986c.tar.gz
chat-29a3706ec3c3523ac8bf552c68e675f0c956986c.tar.bz2
chat-29a3706ec3c3523ac8bf552c68e675f0c956986c.zip
PLT-4307 - fix !channel link hrefs. (#4122)
* PLT-4307 - fix !channel link hrefs. * Fix style.
Diffstat (limited to 'webapp/utils')
-rw-r--r--webapp/utils/text_formatting.jsx11
-rw-r--r--webapp/utils/utils.jsx1
2 files changed, 9 insertions, 3 deletions
diff --git a/webapp/utils/text_formatting.jsx b/webapp/utils/text_formatting.jsx
index 2b0633e5c..9834f4b9b 100644
--- a/webapp/utils/text_formatting.jsx
+++ b/webapp/utils/text_formatting.jsx
@@ -28,6 +28,7 @@ const cjkPattern = /[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-
// be handled by a special click handler (Utils.handleFormattedTextClick)
// - channelNamesMap - An object mapping channel display names to channels. If provided, !channel mentions will be replaced with
// links to the relevant channel.
+// - team - The current team.
export function formatText(text, inputOptions) {
let output = text;
@@ -64,7 +65,7 @@ export function doFormatText(text, options) {
}
if (options.channelNamesMap) {
- output = autolinkChannelMentions(output, tokens, options.channelNamesMap);
+ output = autolinkChannelMentions(output, tokens, options.channelNamesMap, options.team);
}
output = autolinkEmails(output, tokens);
@@ -204,16 +205,20 @@ function autolinkAtMentions(text, tokens, usernameMap) {
return output;
}
-function autolinkChannelMentions(text, tokens, channelNamesMap) {
+function autolinkChannelMentions(text, tokens, channelNamesMap, team) {
function channelMentionExists(c) {
return Boolean(channelNamesMap[c]);
}
function addToken(channelName, mention, displayName) {
const index = tokens.size;
const alias = `MM_CHANNELMENTION${index}`;
+ let href = '#';
+ if (team) {
+ href = '/' + team.name + '/channels/' + channelName;
+ }
tokens.set(alias, {
- value: `<a class='mention-link' href='#' data-channel-mention="${channelName}">${displayName}</a>`,
+ value: `<a class='mention-link' href="${href}" data-channel-mention="${channelName}">${displayName}</a>`,
originalText: mention
});
return alias;
diff --git a/webapp/utils/utils.jsx b/webapp/utils/utils.jsx
index ffc676e63..25a9dfa7d 100644
--- a/webapp/utils/utils.jsx
+++ b/webapp/utils/utils.jsx
@@ -1374,6 +1374,7 @@ export function handleFormattedTextClick(e) {
browserHistory.push(linkAttribute.value);
}
} else if (channelMentionAttribute) {
+ e.preventDefault();
browserHistory.push('/' + TeamStore.getCurrent().name + '/channels/' + channelMentionAttribute.value);
}
}