Compare commits
No commits in common. "0bf714061c6ab693d1aaf5efbff147f1f8018732" and "7fe4289f4249c00818b8026afc81170541855f44" have entirely different histories.
0bf714061c
...
7fe4289f42
1069
gitlog.jsonl
1069
gitlog.jsonl
File diff suppressed because it is too large
Load Diff
@ -46,89 +46,6 @@ class ChatInputComponent extends HTMLElement {
|
|||||||
focus() {
|
focus() {
|
||||||
this.textarea.focus();
|
this.textarea.focus();
|
||||||
}
|
}
|
||||||
getAuthors(){
|
|
||||||
const uniqueAuthors = new Set()
|
|
||||||
document.querySelectorAll('div.author').forEach(el=>
|
|
||||||
{
|
|
||||||
uniqueAuthors.add(el.innerText.trim())
|
|
||||||
})
|
|
||||||
|
|
||||||
return Array.from(uniqueAuthors)
|
|
||||||
}
|
|
||||||
extractMentions(text) {
|
|
||||||
const regex = /@([a-zA-Z0-9_]+)/g;
|
|
||||||
const mentions = [];
|
|
||||||
let match;
|
|
||||||
|
|
||||||
while ((match = regex.exec(text)) !== null) {
|
|
||||||
mentions.push(match[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return mentions;
|
|
||||||
}
|
|
||||||
matchMentionsToAuthors(mentions, authors) {
|
|
||||||
return mentions.map(mention => {
|
|
||||||
let closestAuthor = null;
|
|
||||||
let minDistance = Infinity;
|
|
||||||
|
|
||||||
authors.forEach(author => {
|
|
||||||
const distance = this.levenshteinDistance(mention.toLowerCase(), author.toLowerCase());
|
|
||||||
if (distance < minDistance) {
|
|
||||||
minDistance = distance;
|
|
||||||
closestAuthor = author;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return { mention, closestAuthor, distance: minDistance };
|
|
||||||
});
|
|
||||||
}
|
|
||||||
levenshteinDistance(a, b) {
|
|
||||||
const matrix = [];
|
|
||||||
|
|
||||||
// Initialize the first row and column
|
|
||||||
for (let i = 0; i <= b.length; i++) {
|
|
||||||
matrix[i] = [i];
|
|
||||||
}
|
|
||||||
for (let j = 0; j <= a.length; j++) {
|
|
||||||
matrix[0][j] = j;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fill in the matrix
|
|
||||||
for (let i = 1; i <= b.length; i++) {
|
|
||||||
for (let j = 1; j <= a.length; j++) {
|
|
||||||
if (b.charAt(i - 1) === a.charAt(j - 1)) {
|
|
||||||
matrix[i][j] = matrix[i - 1][j - 1];
|
|
||||||
} else {
|
|
||||||
matrix[i][j] = Math.min(
|
|
||||||
matrix[i - 1][j] + 1, // Deletion
|
|
||||||
matrix[i][j - 1] + 1, // Insertion
|
|
||||||
matrix[i - 1][j - 1] + 1 // Substitution
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return matrix[b.length][a.length];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
replaceMentionsWithAuthors(text) {
|
|
||||||
const authors = this.getAuthors();
|
|
||||||
const mentions = this.extractMentions(text);
|
|
||||||
|
|
||||||
const matches = this.matchMentionsToAuthors(mentions, authors);
|
|
||||||
console.info(matches)
|
|
||||||
let updatedText = text;
|
|
||||||
matches.forEach(({ mention, closestAuthor }) => {
|
|
||||||
const mentionRegex = new RegExp(`@${mention}`, 'g');
|
|
||||||
console.info(closestAuthor)
|
|
||||||
updatedText = updatedText.replace(mentionRegex, `@${closestAuthor}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
return updatedText;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async connectedCallback() {
|
async connectedCallback() {
|
||||||
@ -136,7 +53,6 @@ levenshteinDistance(a, b) {
|
|||||||
app.rpc.getUser(null).then((user) => {
|
app.rpc.getUser(null).then((user) => {
|
||||||
this.user=user
|
this.user=user
|
||||||
})
|
})
|
||||||
const me = this;
|
|
||||||
this.liveType = this.getAttribute("live-type") === "true";
|
this.liveType = this.getAttribute("live-type") === "true";
|
||||||
this.liveTypeInterval =
|
this.liveTypeInterval =
|
||||||
parseInt(this.getAttribute("live-type-interval")) || 3;
|
parseInt(this.getAttribute("live-type-interval")) || 3;
|
||||||
@ -186,7 +102,7 @@ levenshteinDistance(a, b) {
|
|||||||
if (e.key === "Enter" && !e.shiftKey) {
|
if (e.key === "Enter" && !e.shiftKey) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const message = me.replaceMentionsWithAuthors(this.value);
|
const message = e.target.value;
|
||||||
this.messageUid = null;
|
this.messageUid = null;
|
||||||
this.value = "";
|
this.value = "";
|
||||||
this.previousValue = "";
|
this.previousValue = "";
|
||||||
@ -276,7 +192,6 @@ levenshteinDistance(a, b) {
|
|||||||
app.rpc &&
|
app.rpc &&
|
||||||
typeof app.rpc.updateMessageText === "function"
|
typeof app.rpc.updateMessageText === "function"
|
||||||
) {
|
) {
|
||||||
this.value = this.replaceMentionsWithAuthors(this.value);
|
|
||||||
app.rpc.updateMessageText(this.messageUid, this.value);
|
app.rpc.updateMessageText(this.messageUid, this.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -257,13 +257,12 @@
|
|||||||
|
|
||||||
const messagesContainer = document.querySelector(".chat-messages");
|
const messagesContainer = document.querySelector(".chat-messages");
|
||||||
lastMessage = messagesContainer.querySelector(".message:last-child");
|
lastMessage = messagesContainer.querySelector(".message:last-child");
|
||||||
const lastElement = messagesContainer.querySelector(".message-list-bottom");
|
|
||||||
const doScrollDownBecauseLastMessageIsVisible = !lastMessage || isElementVisible(lastMessage);
|
const doScrollDownBecauseLastMessageIsVisible = !lastMessage || isElementVisible(lastMessage);
|
||||||
|
|
||||||
const message = document.createElement("div");
|
const message = document.createElement("div");
|
||||||
message.innerHTML = data.html;
|
message.innerHTML = data.html;
|
||||||
message.style.display = display
|
message.style.display = display
|
||||||
document.querySelector(".chat-messages").insertBefore(message.firstChild,lastElement);
|
document.querySelector(".chat-messages").appendChild(message.firstChild);
|
||||||
updateLayout(doScrollDownBecauseLastMessageIsVisible);
|
updateLayout(doScrollDownBecauseLastMessageIsVisible);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
updateLayout(doScrollDownBecauseLastMessageIsVisible)
|
updateLayout(doScrollDownBecauseLastMessageIsVisible)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user