mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
save
This commit is contained in:
@@ -109,7 +109,15 @@
|
||||
<ion-label class="file-title">{{file.title}}</ion-label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="audio-contentainer" *ngIf="msg.file.type == 'application/audio'">
|
||||
<div (click)="audioPreview(msg)" class="audio-contentainer" *ngIf="msg.file.type == 'application/audio' && !file.title_link">
|
||||
<ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button">
|
||||
<ion-icon name="mic-outline" class="file-icon"></ion-icon>
|
||||
<ion-label>{{file.title}}</ion-label>
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon>
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon>
|
||||
</ion-item>
|
||||
</div>
|
||||
<div class="audio-contentainer" *ngIf="msg.file.type == 'application/audio' && file.title_link">
|
||||
<audio [src]="file.title_link|safehtml" preload="metadata" class="flex-grow-1" controls controlsList="nodownload noplaybackrate"></audio>
|
||||
</div>
|
||||
<div class="file-details-optional add-attachment-bg-color">
|
||||
|
||||
@@ -227,6 +227,13 @@
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.chat-icon-download{
|
||||
font-size: 95px;
|
||||
margin: 0 auto;
|
||||
margin-top: 4px;
|
||||
border: 1px solid red;
|
||||
}
|
||||
|
||||
.type-message{
|
||||
display: flex;
|
||||
border: 1px solid #ebebeb;
|
||||
@@ -329,3 +336,8 @@ display: block;
|
||||
.typing ngx-letters-avatar {
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
.div-do-audio{
|
||||
border: 1px solid red !important;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.serv
|
||||
import { WsChatService } from 'src/app/services/chat/ws-chat.service'
|
||||
import { MessageService } from 'src/app/services/chat/message.service';
|
||||
import { AttachmentsService } from 'src/app/services/attachments.service';
|
||||
|
||||
import { CameraService } from 'src/app/services/camera.service';
|
||||
import { FileType } from 'src/app/models/fileType';
|
||||
import { SearchPage } from 'src/app/pages/search/search.page';
|
||||
@@ -270,7 +269,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
|
||||
startRecording() {
|
||||
console.log('Recording');
|
||||
|
||||
if (this.recording) {
|
||||
return;
|
||||
@@ -357,56 +355,69 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.wsChatMethodsService.getDmRoom(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;
|
||||
|
||||
try {
|
||||
|
||||
this.storage.get('recordData').then((recordData) => {
|
||||
// console.log(recordData);
|
||||
audioFile = recordData;
|
||||
if(recordData.value.recordDataBase64.includes('data:audio')){
|
||||
this.audioRecorded = recordData.value.recordDataBase64;
|
||||
}
|
||||
else{
|
||||
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`;
|
||||
}
|
||||
});
|
||||
} catch (error) {}
|
||||
|
||||
this.storage.get('recordData').then((recordData) => {
|
||||
console.log(recordData);
|
||||
audioFile = recordData;
|
||||
if(recordData.value.recordDataBase64.includes('data:audio')){
|
||||
this.audioRecorded = recordData.value.recordDataBase64;
|
||||
}
|
||||
else{
|
||||
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`;
|
||||
}
|
||||
|
||||
//Converting base64 to blob
|
||||
const base64Response = await fetch(this.audioRecorded);
|
||||
const blob = await base64Response.blob();
|
||||
|
||||
const encodedData = btoa(this.audioRecorded);
|
||||
const blob = this.base64toBlob(encodedData, recordData.value.mimeType)
|
||||
console.log(blob)
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
|
||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||
file: {
|
||||
"type": "application/audio",
|
||||
/* "guid": '', */
|
||||
"msDuration":audioFile.value.msDuration,
|
||||
"mimeType":audioFile.value.mimeType,
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName ,
|
||||
"title_link": this.audioRecorded,
|
||||
"title_link_download": true,
|
||||
"type": "audio"
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
this.deleteRecording();
|
||||
|
||||
});
|
||||
this.deleteRecording();
|
||||
}
|
||||
|
||||
deleteMessage(msgId: string, msg:MessageService) {
|
||||
|
||||
deleteMessage(msgId: string, msg:MessageService) {
|
||||
msg.delateStatusFalse()
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId)
|
||||
|
||||
}
|
||||
|
||||
async viewDocument(msg: any, url?: string) {
|
||||
@@ -753,7 +764,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
const roomId = this.roomId
|
||||
|
||||
const file: any = await this.fileService.getFileFromDevice(types);
|
||||
|
||||
|
||||
console.log('Add file', file)
|
||||
/* const imageData = await this.fileToBase64Service.convert(file).then((filee) => {
|
||||
console.log('Add file', filee)
|
||||
@@ -889,42 +900,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
|
||||
downloadFileMsg(msg: MessageService) {
|
||||
console.log('FILE TYPE', msg.file.type)
|
||||
this.downloadFile = "";
|
||||
//if (msg.file.type == "application/img") {
|
||||
this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => {
|
||||
console.log('FILE TYPE 22', msg.file.guid)
|
||||
var name = msg.file.guid;
|
||||
|
||||
if (event.type === HttpEventType.DownloadProgress) {
|
||||
//this.downloadProgess = Math.round((100 * event.loaded) / event.total);
|
||||
console.log('FILE TYPE 33', msg.file.type)
|
||||
} else if (event.type === HttpEventType.Response) {
|
||||
if (msg.file.type == "application/img") {
|
||||
this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
|
||||
} else if (msg.file.type === 'application/pdf') {
|
||||
|
||||
this.downloadFile = event.body;
|
||||
}
|
||||
|
||||
msg.attachments[0] = {
|
||||
image_url: this.downloadFile,
|
||||
name: msg.attachments[0].name,
|
||||
title: msg.attachments[0].title,
|
||||
title_link_download: msg.attachments[0].title_link_download,
|
||||
ts: msg.attachments[0].ts
|
||||
}
|
||||
|
||||
// save the changes to the storage
|
||||
msg.save()
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// }
|
||||
|
||||
msg.downloadFileMsg()
|
||||
}
|
||||
|
||||
_arrayBufferToBase64( buffer ) {
|
||||
@@ -944,6 +920,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
DocumentViewer.viewDocument
|
||||
}
|
||||
|
||||
async audioPreview(msg) {
|
||||
console.log(msg);
|
||||
if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') {
|
||||
this.downloadFileMsg(msg)
|
||||
} else {}
|
||||
}
|
||||
|
||||
async openPreview(msg) {
|
||||
console.log(msg);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user