fix(chat) - Mention dot doesn't show if mention is preceded by weird … (#12177)

* fix(chat) - Mention dot doesn't show if mention is preceded by weird mention

* fix(chat) - add unit test for chatCard

* fix(chat) - Improve unit test to only mount the wrapper once
This commit is contained in:
Bart Enkelaar
2020-05-09 19:27:20 +02:00
committed by GitHub
parent f7af8ec910
commit 29f6bf7dc6
3 changed files with 65 additions and 26 deletions

View File

@@ -200,7 +200,6 @@
import moment from 'moment';
import cloneDeep from 'lodash/cloneDeep';
import escapeRegExp from 'lodash/escapeRegExp';
import max from 'lodash/max';
import habiticaMarkdown from 'habitica-markdown';
import { mapState } from '@/libs/store';
@@ -245,28 +244,14 @@ export default {
...mapState({ user: 'user.data' }),
isUserMentioned () {
const message = this.msg;
if (message.highlight) return true;
const { user } = this;
if (message.highlight) return message.highlight;
message.highlight = false;
const messageText = message.text.toLowerCase();
const displayName = user.profile.name;
const username = user.auth.local && user.auth.local.username;
const mentioned = max([
messageText.indexOf(username.toLowerCase()),
messageText.indexOf(displayName.toLowerCase()),
]);
if (mentioned === -1) return message.highlight;
const escapedDisplayName = escapeRegExp(displayName);
const escapedUsername = escapeRegExp(username);
const pattern = `@(${escapedUsername}|${escapedDisplayName})(\\b)`;
const precedingChar = messageText.substring(mentioned - 1, mentioned);
if (mentioned === 0 || precedingChar.trim() === '' || precedingChar === '@') {
const regex = new RegExp(pattern, 'i');
message.highlight = regex.test(messageText);
}
const { username } = user.auth.local;
const pattern = `@(${escapeRegExp(displayName)}|${escapeRegExp(username)})(\\b)`;
message.highlight = new RegExp(pattern, 'i').test(message.text);
return message.highlight;
},
@@ -319,11 +304,7 @@ export default {
chatId: message.id,
});
if (!message.likes[this.user._id]) {
message.likes[this.user._id] = true;
} else {
message.likes[this.user._id] = !message.likes[this.user._id];
}
message.likes[this.user._id] = !message.likes[this.user._id];
this.$emit('message-liked', message);
this.$root.$emit('bv::hide::tooltip');