|
@@ -1,5 +1,5 @@
|
|
|
//--- Imports ---
|
|
//--- Imports ---
|
|
|
-import { getUserList } from './service/chat.js';
|
|
|
|
|
|
|
+import { getOnlineUserCount, getUserList } from './service/chat.js';
|
|
|
import { getProducts, sendOrder } from './service/product.js';
|
|
import { getProducts, sendOrder } from './service/product.js';
|
|
|
import { login } from './service/auth.js';
|
|
import { login } from './service/auth.js';
|
|
|
import { createGlobalLoader, showGlobalLoader, hideGlobalLoader } from './utils/loader.js';
|
|
import { createGlobalLoader, showGlobalLoader, hideGlobalLoader } from './utils/loader.js';
|
|
@@ -190,8 +190,8 @@ function initializeWebSocket() {
|
|
|
username: chatUserName
|
|
username: chatUserName
|
|
|
}));
|
|
}));
|
|
|
}
|
|
}
|
|
|
- const userNumber = getUserList().then(users => {
|
|
|
|
|
- onlineUsersElement.innerText = `${users.length} Usuario${users.length !== 1 ? 's' : ''} en línea`;
|
|
|
|
|
|
|
+ getOnlineUserCount().then(count => {
|
|
|
|
|
+ onlineUsersElement.innerText = `${count} Usuario${count !== 1 ? 's' : ''} en línea`;
|
|
|
});
|
|
});
|
|
|
chatWebsocket.onmessage = (event) => {
|
|
chatWebsocket.onmessage = (event) => {
|
|
|
const data = JSON.parse(event.data);
|
|
const data = JSON.parse(event.data);
|
|
@@ -200,14 +200,14 @@ function initializeWebSocket() {
|
|
|
}
|
|
}
|
|
|
else if (data.type === "join") {
|
|
else if (data.type === "join") {
|
|
|
newUserInChat(data.username);
|
|
newUserInChat(data.username);
|
|
|
- const userNumber = getUserList().then(users => {
|
|
|
|
|
- onlineUsersElement.innerText = `${users.length} Usuario${users.length !== 1 ? 's' : ''} en línea`;
|
|
|
|
|
|
|
+ getOnlineUserCount().then(count => {
|
|
|
|
|
+ onlineUsersElement.innerText = `${count} Usuario${count !== 1 ? 's' : ''} en línea`;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
else if (data.type === "leave") {
|
|
else if (data.type === "leave") {
|
|
|
userLeftChat(data.username);
|
|
userLeftChat(data.username);
|
|
|
- const userNumber = getUserList().then(users => {
|
|
|
|
|
- onlineUsersElement.innerText = `${users.length} Usuario${users.length !== 1 ? 's' : ''} en línea`;
|
|
|
|
|
|
|
+ getOnlineUserCount().then(count => {
|
|
|
|
|
+ onlineUsersElement.innerText = `${count} Usuario${count !== 1 ? 's' : ''} en línea`;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
else if (data.type === "mentioned") {
|
|
else if (data.type === "mentioned") {
|
|
@@ -235,16 +235,16 @@ async function sendMessage(message) {
|
|
|
username: chatUserName,
|
|
username: chatUserName,
|
|
|
message: message
|
|
message: message
|
|
|
}));
|
|
}));
|
|
|
- let mentions = [];
|
|
|
|
|
|
|
+ let mentions_repeated = [];
|
|
|
await setTimeout(() => {
|
|
await setTimeout(() => {
|
|
|
const mentionRegex = /@([a-zA-Z0-9_]+_mesa\d+|IAKlein)/g;
|
|
const mentionRegex = /@([a-zA-Z0-9_]+_mesa\d+|IAKlein)/g;
|
|
|
const mentions = message.match(mentionRegex);
|
|
const mentions = message.match(mentionRegex);
|
|
|
if (mentions) {
|
|
if (mentions) {
|
|
|
mentions.forEach(mention => {
|
|
mentions.forEach(mention => {
|
|
|
const username = mention.slice(1);
|
|
const username = mention.slice(1);
|
|
|
- const exist = mentions.find(u => u === username);
|
|
|
|
|
|
|
+ const exist = mentions_repeated.find(u => u === username);
|
|
|
if (!exist && username === chatUserName) return; // don't mention myself if multiple mentions
|
|
if (!exist && username === chatUserName) return; // don't mention myself if multiple mentions
|
|
|
- mentions.push(username);
|
|
|
|
|
|
|
+ mentions_repeated.push(username);
|
|
|
if (username === "IAKlein"){
|
|
if (username === "IAKlein"){
|
|
|
sendMessageToAI(message);
|
|
sendMessageToAI(message);
|
|
|
}else {
|
|
}else {
|