fixe chat message

This commit is contained in:
Peter Maquiran
2023-06-29 16:04:44 +01:00
parent 8c02c5abb8
commit 246ea2e4a6
16 changed files with 356 additions and 227 deletions
@@ -120,11 +120,14 @@
<div (click)="openPreview(msg)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<div *ngIf="!msg.attachments[0].image_url">
<ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button">
<ion-icon *ngIf="msg.attachments[0].type != 'webtrix'" name="document" class="file-icon"></ion-icon>
<ion-icon *ngIf="msg.attachments[0].type == 'webtrix'" src="assets/icon/webtrix.svg" class="file-icon"></ion-icon>
<ion-label>{{file.title}}</ion-label>
<ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon>
<ion-label>{{ file.title}}</ion-label>
<ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="( msg.downloadLoader == true || msg.uploadingFile == true )" class="icon-download" src="assets/gif/theme/{{ThemeService.currentTheme}}/Blocks-loader.svg" slot="end"></ion-icon>
</ion-item>
</div>
<div *ngIf="msg.attachments[0].image_url">
@@ -424,31 +424,11 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
this.ChatSystemService.getGroupRoom(this.roomId).send({})
}
base64toBlob(base64Data, contentType) {
contentType = contentType || '';
var sliceSize = 1024;
var byteCharacters = atob(base64Data);
var bytesLength = byteCharacters.length;
var slicesCount = Math.ceil(bytesLength / sliceSize);
var byteArrays = new Array(slicesCount);
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
var begin = sliceIndex * sliceSize;
var end = Math.min(begin + sliceSize, bytesLength);
var bytes = new Array(end - begin);
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
bytes[i] = byteCharacters[offset].charCodeAt(0);
}
byteArrays[sliceIndex] = new Uint8Array(bytes);
}
return new Blob(byteArrays, { type: contentType });
}
async sendAudio(fileName) {
const roomId = this.roomId
let audioFile;
this.storage.get('recordData').then((recordData) => {
this.storage.get('recordData').then(async (recordData) => {
audioFile = recordData;
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
@@ -461,7 +441,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
//Converting base64 to blob
const encodedData = btoa(this.audioRecorded);
const blob = this.base64toBlob(encodedData, recordData.value.mimeType)
const blob = this.fileService.base64toBlob(encodedData, recordData.value.mimeType)
const formData = new FormData();
formData.append("blobFile", blob);
@@ -477,7 +457,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"title_link_download": true,
"type": "audio"
}],
temporaryData: formData
temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
})
});
@@ -748,7 +731,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"image_url": 'data:image/jpeg;base64,' + file.base64String,
"text": "description",
"title_link_download": false,
}]
}],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
})
}
@@ -776,7 +762,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"text": "description",
"title_link_download": false,
}],
temporaryData: formData
temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
})
}
@@ -864,7 +853,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
"image_url": 'data:image/jpeg;base64,' + file.base64String,
"text": "description",
"title_link_download": false,
}]
}],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
})
}
@@ -882,7 +874,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => {
console.error(error);
})));
const blob = this.base64toBlob(encodedData, file.type)
const blob = this.fileService.base64toBlob(encodedData, file.type)
const formData = new FormData();
@@ -900,7 +892,10 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
// "text": "description",
"title_link_download": false,
}],
temporaryData: formData
temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
})
} else {