diff --git a/src/app/interfaces/search-result.ts b/src/app/interfaces/search-result.ts index 5eb1d15..f2191af 100644 --- a/src/app/interfaces/search-result.ts +++ b/src/app/interfaces/search-result.ts @@ -4,6 +4,7 @@ export interface SearchResult { name: string; avatar: string; message: string; + padNumber: string; userID?: string; channelName?: string; channelID?: string; diff --git a/src/app/main/chat/chat.component.ts b/src/app/main/chat/chat.component.ts index 5f4d789..cf40f21 100644 --- a/src/app/main/chat/chat.component.ts +++ b/src/app/main/chat/chat.component.ts @@ -108,12 +108,12 @@ export class ChatComponent implements AfterViewInit, AfterViewChecked { this.chatService.loadThreadInfo(this.chatService.currentChannelID, messageId); }); } - this.scrollToBottom(); + // this.scrollToBottom(); } ngAfterViewChecked() { - if (this.messagesArrayLength !== this.chatService.currentChannel.messages?.size) - this.scrollToBottom(); + if (this.messagesArrayLength !== this.chatService.currentChannel.messages?.size) {} + // this.scrollToBottom(); } @@ -564,13 +564,15 @@ export class ChatComponent implements AfterViewInit, AfterViewChecked { } scrollToMessage(messageId: string) { - const element = document.getElementById(messageId); - if (element) { - element.scrollIntoView({ behavior: 'smooth', block: 'center' }); - // Optional: Nachricht hervorheben - element.classList.add('highlight'); - setTimeout(() => element.classList.remove('highlight'), 2000); // Entfernt die Hervorhebung nach 2 Sekunden + const messageElement = document.getElementById(messageId) as HTMLElement; + + if (messageElement) { + messageElement.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' }); + console.log('Message element found, using scrollIntoView...'); + } else { + console.error('Message element not found'); } } + } diff --git a/src/app/main/chat/chat.service.ts b/src/app/main/chat/chat.service.ts index c942a9e..d46a86d 100644 --- a/src/app/main/chat/chat.service.ts +++ b/src/app/main/chat/chat.service.ts @@ -90,14 +90,25 @@ export class ChatService { } } - openDirectMessage(user: UsersList) { - this.selectedDirectmessage = user.id; - this.selectedChannel = ""; - this.selectedUser = user; - if (window.matchMedia("(max-width: 768px)").matches) { - this.mobileOpen = "directmessage"; + openDirectMessage(userId: string) { + // Suche den Benutzer mit der passenden userId in der usersList + const user = this.usersList.find(user => user.id === userId); + + // Falls der Benutzer existiert, wird der Chat geöffnet + if (user) { + this.selectedDirectmessage = userId; + this.selectedChannel = ""; + this.selectedUser = user; // Setze den gefundenen Benutzer + + // Überprüfe, ob das Gerät mobil ist und öffne die Direktnachricht + if (window.matchMedia("(max-width: 768px)").matches) { + this.mobileOpen = "directmessage"; + } + } else { + console.error(`User with ID ${userId} not found`); } } + loadChannel(id: string) { const channelRef = this.firestore.channelsRef; const channelDocRef = doc(channelRef, id); diff --git a/src/app/main/chat/direct-message/direct-message.component.html b/src/app/main/chat/direct-message/direct-message.component.html index 7118113..1e8441e 100644 --- a/src/app/main/chat/direct-message/direct-message.component.html +++ b/src/app/main/chat/direct-message/direct-message.component.html @@ -42,7 +42,7 @@

{{ dayDate(message.value.time) }}

'my-message': message.value.id === this.currentUser.currentUser.id, - }"> + }" [id]="message.key">