allow change default values, fix loading search users (#14177)
<!-- INSTRUCTION: Your Pull Request name should start with one of the following tags --> <!-- [NEW] For new features --> <!-- [FIX] For bug fixes --> <!-- [BREAK] For pull requests including breaking changes --> <!-- INSTRUCTION: Inform the issue number that this PR closes, or remove the line below --> <!-- INSTRUCTION: Link to a https://github.com/RocketChat/docs PR with added/updated documentation or an update to the missing/outdated documentation list, see https://rocket.chat/docs/contributing/documentation/ --> <!-- INSTRUCTION: Tell us more about your PR with screen shots if you can -->pull/14214/head
parent
e779a23f48
commit
51e66eaffb
@ -1,61 +1,62 @@ |
||||
import s from 'underscore.string'; |
||||
|
||||
import { Meteor } from 'meteor/meteor'; |
||||
import { Tracker } from 'meteor/tracker'; |
||||
|
||||
import { getUserPreference } from '../../utils'; |
||||
import { callbacks } from '../../callbacks'; |
||||
import { emoji } from '../lib/rocketchat'; |
||||
import { isSetNotNull } from './function-isSet'; |
||||
import s from 'underscore.string'; |
||||
|
||||
/* |
||||
* emojiParser is a function that will replace emojis |
||||
* @param {Object} message - The message object |
||||
*/ |
||||
callbacks.add('renderMessage', (message) => { |
||||
if (isSetNotNull(() => getUserPreference(Meteor.userId(), 'useEmojis')) && |
||||
!getUserPreference(Meteor.userId(), 'useEmojis')) { |
||||
return message; |
||||
|
||||
Tracker.autorun(() => { |
||||
if (!getUserPreference(Meteor.userId(), 'useEmojis')) { |
||||
return callbacks.remove('renderMessage', 'emoji'); |
||||
} |
||||
callbacks.add('renderMessage', (message) => { |
||||
if (s.trim(message.html)) { |
||||
// ' to apostrophe (') for emojis such as :')
|
||||
message.html = message.html.replace(/'/g, '\''); |
||||
|
||||
// '<br>' to ' <br> ' for emojis such at line breaks
|
||||
message.html = message.html.replace(/<br>/g, ' <br> '); |
||||
|
||||
if (s.trim(message.html)) { |
||||
// ' to apostrophe (') for emojis such as :')
|
||||
message.html = message.html.replace(/'/g, '\''); |
||||
message.html = Object.entries(emoji.packages).reduce((value, [, emojiPackage]) => emojiPackage.render(value), message.html); |
||||
|
||||
// '<br>' to ' <br> ' for emojis such at line breaks
|
||||
message.html = message.html.replace(/<br>/g, ' <br> '); |
||||
const checkEmojiOnly = $(`<div>${ message.html }</div>`); |
||||
let emojiOnly = true; |
||||
|
||||
Object.keys(emoji.packages).forEach((emojiPackage) => { |
||||
message.html = emoji.packages[emojiPackage].render(message.html); |
||||
}); |
||||
|
||||
const checkEmojiOnly = $(`<div>${ message.html }</div>`); |
||||
let emojiOnly = true; |
||||
for (const childNode in checkEmojiOnly[0].childNodes) { |
||||
if (checkEmojiOnly[0].childNodes.hasOwnProperty(childNode)) { |
||||
const child = $(checkEmojiOnly[0].childNodes[childNode]); |
||||
for (let i = 0, len = checkEmojiOnly[0].childNodes.length; i < len; i++) { |
||||
const childNode = checkEmojiOnly[0].childNodes[i]; |
||||
|
||||
if (child.hasClass('emoji') || child.hasClass('emojione')) { |
||||
checkEmojiOnly[0].childNodes[childNode] = child.addClass('big'); |
||||
if (childNode.classList && (childNode.classList.contains('emoji') || childNode.classList.contains('emojione'))) { |
||||
childNode.classList.add('big'); |
||||
continue; |
||||
} |
||||
|
||||
if (s.trim(child.text()) === '') { |
||||
if (s.trim(childNode.innerText) === '') { |
||||
continue; |
||||
} |
||||
|
||||
emojiOnly = false; |
||||
break; |
||||
} |
||||
} |
||||
|
||||
if (emojiOnly) { |
||||
message.html = checkEmojiOnly.unwrap().html(); |
||||
} |
||||
if (emojiOnly) { |
||||
message.html = checkEmojiOnly.unwrap().html(); |
||||
} |
||||
|
||||
// apostrophe (') back to '
|
||||
message.html = message.html.replace(/\'/g, '''); |
||||
// apostrophe (') back to '
|
||||
message.html = message.html.replace(/\'/g, '''); |
||||
|
||||
// apostrophe ' <br> ' back to '<br>'
|
||||
message.html = message.html.replace(/ <br> /g, '<br>'); |
||||
} |
||||
// apostrophe ' <br> ' back to '<br>'
|
||||
message.html = message.html.replace(/ <br> /g, '<br>'); |
||||
} |
||||
|
||||
return message; |
||||
}, callbacks.priority.LOW, 'emoji'); |
||||
return message; |
||||
}, callbacks.priority.LOW, 'emoji'); |
||||
}); |
||||
|
@ -1,42 +1,28 @@ |
||||
import s from 'underscore.string'; |
||||
|
||||
export const checkHighlightedWordsInUrls = (msg, highlight) => { |
||||
const urlRegex = new RegExp(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)(${ s.escapeRegExp(highlight) })\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)`, 'gmi'); |
||||
const urlMatches = msg.match(urlRegex); |
||||
|
||||
return urlMatches; |
||||
}; |
||||
export const checkHighlightedWordsInUrls = (msg, urlRegex) => msg.match(urlRegex); |
||||
|
||||
export const removeHighlightedUrls = (msg, highlight, urlMatches) => { |
||||
const highlightRegex = new RegExp(highlight, 'gmi'); |
||||
|
||||
urlMatches.forEach((match) => { |
||||
const highlightRegex = new RegExp(highlight, 'gmi'); |
||||
return urlMatches.reduce((msg, match) => { |
||||
const withTemplate = match.replace(highlightRegex, `<span class="highlight-text">${ highlight }</span>`); |
||||
const regexWithTemplate = new RegExp(withTemplate, 'i'); |
||||
|
||||
msg = msg.replace(regexWithTemplate, match); |
||||
}); |
||||
|
||||
return msg; |
||||
return msg.replace(regexWithTemplate, match); |
||||
}, msg); |
||||
}; |
||||
|
||||
export const highlightWords = (msg, to_highlight) => { |
||||
const highlightTemplate = '$1<span class="highlight-text">$2</span>$3'; |
||||
const highlightTemplate = '$1<span class="highlight-text">$2</span>$3'; |
||||
|
||||
if (Array.isArray(to_highlight)) { |
||||
to_highlight.forEach((highlight) => { |
||||
if (!s.isBlank(highlight)) { |
||||
const regex = new RegExp(`(^|\\b|[\\s\\n\\r\\t.,،'\\\"\\+!?:-])(${ s.escapeRegExp(highlight) })($|\\b|[\\s\\n\\r\\t.,،'\\\"\\+!?:-])(?![^<]*>|[^<>]*<\\/)`, 'gmi'); |
||||
const urlMatches = checkHighlightedWordsInUrls(msg, highlight); |
||||
export const getRegexHighlight = (highlight) => new RegExp(`(^|\\b|[\\s\\n\\r\\t.,،'\\\"\\+!?:-])(${ s.escapeRegExp(highlight) })($|\\b|[\\s\\n\\r\\t.,،'\\\"\\+!?:-])(?![^<]*>|[^<>]*<\\/)`, 'gmi'); |
||||
|
||||
msg = msg.replace(regex, highlightTemplate); |
||||
export const getRegexHighlightUrl = (highlight) => new RegExp(`https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)(${ s.escapeRegExp(highlight) })\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)`, 'gmi'); |
||||
|
||||
if (urlMatches) { |
||||
msg = removeHighlightedUrls(msg, highlight, urlMatches); |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
export const highlightWords = (msg, highlights) => highlights.reduce((msg, { highlight, regex, urlRegex }) => { |
||||
const urlMatches = checkHighlightedWordsInUrls(msg, urlRegex); |
||||
if (!urlMatches) { |
||||
return msg.replace(regex, highlightTemplate); |
||||
|
||||
return msg; |
||||
}; |
||||
} |
||||
return removeHighlightedUrls(msg.replace(regex, highlightTemplate), highlight, urlMatches); |
||||
}, msg); |
||||
|
@ -0,0 +1,6 @@ |
||||
const url = new URL(window.location); |
||||
const keys = new Set(); |
||||
export const getConfig = (key) => { |
||||
keys.add(key); |
||||
return url.searchParams.get(key) || localStorage.getItem(`rc-config-${ key }`); |
||||
}; |
Loading…
Reference in new issue