- Change "features/chat" to support listening for new chat messages and storing them, removing that logic from conference.js. - Combine chat.scss and side_toolbar_container.css, and remove unused scss files. Chat is the only side panel so the two concepts have been merged. - Remove direct access to the chat feature from non-react and non-redux flows. - Modify the i18n translate function to take in an options object. By default the option "wait" is set to true, but that causes components to mount after the parent has been notified of an update, which means autoscrolling down to the latest rendered messages does not work. With "wait" set to false, the children will mount and then the parent will trigger componentDidUpdate. - Create react components for chat. Chat is the side panel plus the entiren chat feature. ChatInput is a child of Chat and is used for composing messages. ChatMessage displays one message and extends PureComponent to limit re-renders. - Fix a bug where the toolbar was not showing automatically when chat is closed and a new message is received. - Import react-transition-group to time the animation of the side panel showing/hiding and unmounting the Chat component. This gets around the issue of having to control autofocus if the component were always mounted and visibility toggled, but introduces not being able to store previous scroll state (without additional work or re-work).
68 lines
2.0 KiB
JavaScript
68 lines
2.0 KiB
JavaScript
import { regexes } from './smileys';
|
|
|
|
/**
|
|
* Processes links and smileys in "body".
|
|
*
|
|
* @param {string} body - The message body.
|
|
* @returns {string} Message body with image tags and href tags.
|
|
*/
|
|
export function processReplacements(body) {
|
|
// make links clickable + add smileys
|
|
return smilify(linkify(body));
|
|
}
|
|
|
|
|
|
/**
|
|
* Finds and replaces all links in the links in "body" with an href tag.
|
|
*
|
|
* @param {string} inputText - The message body.
|
|
* @returns {string} The text replaced with HTML tags for links.
|
|
*/
|
|
function linkify(inputText) {
|
|
let replacedText;
|
|
|
|
/* eslint-disable no-useless-escape, max-len */
|
|
|
|
// URLs starting with http://, https://, or ftp://
|
|
const replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
|
|
|
|
replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>');
|
|
|
|
// URLs starting with "www." (without // before it, or it'd re-link the ones done above).
|
|
const replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
|
|
|
|
replacedText = replacedText.replace(replacePattern2, '$1<a href="https://$2" target="_blank" rel="noopener noreferrer">$2</a>');
|
|
|
|
// Change email addresses to mailto: links.
|
|
const replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;
|
|
|
|
replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');
|
|
|
|
/* eslint-enable no-useless-escape */
|
|
|
|
return replacedText;
|
|
}
|
|
|
|
/**
|
|
* Replaces common smiley strings with images.
|
|
*
|
|
* @param {string} body - The message body.
|
|
* @returns {string} Body returned with smiley replaced.
|
|
*/
|
|
function smilify(body) {
|
|
if (!body) {
|
|
return body;
|
|
}
|
|
|
|
let formattedBody = body;
|
|
|
|
for (const smiley in regexes) {
|
|
if (regexes.hasOwnProperty(smiley)) {
|
|
formattedBody = formattedBody.replace(regexes[smiley],
|
|
`<img class="smiley" src="images/smileys/${smiley}.svg">`);
|
|
}
|
|
}
|
|
|
|
return formattedBody;
|
|
}
|