a18d54b706
* Chore: Enable file upload for facebook messenger * Chore: Fix attachments * Chore: Fix Specs * Fix ReplyBox file attachment logic * Set default value for message Co-authored-by: Pranav Raj Sreepuram <pranavrajs@gmail.com>
30 lines
659 B
JavaScript
30 lines
659 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;
|