diff --git a/src/app/components/main-chat/single-chat/attachments/attachments.component.ts b/src/app/components/main-chat/single-chat/attachments/attachments.component.ts index 193e67f..c1cc2ef 100644 --- a/src/app/components/main-chat/single-chat/attachments/attachments.component.ts +++ b/src/app/components/main-chat/single-chat/attachments/attachments.component.ts @@ -18,7 +18,6 @@ export class AttachmentsComponent { @Input() openOnSecondaryChat: boolean = false; @Input() viewWidth: number = 0; loadingUrl: string = './../../../assets/img/loading.svg'; - cachedImageUrl: string | null = null; imageUrl: string | null = ''; constructor( @@ -31,17 +30,9 @@ export class AttachmentsComponent { async ngOnInit() { if (this.filePath) { - // Überprüfen Sie, ob der Bild-URL bereits im Cache vorhanden ist - if (!this.cachedImageUrl) { - // Wenn nicht, laden Sie ihn herunter und speichern Sie ihn im Cache - this.cachedImageUrl = await this.downloadFilesService.downloadFiles( - this.filePath - ); - console.log('1'); - } - - // Verwenden Sie den gecachten Bild-URL - this.imageUrl = this.cachedImageUrl; + this.imageUrl = await this.downloadFilesService.downloadFiles( + this.filePath + ); } } diff --git a/src/app/service/download-files.service.ts b/src/app/service/download-files.service.ts index 1691d12..fb8d1e9 100644 --- a/src/app/service/download-files.service.ts +++ b/src/app/service/download-files.service.ts @@ -1,7 +1,6 @@ import { Injectable } from '@angular/core'; import { getDownloadURL, - getMetadata, getStorage, listAll, ref, @@ -23,21 +22,21 @@ export class DownloadFilesService { this.listAllFiles(); } - checkChatHasFiles(chatId: string) { - const storage = getStorage(); - const listRef = ref(storage, `chatFiles/${chatId}`); - return listAll(listRef) - .then((result) => { - if (result.items.length > 0) { - return result.items[0].fullPath; - } else { - return undefined; - } - }) - .catch((error) => { - console.error('Error listing files:', error); + async checkChatHasFiles(chatId: string): Promise { + try { + const storage = getStorage(); + const listRef = ref(storage, `chatFiles/${chatId}`); + + const result = await listAll(listRef); + if (result.items.length > 0) { + return result.items[0].fullPath; + } else { return undefined; - }); + } + } catch (error) { + console.error('Error listing files:', error); + return undefined; + } } /** diff --git a/src/app/shared/components/overlay/overlay.component.ts b/src/app/shared/components/overlay/overlay.component.ts index 3fe19d9..c6b302d 100644 --- a/src/app/shared/components/overlay/overlay.component.ts +++ b/src/app/shared/components/overlay/overlay.component.ts @@ -1,8 +1,4 @@ -import { - Component, - HostListener, - OnInit -} from '@angular/core'; +import { Component, HostListener, OnInit } from '@angular/core'; import { OverlayService } from '../../../service/overlay.service'; import { CommonModule } from '@angular/common'; import { SmallBtnComponent } from '../small-btn/small-btn.component'; @@ -19,7 +15,6 @@ export class OverlayComponent implements OnInit { constructor(private overlayService: OverlayService) {} - /** * Initializes the component and subscribes to overlay data changes. */ @@ -29,7 +24,6 @@ export class OverlayComponent implements OnInit { }); } - /** * Extracts the file type from the file name. * @param file The file name. @@ -41,7 +35,6 @@ export class OverlayComponent implements OnInit { return getTag || ''; } - /** * Closes the overlay. */ @@ -49,7 +42,6 @@ export class OverlayComponent implements OnInit { this.overlayData = ''; } - /** * Checks if the contact edit overlay is open and closes it if the click is outside the overlay content. * @param event The mouse event. @@ -59,7 +51,7 @@ export class OverlayComponent implements OnInit { const targetElement = event.target as HTMLElement; if ( !targetElement.closest('.overlayContent') && - !targetElement.closest('.attachments') + !targetElement.closest('.files') ) { this.onCloseOverlay(); }