Highlight self-mentions in messages

Signed-off-by: Nikola Forró <nforro@redhat.com>
This commit is contained in:
Nikola Forró
2020-08-04 16:17:26 +02:00
parent a0c609ce76
commit b6ad96da28
2 changed files with 13 additions and 1 deletions

View File

@@ -35,11 +35,18 @@ class Message {
target: '_blank'
}
});
return addNewlines(linked);
const highlighted = this.highlightUsername(linked);
return addNewlines(highlighted);
}
userColor() {
return messageBubbleColorForString(this.author);
}
highlightUsername(message) {
const username = document.getElementById('self-message-author').value;
const pattern = new RegExp('@?' + username.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'gi');
return message.replace(pattern, '<span class="highlighted">$&</span>');
}
}