Chatwoot/app/javascript/shared/helpers/MessageFormatter.js
Pranav Raj S f78df91dd2
Chore: Contact Sidebar, conversation cleanup (#908)
- 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>
2020-06-02 22:59:02 +05:30

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;