notif_ok_but_id_ko

This commit is contained in:
Pascal 2025-01-09 15:45:26 +01:00
parent e1ee152fef
commit 0af53f4e27

View File

@ -112,6 +112,15 @@ class ChatElement extends HTMLElement {
window.toggleUserList = this.toggleUserList.bind(this);
window.loadMemberChat = this.loadMemberChat.bind(this);
this.notificationBadge = document.querySelector('.notification-badge');
this.notificationBoard = document.getElementById('notification-board');
this.notificationBell = document.getElementById('notification-bell');
if (!this.notificationBadge || !this.notificationBoard || !this.notificationBell) {
console.error('Notification elements not found');
}
// Initialiser les événements de notification
document.addEventListener('click', (event: Event): void => {
if (this.notificationBoard && this.notificationBoard.style.display === 'block' &&
@ -205,11 +214,18 @@ class ChatElement extends HTMLElement {
// Add notification
private addNotification(memberId: string, message: Message) {
private addNotification(memberId: string, message: any) {
let notificationText = '';
if (message.type === 'file') {
notificationText = `New file from Member ${memberId}: ${message.fileName}`;
} else {
notificationText = `New message from Member ${memberId}: ${message.text}`;
}
// Creating a new notification
const notification = {
memberId,
text: `New message from Member ${memberId}: ${message.text}`,
text: notificationText,
time: message.time
};
@ -457,6 +473,9 @@ class ChatElement extends HTMLElement {
messageStore.addMessage(this.selectedMemberId!, autoReply);
this.messagesMock = messageStore.getMessages();
this.loadMemberChat(this.selectedMemberId!);
// Ajouter la notification UNIQUEMENT pour la réponse reçue
this.addNotification(this.selectedMemberId!, autoReply);
}, 1000);
} catch (error) {
@ -807,7 +826,7 @@ class ChatElement extends HTMLElement {
}
// Send a file
private sendFile(file: File) {
private async sendFile(file: File) {
if (!this.selectedMemberId) return;
const MAX_FILE_SIZE = 5 * 1024 * 1024;
@ -835,6 +854,17 @@ class ChatElement extends HTMLElement {
const fileInput = this.shadowRoot?.querySelector('#file-input') as HTMLInputElement;
if (fileInput) fileInput.value = '';
// Générer la réponse automatique
setTimeout(() => {
const autoReply = this.generateAutoReply(this.selectedMemberId!);
messageStore.addMessage(this.selectedMemberId!, autoReply);
this.messagesMock = messageStore.getMessages();
this.loadMemberChat(this.selectedMemberId!);
// Ajouter la notification UNIQUEMENT pour la réponse reçue
this.addNotification(this.selectedMemberId!, autoReply);
}, 1000);
};
}