Merge branch 'master' into PLT-25
Этот коммит содержится в:
@@ -132,7 +132,7 @@ export function getChannel(id) {
|
||||
callTracker['getChannel' + id] = utils.getTimestamp();
|
||||
|
||||
client.getChannel(id,
|
||||
function getChannelSuccess(data, textStatus, xhr) {
|
||||
(data, textStatus, xhr) => {
|
||||
callTracker['getChannel' + id] = 0;
|
||||
|
||||
if (xhr.status === 304 || !data) {
|
||||
@@ -145,7 +145,7 @@ export function getChannel(id) {
|
||||
member: data.member
|
||||
});
|
||||
},
|
||||
function getChannelFailure(err) {
|
||||
(err) => {
|
||||
callTracker['getChannel' + id] = 0;
|
||||
dispatchError(err, 'getChannel');
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ function handleError(methodName, xhr, status, err) {
|
||||
|
||||
if (oldError && oldError.connErrorCount) {
|
||||
errorCount += oldError.connErrorCount;
|
||||
connectError = 'We cannot reach the Mattermost service. The service may be down or misconfigured. Please contact an administrator to make sure the WebSocket port is configured properly.';
|
||||
connectError = 'Please check connection, Mattermost unreachable. If issue persists, ask administrator to check WebSocket port.';
|
||||
}
|
||||
|
||||
e = {message: connectError, connErrorCount: errorCount};
|
||||
|
||||
@@ -98,6 +98,7 @@ module.exports = {
|
||||
POST_LOADING: 'loading',
|
||||
POST_FAILED: 'failed',
|
||||
POST_DELETED: 'deleted',
|
||||
POST_TYPE_JOIN_LEAVE: 'join_leave',
|
||||
RESERVED_TEAM_NAMES: [
|
||||
'www',
|
||||
'web',
|
||||
@@ -132,6 +133,7 @@ module.exports = {
|
||||
OFFLINE_ICON_SVG: "<svg version='1.1' id='Layer_1' xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:cc='http://creativecommons.org/ns#' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:svg='http://www.w3.org/2000/svg' xmlns:sodipodi='http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd' xmlns:inkscape='http://www.inkscape.org/namespaces/inkscape' sodipodi:docname='TRASH_1_4.svg' inkscape:version='0.48.4 r9939' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='12px' height='12px' viewBox='0 0 12 12' enable-background='new 0 0 12 12' xml:space='preserve'><sodipodi:namedview inkscape:cy='139.7898' inkscape:cx='26.358185' inkscape:zoom='1.18' showguides='true' showgrid='false' id='namedview6' guidetolerance='10' gridtolerance='10' objecttolerance='10' borderopacity='1' bordercolor='#666666' pagecolor='#ffffff' inkscape:current-layer='Layer_1' inkscape:window-maximized='1' inkscape:window-y='-8' inkscape:window-x='-8' inkscape:window-height='705' inkscape:window-width='1366' inkscape:guide-bbox='true' inkscape:pageshadow='2' inkscape:pageopacity='0'><sodipodi:guide position='50.036793,85.991376' orientation='1,0' id='guide2986'></sodipodi:guide><sodipodi:guide position='58.426196,66.216355' orientation='0,1' id='guide3047'></sodipodi:guide></sodipodi:namedview><g><g><path fill='#cccccc' d='M6.002,7.143C5.645,7.363,5.167,7.52,4.502,7.52c-2.493,0-2.5-2.02-2.5-2.02S1.029,5.607,0.775,6.004C0.41,6.577,0.15,7.716,0.049,8.545c-0.025,0.145-0.057,0.537-0.05,0.598c0.162,1.295,2.237,2.321,4.375,2.357c0.043,0.001,0.085,0.001,0.127,0.001c0.043,0,0.084,0,0.127-0.001c1.879-0.023,3.793-0.879,4.263-2h-2.89L6.002,7.143L6.002,7.143z M4.501,5.488c1.372,0,2.483-1.117,2.483-2.494c0-1.378-1.111-2.495-2.483-2.495c-1.371,0-2.481,1.117-2.481,2.495C2.02,4.371,3.13,5.488,4.501,5.488z M7.002,6.5v2h5v-2H7.002z'/></g></g></svg>",
|
||||
MENU_ICON: "<svg version='1.1' id='Layer_1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px'width='4px' height='16px' viewBox='0 0 8 32' enable-background='new 0 0 8 32' xml:space='preserve'> <g> <circle cx='4' cy='4.062' r='4'/> <circle cx='4' cy='16' r='4'/> <circle cx='4' cy='28' r='4'/> </g> </svg>",
|
||||
COMMENT_ICON: "<svg version='1.1' id='Layer_2' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px'width='15px' height='15px' viewBox='1 1.5 15 15' enable-background='new 1 1.5 15 15' xml:space='preserve'> <g> <g> <path fill='#211B1B' d='M14,1.5H3c-1.104,0-2,0.896-2,2v8c0,1.104,0.896,2,2,2h1.628l1.884,3l1.866-3H14c1.104,0,2-0.896,2-2v-8 C16,2.396,15.104,1.5,14,1.5z M15,11.5c0,0.553-0.447,1-1,1H8l-1.493,2l-1.504-1.991L5,12.5H3c-0.552,0-1-0.447-1-1v-8 c0-0.552,0.448-1,1-1h11c0.553,0,1,0.448,1,1V11.5z'/> </g> </g> </svg>",
|
||||
UPDATE_TYPING_MS: 5000,
|
||||
THEMES: {
|
||||
default: {
|
||||
type: 'Mattermost',
|
||||
@@ -300,6 +302,13 @@ module.exports = {
|
||||
uiName: 'Mention Highlight Link'
|
||||
}
|
||||
],
|
||||
CODE_THEMES: {
|
||||
github: 'GitHub',
|
||||
solarized_light: 'Solarized light',
|
||||
monokai: 'Monokai',
|
||||
solarized_dark: 'Solarized Dark'
|
||||
},
|
||||
DEFAULT_CODE_THEME: 'github',
|
||||
Preferences: {
|
||||
CATEGORY_DIRECT_CHANNEL_SHOW: 'direct_channel_show',
|
||||
CATEGORY_DISPLAY_SETTINGS: 'display_settings'
|
||||
@@ -313,5 +322,30 @@ module.exports = {
|
||||
ENTER: 13,
|
||||
ESCAPE: 27,
|
||||
SPACE: 32
|
||||
},
|
||||
HighlightedLanguages: {
|
||||
diff: 'Diff',
|
||||
apache: 'Apache',
|
||||
makefile: 'Makefile',
|
||||
http: 'HTTP',
|
||||
json: 'JSON',
|
||||
markdown: 'Markdown',
|
||||
javascript: 'JavaScript',
|
||||
css: 'CSS',
|
||||
nginx: 'nginx',
|
||||
objectivec: 'Objective-C',
|
||||
python: 'Python',
|
||||
xml: 'XML',
|
||||
perl: 'Perl',
|
||||
bash: 'Bash',
|
||||
php: 'PHP',
|
||||
coffeescript: 'CoffeeScript',
|
||||
cs: 'C#',
|
||||
cpp: 'C++',
|
||||
sql: 'SQL',
|
||||
go: 'Go',
|
||||
ruby: 'Ruby',
|
||||
java: 'Java',
|
||||
ini: 'ini'
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,6 +6,34 @@ const Utils = require('./utils.jsx');
|
||||
|
||||
const marked = require('marked');
|
||||
|
||||
const highlightJs = require('highlight.js/lib/highlight.js');
|
||||
const highlightJsDiff = require('highlight.js/lib/languages/diff.js');
|
||||
const highlightJsApache = require('highlight.js/lib/languages/apache.js');
|
||||
const highlightJsMakefile = require('highlight.js/lib/languages/makefile.js');
|
||||
const highlightJsHttp = require('highlight.js/lib/languages/http.js');
|
||||
const highlightJsJson = require('highlight.js/lib/languages/json.js');
|
||||
const highlightJsMarkdown = require('highlight.js/lib/languages/markdown.js');
|
||||
const highlightJsJavascript = require('highlight.js/lib/languages/javascript.js');
|
||||
const highlightJsCss = require('highlight.js/lib/languages/css.js');
|
||||
const highlightJsNginx = require('highlight.js/lib/languages/nginx.js');
|
||||
const highlightJsObjectivec = require('highlight.js/lib/languages/objectivec.js');
|
||||
const highlightJsPython = require('highlight.js/lib/languages/python.js');
|
||||
const highlightJsXml = require('highlight.js/lib/languages/xml.js');
|
||||
const highlightJsPerl = require('highlight.js/lib/languages/perl.js');
|
||||
const highlightJsBash = require('highlight.js/lib/languages/bash.js');
|
||||
const highlightJsPhp = require('highlight.js/lib/languages/php.js');
|
||||
const highlightJsCoffeescript = require('highlight.js/lib/languages/coffeescript.js');
|
||||
const highlightJsCs = require('highlight.js/lib/languages/cs.js');
|
||||
const highlightJsCpp = require('highlight.js/lib/languages/cpp.js');
|
||||
const highlightJsSql = require('highlight.js/lib/languages/sql.js');
|
||||
const highlightJsGo = require('highlight.js/lib/languages/go.js');
|
||||
const highlightJsRuby = require('highlight.js/lib/languages/ruby.js');
|
||||
const highlightJsJava = require('highlight.js/lib/languages/java.js');
|
||||
const highlightJsIni = require('highlight.js/lib/languages/ini.js');
|
||||
|
||||
const Constants = require('../utils/constants.jsx');
|
||||
const HighlightedLanguages = Constants.HighlightedLanguages;
|
||||
|
||||
export class MattermostMarkdownRenderer extends marked.Renderer {
|
||||
constructor(options, formattingOptions = {}) {
|
||||
super(options);
|
||||
@@ -15,6 +43,43 @@ export class MattermostMarkdownRenderer extends marked.Renderer {
|
||||
this.text = this.text.bind(this);
|
||||
|
||||
this.formattingOptions = formattingOptions;
|
||||
|
||||
highlightJs.registerLanguage('diff', highlightJsDiff);
|
||||
highlightJs.registerLanguage('apache', highlightJsApache);
|
||||
highlightJs.registerLanguage('makefile', highlightJsMakefile);
|
||||
highlightJs.registerLanguage('http', highlightJsHttp);
|
||||
highlightJs.registerLanguage('json', highlightJsJson);
|
||||
highlightJs.registerLanguage('markdown', highlightJsMarkdown);
|
||||
highlightJs.registerLanguage('javascript', highlightJsJavascript);
|
||||
highlightJs.registerLanguage('css', highlightJsCss);
|
||||
highlightJs.registerLanguage('nginx', highlightJsNginx);
|
||||
highlightJs.registerLanguage('objectivec', highlightJsObjectivec);
|
||||
highlightJs.registerLanguage('python', highlightJsPython);
|
||||
highlightJs.registerLanguage('xml', highlightJsXml);
|
||||
highlightJs.registerLanguage('perl', highlightJsPerl);
|
||||
highlightJs.registerLanguage('bash', highlightJsBash);
|
||||
highlightJs.registerLanguage('php', highlightJsPhp);
|
||||
highlightJs.registerLanguage('coffeescript', highlightJsCoffeescript);
|
||||
highlightJs.registerLanguage('cs', highlightJsCs);
|
||||
highlightJs.registerLanguage('cpp', highlightJsCpp);
|
||||
highlightJs.registerLanguage('sql', highlightJsSql);
|
||||
highlightJs.registerLanguage('go', highlightJsGo);
|
||||
highlightJs.registerLanguage('ruby', highlightJsRuby);
|
||||
highlightJs.registerLanguage('java', highlightJsJava);
|
||||
highlightJs.registerLanguage('ini', highlightJsIni);
|
||||
}
|
||||
|
||||
code(code, language) {
|
||||
if (!language || highlightJs.listLanguages().indexOf(language) < 0) {
|
||||
let parsed = super.code(code, language);
|
||||
return '<code class="hljs">' + $(parsed).text() + '</code>';
|
||||
}
|
||||
|
||||
let parsed = highlightJs.highlight(language, code);
|
||||
return '<div class="post-body--code">' +
|
||||
'<span class="post-body--code__language">' + HighlightedLanguages[language] + '</span>' +
|
||||
'<code style="white-space: pre;" class="hljs">' + parsed.value + '</code>' +
|
||||
'</div>';
|
||||
}
|
||||
|
||||
br() {
|
||||
|
||||
@@ -91,6 +91,7 @@ export function sanitizeHtml(text) {
|
||||
return output;
|
||||
}
|
||||
|
||||
// Convert URLs into tokens
|
||||
function autolinkUrls(text, tokens) {
|
||||
function replaceUrlWithToken(autolinker, match) {
|
||||
const linkText = match.getMatchedText();
|
||||
@@ -132,27 +133,61 @@ function autolinkUrls(text, tokens) {
|
||||
}
|
||||
|
||||
function autolinkAtMentions(text, tokens) {
|
||||
let output = text;
|
||||
// Return true if provided character is punctuation
|
||||
function isPunctuation(character) {
|
||||
const re = /[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,\-.\/:;<=>?@\[\]^_`{|}~]/g;
|
||||
return re.test(character);
|
||||
}
|
||||
|
||||
// Test if provided text needs to be highlighted, special mention or current user
|
||||
function mentionExists(u) {
|
||||
return (Constants.SPECIAL_MENTIONS.indexOf(u) !== -1 || UserStore.getProfileByUsername(u));
|
||||
}
|
||||
|
||||
function addToken(username, mention, extraText) {
|
||||
const index = tokens.size;
|
||||
const alias = `MM_ATMENTION${index}`;
|
||||
|
||||
tokens.set(alias, {
|
||||
value: `<a class='mention-link' href='#' data-mention='${username}'>${mention}</a>`,
|
||||
originalText: mention,
|
||||
extraText
|
||||
});
|
||||
return alias;
|
||||
}
|
||||
|
||||
function replaceAtMentionWithToken(fullMatch, prefix, mention, username) {
|
||||
const usernameLower = username.toLowerCase();
|
||||
if (Constants.SPECIAL_MENTIONS.indexOf(usernameLower) !== -1 || UserStore.getProfileByUsername(usernameLower)) {
|
||||
const index = tokens.size;
|
||||
const alias = `MM_ATMENTION${index}`;
|
||||
|
||||
tokens.set(alias, {
|
||||
value: `<a class='mention-link' href='#' data-mention='${usernameLower}'>${mention}</a>`,
|
||||
originalText: mention
|
||||
});
|
||||
let usernameLower = username.toLowerCase();
|
||||
|
||||
if (mentionExists(usernameLower)) {
|
||||
// Exact match
|
||||
const alias = addToken(usernameLower, mention, '');
|
||||
return prefix + alias;
|
||||
}
|
||||
|
||||
// Not an exact match, attempt to truncate any punctuation to see if we can find a user
|
||||
const originalUsername = usernameLower;
|
||||
|
||||
for (let c = usernameLower.length; c > 0; c--) {
|
||||
if (isPunctuation(usernameLower[c - 1])) {
|
||||
usernameLower = usernameLower.substring(0, c - 1);
|
||||
|
||||
if (mentionExists(usernameLower)) {
|
||||
const extraText = originalUsername.substr(c - 1);
|
||||
const alias = addToken(usernameLower, '@' + usernameLower, extraText);
|
||||
return prefix + alias;
|
||||
}
|
||||
} else {
|
||||
// If the last character is not punctuation, no point in going any further
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return fullMatch;
|
||||
}
|
||||
|
||||
output = output.replace(/(^|\s)(@([a-z0-9.\-_]*[a-z0-9]))/gi, replaceAtMentionWithToken);
|
||||
|
||||
let output = text;
|
||||
output = output.replace(/(^|\s)(@([a-z0-9.\-_]*))/gi, replaceAtMentionWithToken);
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -169,10 +204,9 @@ function highlightCurrentMentions(text, tokens) {
|
||||
const newAlias = `MM_SELFMENTION${index}`;
|
||||
|
||||
newTokens.set(newAlias, {
|
||||
value: `<span class='mention-highlight'>${alias}</span>`,
|
||||
value: `<span class='mention-highlight'>${alias}</span>` + token.extraText,
|
||||
originalText: token.originalText
|
||||
});
|
||||
|
||||
output = output.replace(alias, newAlias);
|
||||
}
|
||||
}
|
||||
@@ -246,7 +280,7 @@ function highlightSearchTerm(text, tokens, searchTerm) {
|
||||
|
||||
var newTokens = new Map();
|
||||
for (const [alias, token] of tokens) {
|
||||
if (token.originalText === searchTerm) {
|
||||
if (token.originalText.indexOf(searchTerm.replace(/\*$/, '')) > -1) {
|
||||
const index = tokens.size + newTokens.size;
|
||||
const newAlias = `MM_SEARCHTERM${index}`;
|
||||
|
||||
@@ -276,7 +310,7 @@ function highlightSearchTerm(text, tokens, searchTerm) {
|
||||
return prefix + alias;
|
||||
}
|
||||
|
||||
return output.replace(new RegExp(`(^|\\W)(${searchTerm})\\b`, 'gi'), replaceSearchTermWithToken);
|
||||
return output.replace(new RegExp(`()(${searchTerm})`, 'gi'), replaceSearchTermWithToken);
|
||||
}
|
||||
|
||||
function replaceTokens(text, tokens) {
|
||||
|
||||
@@ -20,6 +20,7 @@ export function isEmail(email) {
|
||||
|
||||
export function cleanUpUrlable(input) {
|
||||
var cleaned = input.trim().replace(/-/g, ' ').replace(/[^\w\s]/gi, '').toLowerCase().replace(/\s/g, '-');
|
||||
cleaned = cleaned.replace(/-{2,}/, '-');
|
||||
cleaned = cleaned.replace(/^\-+/, '');
|
||||
cleaned = cleaned.replace(/\-+$/, '');
|
||||
return cleaned;
|
||||
@@ -402,6 +403,11 @@ export function toTitleCase(str) {
|
||||
}
|
||||
|
||||
export function applyTheme(theme) {
|
||||
if (!theme.codeTheme) {
|
||||
theme.codeTheme = Constants.DEFAULT_CODE_THEME;
|
||||
}
|
||||
updateCodeTheme(theme.codeTheme);
|
||||
|
||||
if (theme.sidebarBg) {
|
||||
changeCss('.sidebar--left, .settings-modal .settings-table .settings-links, .sidebar--menu', 'background:' + theme.sidebarBg, 1);
|
||||
}
|
||||
@@ -588,6 +594,27 @@ export function rgb2hex(rgbIn) {
|
||||
return '#' + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
|
||||
}
|
||||
|
||||
export function updateCodeTheme(theme) {
|
||||
const path = '/static/css/highlight/' + theme + '.css';
|
||||
const $link = $('link.code_theme');
|
||||
if (path !== $link.attr('href')) {
|
||||
changeCss('code.hljs', 'visibility: hidden');
|
||||
var xmlHTTP = new XMLHttpRequest();
|
||||
xmlHTTP.open('GET', path, true);
|
||||
xmlHTTP.onload = function onLoad() {
|
||||
$link.attr('href', path);
|
||||
if (isBrowserFirefox()) {
|
||||
$link.one('load', () => {
|
||||
changeCss('code.hljs', 'visibility: visible');
|
||||
});
|
||||
} else {
|
||||
changeCss('code.hljs', 'visibility: visible');
|
||||
}
|
||||
};
|
||||
xmlHTTP.send();
|
||||
}
|
||||
}
|
||||
|
||||
export function placeCaretAtEnd(el) {
|
||||
el.focus();
|
||||
if (typeof window.getSelection != 'undefined' && typeof document.createRange != 'undefined') {
|
||||
|
||||
Ссылка в новой задаче
Block a user