diff --git a/src/app/components/main-chat/single-chat/attachments/attachments.component.html b/src/app/components/main-chat/single-chat/attachments/attachments.component.html index d202528..d69290c 100644 --- a/src/app/components/main-chat/single-chat/attachments/attachments.component.html +++ b/src/app/components/main-chat/single-chat/attachments/attachments.component.html @@ -1,68 +1,61 @@ - -
-
-
-
-
-
- @if (['png', 'jpg', 'jpeg', 'gif'].includes(getFileType(file))) { - image - } @if (['pdf', 'doc', 'txt'].includes(getFileType(file))) { - - image - } @if (['mp3', 'wav', 'wma'].includes(getFileType(file))) { - - }@if (getFileType(file) === 'mp4') { -
- -
- } -
-
-
+@if(imageUrl) { +
+
+ @if (['png', 'jpg', 'jpeg', 'gif'].includes(getFileType(imageUrl))) { + image + } @if (['pdf', 'doc', 'txt'].includes(getFileType(imageUrl))) { + + image + } @if (['mp3', 'wav', 'wma'].includes(getFileType(imageUrl))) { + + }@if (getFileType(imageUrl) === 'mp4') { +
+
+ }
- +
+} 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 13a1eba..193e67f 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 @@ -14,9 +14,12 @@ import { SharedService } from '../../../../service/shared.service'; }) export class AttachmentsComponent { @Input() chatId: string = ''; + @Input() filePath: string = ''; @Input() openOnSecondaryChat: boolean = false; @Input() viewWidth: number = 0; - imageUrl: string = ''; + loadingUrl: string = './../../../assets/img/loading.svg'; + cachedImageUrl: string | null = null; + imageUrl: string | null = ''; constructor( public downloadFilesService: DownloadFilesService, @@ -26,6 +29,22 @@ export class AttachmentsComponent { RESPONSIVE_THRESHOLD = this.sharedService.RESPONSIVE_THRESHOLD; + 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; + } + } + // Type of files: // Img: PNG, GIF, JPG, JPEG // Files: PDF, DOC, TXT diff --git a/src/app/components/main-chat/single-chat/single-chat.component.html b/src/app/components/main-chat/single-chat/single-chat.component.html index cb230ab..3a70fa0 100644 --- a/src/app/components/main-chat/single-chat/single-chat.component.html +++ b/src/app/components/main-chat/single-chat/single-chat.component.html @@ -89,11 +89,14 @@ {{ "single-chat.edit" | translate }} }
+ @if(filePath) { + }
@if (!isPrivatChannel && !openOnSecondaryChat) {
diff --git a/src/app/components/main-chat/single-chat/single-chat.component.ts b/src/app/components/main-chat/single-chat/single-chat.component.ts index f1960e8..e3c8984 100644 --- a/src/app/components/main-chat/single-chat/single-chat.component.ts +++ b/src/app/components/main-chat/single-chat/single-chat.component.ts @@ -54,6 +54,8 @@ export class SingleChatComponent { isMsgEditFormOpen: boolean = false; firstLoadOptionMenu: boolean = false; + filePath: string | undefined = ''; + constructor( public chatService: ChatService, public channelService: ChatService, @@ -61,6 +63,16 @@ export class SingleChatComponent { public downloadFilesService: DownloadFilesService ) {} + ngOnInit() { + this.checkChatHasFiles(); + } + + async checkChatHasFiles() { + this.filePath = await this.downloadFilesService.checkChatHasFiles( + this.chat.id + ); + } + /** * Emits a signal to edit a message. * @param {boolean} variable - The value indicating whether the message edit form should be open or not. diff --git a/src/app/service/download-files.service.ts b/src/app/service/download-files.service.ts index 2b5791e..1691d12 100644 --- a/src/app/service/download-files.service.ts +++ b/src/app/service/download-files.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@angular/core'; import { getDownloadURL, + getMetadata, getStorage, listAll, ref, @@ -22,6 +23,23 @@ 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); + return undefined; + }); + } + /** * Uploads all files and updates the list. * @param {string} docID - The documentId under which the files are to be saved. @@ -67,4 +85,32 @@ export class DownloadFilesService { console.error('Error when retrieving the files:', error); }); } + + checkFiles(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; + } + return; + }) + .catch((error) => { + console.error('Error listing files:', error); + return false; + }); + } + + async downloadFiles(path: string): Promise { + try { + const storage = getStorage(); + const forestRef = ref(storage, path); + const downloadUrl = await getDownloadURL(forestRef); + return downloadUrl; + } catch (error) { + console.error('Error downloading file:', error); + return null; + } + } } diff --git a/src/app/shared/components/header/header.component.html b/src/app/shared/components/header/header.component.html index 7403c90..163f0aa 100644 --- a/src/app/shared/components/header/header.component.html +++ b/src/app/shared/components/header/header.component.html @@ -11,9 +11,11 @@ }
+ @if (viewWidth >= RESPONSIVE_THRESHOLD) {
+ }
@for(i of userService.getCurentUsers(); track i){ diff --git a/src/app/shared/components/header/header.component.scss b/src/app/shared/components/header/header.component.scss index 1b2d807..1efba98 100644 --- a/src/app/shared/components/header/header.component.scss +++ b/src/app/shared/components/header/header.component.scss @@ -122,10 +122,6 @@ header { /*------------- RESPONSIVE -------------*/ @media screen and (max-width: $RESPONSIVE_THRESHOLD) { - .middleSide { - display: none; - } - .rightSide, .leftSide { width: 50vw; diff --git a/src/app/shared/components/header/search-bar/search-bar.component.html b/src/app/shared/components/header/search-bar/search-bar.component.html index 537666c..3c3834c 100644 --- a/src/app/shared/components/header/search-bar/search-bar.component.html +++ b/src/app/shared/components/header/search-bar/search-bar.component.html @@ -1,7 +1,7 @@
+ + + + +