Fixed mentions.
This commit is contained in:
parent
69352fe0b5
commit
1c1d578db7
@ -70,9 +70,14 @@ class ChatInputComponent extends HTMLElement {
|
|||||||
return mentions.map(mention => {
|
return mentions.map(mention => {
|
||||||
let closestAuthor = null;
|
let closestAuthor = null;
|
||||||
let minDistance = Infinity;
|
let minDistance = Infinity;
|
||||||
|
const lowerMention = mention.toLowerCase();
|
||||||
|
|
||||||
authors.forEach(author => {
|
authors.forEach(author => {
|
||||||
const distance = this.levenshteinDistance(mention.toLowerCase(), author.toLowerCase());
|
const lowerAuthor = author.toLowerCase();
|
||||||
|
const distance = this.levenshteinDistance(lowerMention, lowerAuthor);
|
||||||
|
if(!this.isSubSequence(lowerMention,lowerAuthor)) {
|
||||||
|
distance += 1
|
||||||
|
}
|
||||||
if (distance < minDistance) {
|
if (distance < minDistance) {
|
||||||
minDistance = distance;
|
minDistance = distance;
|
||||||
closestAuthor = author;
|
closestAuthor = author;
|
||||||
@ -252,6 +257,25 @@ levenshteinDistance(a, b) {
|
|||||||
const millisecondsDifference = event2Time.getTime() - event1Time.getTime();
|
const millisecondsDifference = event2Time.getTime() - event1Time.getTime();
|
||||||
return millisecondsDifference / 1000;
|
return millisecondsDifference / 1000;
|
||||||
}
|
}
|
||||||
|
isSubsequence(input, array) {
|
||||||
|
for (const str of array) {
|
||||||
|
let i = 0;
|
||||||
|
let j = 0;
|
||||||
|
|
||||||
|
while (i < input.length && j < str.length) {
|
||||||
|
if (input[i] === str[j]) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i === input.length) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
newMessage() {
|
newMessage() {
|
||||||
if (!this.messageUid) {
|
if (!this.messageUid) {
|
||||||
|
Loading…
Reference in New Issue
Block a user