Fixed mentions.

This commit is contained in:
retoor 2025-05-27 12:06:35 +02:00
parent 69352fe0b5
commit 1c1d578db7

View File

@ -70,9 +70,14 @@ class ChatInputComponent extends HTMLElement {
return mentions.map(mention => {
let closestAuthor = null;
let minDistance = Infinity;
const lowerMention = mention.toLowerCase();
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) {
minDistance = distance;
closestAuthor = author;
@ -252,6 +257,25 @@ levenshteinDistance(a, b) {
const millisecondsDifference = event2Time.getTime() - event1Time.getTime();
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() {
if (!this.messageUid) {