summaryrefslogtreecommitdiffstats
path: root/web/react/utils
diff options
context:
space:
mode:
Diffstat (limited to 'web/react/utils')
-rw-r--r--web/react/utils/channel_intro_messages.jsx2
-rw-r--r--web/react/utils/utils.jsx67
2 files changed, 26 insertions, 43 deletions
diff --git a/web/react/utils/channel_intro_messages.jsx b/web/react/utils/channel_intro_messages.jsx
index 79e58147f..ed94f94b8 100644
--- a/web/react/utils/channel_intro_messages.jsx
+++ b/web/react/utils/channel_intro_messages.jsx
@@ -47,7 +47,7 @@ export function createDMIntroMessage(channel) {
</div>
<div className='channel-intro-profile'>
<strong>
- <UserProfile userId={teammate.id}/>
+ <UserProfile user={teammate}/>
</strong>
</div>
<p className='channel-intro-text'>
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index a4d2515e2..38516fae2 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -19,7 +19,7 @@ import {FormattedTime} from 'mm-intl';
export function isEmail(email) {
// writing a regex to match all valid email addresses is really, really hard (see http://stackoverflow.com/a/201378)
// so we just do a simple check and rely on a verification email to tell if it's a real address
- return email.indexOf('@') !== -1;
+ return (/^.+@.+$/).test(email);
}
export function cleanUpUrlable(input) {
@@ -313,41 +313,17 @@ export function getTimestamp() {
// extracts links not styled by Markdown
export function extractLinks(text) {
const links = [];
- let replaceText = text;
-
- // pull out the Markdown code blocks
- const codeBlocks = [];
- const splitText = replaceText.split('`'); // also handles ```
- for (let i = 1; i < splitText.length; i += 2) {
- if (splitText[i].trim() !== '') {
- codeBlocks.push(splitText[i]);
- }
- }
+ let inText = text;
+
+ // strip out code blocks
+ inText = inText.replace(/`[^`]*`/g, '');
+
+ // strip out inline markdown images
+ inText = inText.replace(/!\[[^\]]*\]\([^\)]*\)/g, '');
function replaceFn(autolinker, match) {
let link = '';
const matchText = match.getMatchedText();
- const tempText = replaceText;
-
- const start = replaceText.indexOf(matchText);
- const end = start + matchText.length;
-
- replaceText = replaceText.substring(0, start) + replaceText.substring(end);
-
- // if it's a Markdown link, just skip it
- if (start > 1) {
- if (tempText.charAt(start - 2) === ']' && tempText.charAt(start - 1) === '(' && tempText.charAt(end) === ')') {
- return;
- }
- }
-
- // if it's in a Markdown code block, skip it
- for (const i in codeBlocks) {
- if (codeBlocks[i].indexOf(matchText) === 0) {
- codeBlocks[i] = codeBlocks[i].replace(matchText, '');
- return;
- }
- }
if (matchText.trim().indexOf('http') === 0) {
link = matchText;
@@ -358,16 +334,19 @@ export function extractLinks(text) {
links.push(link);
}
- Autolinker.link(text, {
- replaceFn,
- urls: {schemeMatches: true, wwwMatches: true, tldMatches: false},
- emails: false,
- twitter: false,
- phone: false,
- hashtag: false
- });
+ Autolinker.link(
+ inText,
+ {
+ replaceFn,
+ urls: {schemeMatches: true, wwwMatches: true, tldMatches: false},
+ emails: false,
+ twitter: false,
+ phone: false,
+ hashtag: false
+ }
+ );
- return {links, text};
+ return links;
}
export function escapeRegExp(string) {
@@ -758,7 +737,7 @@ export function applyTheme(theme) {
changeCss('.post:hover, .modal .more-table tbody>tr:hover td, .settings-modal .settings-table .settings-content .section-min:hover', 'background:' + changeOpacity(theme.centerChannelColor, 0.07), 1);
changeCss('.date-separator.hovered--before:after, .date-separator.hovered--after:before, .new-separator.hovered--after:before, .new-separator.hovered--before:after', 'background:' + changeOpacity(theme.centerChannelColor, 0.07), 1);
changeCss('.command-name:hover, .mentions-name:hover, .suggestion--selected, .dropdown-menu>li>a:focus, .dropdown-menu>li>a:hover, .bot-indicator', 'background:' + changeOpacity(theme.centerChannelColor, 0.15), 1);
- changeCss('code', 'background:' + changeOpacity(theme.centerChannelColor, 0.1), 1);
+ changeCss('code, .form-control[disabled], .form-control[readonly], fieldset[disabled] .form-control', 'background:' + changeOpacity(theme.centerChannelColor, 0.1), 1);
changeCss('@media(min-width: 960px){.post.current--user:hover .post__body ', 'background: none;', 1);
changeCss('.sidebar--right', 'color:' + theme.centerChannelColor, 2);
changeCss('.search-help-popover .search-autocomplete__item:hover, .settings-modal .settings-table .settings-content .appearance-section .theme-elements__body', 'background:' + changeOpacity(theme.centerChannelColor, 0.05), 1);
@@ -1417,3 +1396,7 @@ export function languages() {
export function isPostEphemeral(post) {
return post.type === Constants.POST_TYPE_EPHEMERAL || post.state === Constants.POST_DELETED;
}
+
+export function getRootId(post) {
+ return post.root_id === '' ? post.id : post.root_id;
+}