Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Adding support for the new field for team_name in the post mentions (#…
Browse files Browse the repository at this point in the history
…5152)

Co-authored-by: mattermod <[email protected]>
  • Loading branch information
jespino and mattermod committed Apr 22, 2020
1 parent 26e2c13 commit c5c3722
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 16 additions & 6 deletions utils/text_formatting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const htmlEmojiPattern = /^<p>\s*(?:<img class="emoticon"[^>]*>|<span data-emoti
export type ChannelNamesMap = {
[name: string]: {
display_name: string;
team_name: string;
};
};

Expand Down Expand Up @@ -370,19 +371,26 @@ function autolinkChannelMentions(
function channelMentionExists(c: string) {
return Boolean(channelNamesMap[c]);
}
function addToken(channelName: string, mention: string, displayName: string) {
function addToken(channelName: string, teamName: string, mention: string, displayName: string) {
const index = tokens.size;
const alias = `$MM_CHANNELMENTION${index}$`;
let href = '#';
if (team) {
if (teamName) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
href = ((window as any).basename || '') + '/' + teamName + '/channels/' + channelName;
tokens.set(alias, {
value: `<a class="mention-link" href="${href}" data-channel-mention-team="${teamName}" "data-channel-mention="${channelName}">~${displayName}</a>`,
originalText: mention,
});
} else if (team) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
href = ((window as any).basename || '') + '/' + team.name + '/channels/' + channelName;
tokens.set(alias, {
value: `<a class="mention-link" href="${href}" data-channel-mention="${channelName}">~${displayName}</a>`,
originalText: mention,
});
}

tokens.set(alias, {
value: `<a class="mention-link" href="${href}" data-channel-mention="${channelName}">~${displayName}</a>`,
originalText: mention,
});
return alias;
}

Expand All @@ -397,6 +405,7 @@ function autolinkChannelMentions(
// Exact match
const alias = addToken(
channelNameLower,
channelNamesMap[channelNameLower].team_name,
mention,
escapeHtml(channelNamesMap[channelNameLower].display_name)
);
Expand All @@ -414,6 +423,7 @@ function autolinkChannelMentions(
const suffix = originalChannelName.substr(c - 1);
const alias = addToken(
channelNameLower,
channelNamesMap[channelNameLower].team_name,
'~' + channelNameLower,
escapeHtml(channelNamesMap[channelNameLower].display_name)
);
Expand Down
4 changes: 4 additions & 0 deletions utils/utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,7 @@ export function handleFormattedTextClick(e, currentRelativeTeamUrl) {
const hashtagAttribute = e.target.getAttributeNode('data-hashtag');
const linkAttribute = e.target.getAttributeNode('data-link');
const channelMentionAttribute = e.target.getAttributeNode('data-channel-mention');
const channelMentionTeamAttribute = e.target.getAttributeNode('data-channel-mention-team');

if (hashtagAttribute) {
e.preventDefault();
Expand All @@ -1606,6 +1607,9 @@ export function handleFormattedTextClick(e, currentRelativeTeamUrl) {

browserHistory.push(linkAttribute.value);
}
} else if (channelMentionAttribute && channelMentionTeamAttribute) {
e.preventDefault();
browserHistory.push(channelMentionTeamAttribute + '/channels/' + channelMentionAttribute.value);
} else if (channelMentionAttribute) {
e.preventDefault();
browserHistory.push(currentRelativeTeamUrl + '/channels/' + channelMentionAttribute.value);
Expand Down

0 comments on commit c5c3722

Please sign in to comment.