f78df91dd2
- Update sidebar design - Move every contact data to contacts module - Revert go to next conversation feature - Fix issues with new conversation in action cable - Escape HTML content - Broadcast event when conversation.contact changes. Co-authored-by: Sojan <sojan@pepalo.com>
30 lines
653 B
JavaScript
30 lines
653 B
JavaScript
import { escapeHtml } from './HTMLSanitizer';
|
|
|
|
class MessageFormatter {
|
|
constructor(message) {
|
|
this.message = escapeHtml(message) || '';
|
|
}
|
|
|
|
formatMessage() {
|
|
const linkifiedMessage = this.linkify();
|
|
return linkifiedMessage.replace(/\n/g, '<br>');
|
|
}
|
|
|
|
linkify() {
|
|
if (!this.message) {
|
|
return '';
|
|
}
|
|
const urlRegex = /(https?:\/\/[^\s]+)/g;
|
|
return this.message.replace(
|
|
urlRegex,
|
|
url =>
|
|
`<a rel="noreferrer noopener nofollow" href="${url}" class="link" target="_blank">${url}</a>`
|
|
);
|
|
}
|
|
|
|
get formattedMessage() {
|
|
return this.formatMessage();
|
|
}
|
|
}
|
|
|
|
export default MessageFormatter;
|