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

Adding support for the new field for team_name in the post mentions #5152

Merged
merged 2 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1592,6 +1592,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 @@ -1605,6 +1606,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