mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
fix merge
This commit is contained in:
@@ -239,9 +239,9 @@
|
||||
<ion-fab-button title="Nova Reunião" (click)="bookMeeting()" color="light">
|
||||
<ion-icon name="calendar"></ion-icon>
|
||||
</ion-fab-button>
|
||||
<!-- <ion-fab-button title="Adicionar Documento" (click)="addFile()" color="light">
|
||||
<ion-fab-button title="Adicionar Documento" (click)="addFile()" color="light">
|
||||
<ion-icon name="document"></ion-icon>
|
||||
</ion-fab-button> -->
|
||||
</ion-fab-button>
|
||||
<ion-fab-button title="Anexar Fotografia" (click)="addImage()" color="light">
|
||||
<ion-icon name="image"></ion-icon>
|
||||
</ion-fab-button>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Component, OnChanges, OnInit, Input, SimpleChanges, ChangeDetectorRef, Output, EventEmitter, ViewChild, ElementRef, AfterViewChecked, AfterViewInit, OnDestroy } from '@angular/core';
|
||||
import { ActionSheetController, AnimationController, IonSlides, MenuController, ModalController, PopoverController } from '@ionic/angular';
|
||||
import { ActionSheetController, AnimationController, IonSlides, MenuController, ModalController, PopoverController, Platform } from '@ionic/angular';
|
||||
import { AlertService } from 'src/app/services/alert.service';
|
||||
import { AuthService } from 'src/app/services/auth.service';
|
||||
import { ChatService } from 'src/app/services/chat.service';
|
||||
@@ -36,7 +36,10 @@ import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
|
||||
import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder';
|
||||
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { AlertController, Platform, NavParams } from '@ionic/angular';
|
||||
import { AlertController, NavParams } from '@ionic/angular';
|
||||
import { File } from '@awesome-cordova-plugins/file/ngx';
|
||||
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
|
||||
|
||||
|
||||
/*
|
||||
import * as pdfjsLib from 'pdfjs-dist';
|
||||
@@ -95,8 +98,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
allowTyping = true;
|
||||
storedFileNames = [];
|
||||
lastAudioRecorded = '';
|
||||
audioRecorded:any = "";
|
||||
audioDownloaded:any = "";
|
||||
audioRecorded: any = "";
|
||||
audioDownloaded: any = "";
|
||||
durationDisplay = '';
|
||||
duration = 0;
|
||||
|
||||
@@ -124,7 +127,11 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
private CameraService: CameraService,
|
||||
private toastService: ToastService,
|
||||
private sanitiser: DomSanitizer,
|
||||
private alertController: AlertController
|
||||
private alertController: AlertController,
|
||||
private file: File,
|
||||
private platform: Platform,
|
||||
private fileOpener: FileOpener,
|
||||
|
||||
|
||||
) {
|
||||
console.log('OnCONSTRUCTOR');
|
||||
@@ -146,7 +153,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
|
||||
this.showAvatar = false
|
||||
|
||||
setTimeout(()=>{
|
||||
setTimeout(() => {
|
||||
this.scrollToBottomClicked()
|
||||
this.showAvatar = true
|
||||
}, 50)
|
||||
@@ -156,7 +163,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.loggedUser=this.loggedUserChat;
|
||||
this.loggedUser = this.loggedUserChat;
|
||||
setTimeout(() => {
|
||||
this.getRoomInfo();
|
||||
}, 1000);
|
||||
@@ -263,7 +270,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
async getFile(fileName?:any){
|
||||
async getFile(fileName?: any) {
|
||||
const audioFile = await Filesystem.readFile({
|
||||
path: fileName,
|
||||
directory: Directory.Data
|
||||
@@ -281,14 +288,14 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
|
||||
this.storage.get('recordData').then((recordData) => {
|
||||
console.log(recordData);
|
||||
if(recordData?.value?.recordDataBase64.includes('data:audio')){
|
||||
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
|
||||
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`);
|
||||
}
|
||||
});
|
||||
} catch (error) {}
|
||||
} catch (error) { }
|
||||
|
||||
|
||||
}
|
||||
@@ -354,8 +361,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
//console.log(recordData);
|
||||
const fileName = new Date().getTime() + ".mp3";
|
||||
//Save file
|
||||
this.storage.set('fileName',fileName);
|
||||
this.storage.set('recordData',result).then(() => {
|
||||
this.storage.set('fileName', fileName);
|
||||
this.storage.set('recordData', result).then(() => {
|
||||
console.log('Audio recorded saved');
|
||||
})
|
||||
}
|
||||
@@ -463,17 +470,17 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
var byteArrays = new Array(slicesCount);
|
||||
|
||||
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
|
||||
var begin = sliceIndex * sliceSize;
|
||||
var end = Math.min(begin + sliceSize, bytesLength);
|
||||
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);
|
||||
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
|
||||
@@ -481,36 +488,36 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
this.storage.get('recordData').then((recordData) => {
|
||||
console.log(recordData);
|
||||
audioFile = recordData;
|
||||
if(recordData?.value?.recordDataBase64.includes('data:audio')){
|
||||
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
|
||||
this.audioRecorded = recordData?.value?.recordDataBase64;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`;
|
||||
}
|
||||
|
||||
|
||||
//Converting base64 to 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);
|
||||
//Converting base64 to 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.getGroupRoom(roomId).send({
|
||||
file: {
|
||||
"type": "application/audio",
|
||||
"msDuration":audioFile.value.msDuration,
|
||||
"mimeType":audioFile.value.mimeType,
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName ,
|
||||
"title_link_download": true,
|
||||
"type": "audio"
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
this.wsChatMethodsService.getGroupRoom(roomId).send({
|
||||
file: {
|
||||
"type": "application/audio",
|
||||
"msDuration": audioFile.value.msDuration,
|
||||
"mimeType": audioFile.value.mimeType,
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName,
|
||||
"title_link_download": true,
|
||||
"type": "audio"
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
|
||||
});
|
||||
});
|
||||
this.deleteRecording();
|
||||
}
|
||||
|
||||
@@ -761,7 +768,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
//const imageData = await this.fileToBase64Service.convert(file)
|
||||
//console.log('ADDFILECHAT', imageData)
|
||||
|
||||
const response = await fetch('data:image/jpeg;base64,'+ file.base64String!);
|
||||
const response = await fetch('data:image/jpeg;base64,' + file.base64String!);
|
||||
const blob = await response.blob();
|
||||
|
||||
const formData = new FormData();
|
||||
@@ -774,8 +781,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
},
|
||||
temporaryData: formData,
|
||||
attachments: [{
|
||||
"title": file.path ,
|
||||
"image_url": 'data:image/jpeg;base64,' +file.base64String,
|
||||
"title": file.path,
|
||||
"image_url": 'data:image/jpeg;base64,' + file.base64String,
|
||||
"text": "description",
|
||||
"title_link_download": false,
|
||||
}]
|
||||
@@ -789,7 +796,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
const image = await this.CameraService.takePicture();
|
||||
await this.fileService.saveImage(image)
|
||||
const lastphoto: any = await this.fileService.loadFiles();
|
||||
const { capturedImage, capturedImageTitle} = await this.fileService.loadFileData(lastphoto);
|
||||
const { capturedImage, capturedImageTitle } = await this.fileService.loadFileData(lastphoto);
|
||||
|
||||
const base64 = await fetch(capturedImage);
|
||||
const blob = await base64.blob();
|
||||
@@ -802,7 +809,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
"guid": ''
|
||||
},
|
||||
attachments: [{
|
||||
"title": capturedImageTitle ,
|
||||
"title": capturedImageTitle,
|
||||
"image_url": capturedImage,
|
||||
"text": "description",
|
||||
"title_link_download": false,
|
||||
@@ -833,13 +840,13 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
}
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss().then(async res=>{
|
||||
modal.onDidDismiss().then(async res => {
|
||||
const data = res.data;
|
||||
|
||||
if(data.selected) {
|
||||
if (data.selected) {
|
||||
|
||||
this.wsChatMethodsService.getGroupRoom(roomId).send({
|
||||
file:{
|
||||
file: {
|
||||
"name": res.data.selected.Assunto,
|
||||
"type": "application/webtrix",
|
||||
"ApplicationId": res.data.selected.ApplicationType,
|
||||
@@ -865,7 +872,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
}
|
||||
});
|
||||
}
|
||||
async addFileToChatMobile(types: typeof FileType[] ) {
|
||||
async addFileToChatMobile(types: typeof FileType[]) {
|
||||
const roomId = this.roomId
|
||||
|
||||
const file = await Camera.getPhoto({
|
||||
@@ -878,7 +885,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
//const imageData = await this.fileToBase64Service.convert(file)
|
||||
//console.log('ADDFILECHAT', imageData)
|
||||
|
||||
const response = await fetch('data:image/jpeg;base64,'+ file.base64String!);
|
||||
const response = await fetch('data:image/jpeg;base64,' + file.base64String!);
|
||||
const blob = await response.blob();
|
||||
|
||||
const formData = new FormData();
|
||||
@@ -891,8 +898,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
},
|
||||
temporaryData: formData,
|
||||
attachments: [{
|
||||
"title": file.path ,
|
||||
"image_url": 'data:image/jpeg;base64,' +file.base64String,
|
||||
"title": file.path,
|
||||
"image_url": 'data:image/jpeg;base64,' + file.base64String,
|
||||
"text": "description",
|
||||
"title_link_download": false,
|
||||
}]
|
||||
@@ -901,52 +908,63 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
}
|
||||
|
||||
|
||||
async addFileToChat(types: typeof FileType[] ) {
|
||||
async addFileToChat(types: typeof FileType[]) {
|
||||
|
||||
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)
|
||||
}) */
|
||||
const blob = new Blob([file],{type: file.type})
|
||||
console.log('Add file', blob)
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") {
|
||||
|
||||
let pdfBase64;
|
||||
this.blobToBase64(blob).then(res => {
|
||||
console.log('Base64 pdf', res);
|
||||
this.wsChatMethodsService.getGroupRoom(roomId).send({
|
||||
const encodedData = btoa(JSON.stringify(await this.getBase64(file)));
|
||||
const blob = this.base64toBlob(encodedData, file.type)
|
||||
console.log('Add Blob file', blob)
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
|
||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||
file: {
|
||||
"type": file.type,
|
||||
"guid": '',
|
||||
},
|
||||
attachments: [{
|
||||
"title": file.name ,
|
||||
"name": file.name ,
|
||||
"image_url": res,
|
||||
"title": file.name,
|
||||
"name": file.name,
|
||||
//"image_url": res,
|
||||
// "text": "description",
|
||||
"title_link_download": false,
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
});
|
||||
|
||||
} else {
|
||||
console.log('File type invalid')
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
blobToBase64 = blob => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(blob);
|
||||
getFileReader(): FileReader {
|
||||
const fileReader = new FileReader();
|
||||
const zoneOriginalInstance = (fileReader as any)["__zone_symbol__originalInstance"];
|
||||
return zoneOriginalInstance || fileReader;
|
||||
}
|
||||
|
||||
getBase64(file) {
|
||||
var reader = this.getFileReader();
|
||||
reader.readAsDataURL(file);
|
||||
return new Promise(resolve => {
|
||||
reader.onloadend = () => {
|
||||
resolve(reader.result);
|
||||
reader.onload = function () {
|
||||
resolve(reader.result)
|
||||
};
|
||||
reader.onerror = function (error) {
|
||||
console.log('Error: ', error);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
bookMeeting() {
|
||||
let data = {
|
||||
@@ -992,7 +1010,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
}
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss().then( async (res) => {
|
||||
modal.onDidDismiss().then(async (res) => {
|
||||
console.log(res['data']);
|
||||
const roomId = this.roomId;
|
||||
|
||||
@@ -1034,23 +1052,95 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
msg.downloadFileMsg()
|
||||
}
|
||||
|
||||
downloadFileFromBrowser(fileName: string, data: any): void {
|
||||
const linkSource = data;
|
||||
const downloadLink = document.createElement("a");
|
||||
downloadLink.href = linkSource;
|
||||
downloadLink.download = fileName;
|
||||
downloadLink.click();
|
||||
}
|
||||
|
||||
b64toBlob(b64Data, contentType) {
|
||||
contentType = contentType || '';
|
||||
var sliceSize = 512;
|
||||
b64Data = b64Data.replace(/^[^,]+,/, '');
|
||||
b64Data = b64Data.replace(/\s/g, '');
|
||||
var byteCharacters = window.atob(b64Data);
|
||||
var byteArrays = [];
|
||||
|
||||
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
||||
var slice = byteCharacters.slice(offset, offset + sliceSize);
|
||||
|
||||
var byteNumbers = new Array(slice.length);
|
||||
for (var i = 0; i < slice.length; i++) {
|
||||
byteNumbers[i] = slice.charCodeAt(i);
|
||||
}
|
||||
|
||||
var byteArray = new Uint8Array(byteNumbers);
|
||||
|
||||
byteArrays.push(byteArray);
|
||||
}
|
||||
|
||||
var blob = new Blob(byteArrays, { type: contentType });
|
||||
return blob;
|
||||
}
|
||||
|
||||
openFile(pdfString, filename, type) {
|
||||
const blob = this.b64toBlob(pdfString, type)
|
||||
let pathFile = ''
|
||||
const fileName = filename
|
||||
const contentFile = blob
|
||||
if (this.platform.is('ios')) {
|
||||
pathFile = this.file.documentsDirectory
|
||||
} else {
|
||||
pathFile = this.file.externalRootDirectory
|
||||
}
|
||||
console.log(pdfString)
|
||||
console.log(pathFile)
|
||||
console.log(contentFile)
|
||||
this.file
|
||||
.writeFile(pathFile, fileName, contentFile, { replace: true })
|
||||
.then(success => {
|
||||
this.fileOpener
|
||||
.open(pathFile + fileName, type)
|
||||
.then(() => console.log('File is opened'))
|
||||
.catch(e => console.log('Error opening file', e));
|
||||
})
|
||||
.catch(e => console.log('Error writing file', e))
|
||||
}
|
||||
|
||||
async openPreview(msg) {
|
||||
|
||||
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '' ) {
|
||||
this.downloadFileMsg(msg)
|
||||
|
||||
if (msg.file.type === "application/webtrix") {
|
||||
this.viewDocument(msg.file, msg.attachments.image_url)
|
||||
} else {
|
||||
const modal = await this.modalController.create({
|
||||
component: ViewMediaPage,
|
||||
cssClass: 'modal modal-desktop',
|
||||
componentProps: {
|
||||
image: msg.attachments[0].image_url,
|
||||
type: msg.file.type,
|
||||
username: msg.u.name,
|
||||
_updatedAt: msg._updatedAt
|
||||
|
||||
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
|
||||
this.downloadFileMsg(msg)
|
||||
|
||||
} else {
|
||||
|
||||
var str = msg.attachments[0].image_url;
|
||||
str = str.substring(1, ((str.length) - 1));
|
||||
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
this.downloadFileFromBrowser(msg.attachments[0].name, str)
|
||||
} else if (this.platform.is('tablet')) {
|
||||
this.openFile(str, msg.attachments[0].name, msg.file.type);
|
||||
}
|
||||
});
|
||||
modal.present();
|
||||
|
||||
/* const modal = await this.modalController.create({
|
||||
component: ViewMediaPage,
|
||||
cssClass: 'modal modal-desktop',
|
||||
componentProps: {
|
||||
image: str,
|
||||
type: msg.file.type,
|
||||
username: msg.u.name,
|
||||
_updatedAt: msg._updatedAt
|
||||
}
|
||||
});
|
||||
modal.present(); */
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1059,7 +1149,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
console.log(msg);
|
||||
if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') {
|
||||
this.downloadFileMsg(msg)
|
||||
} else {}
|
||||
} else { }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@
|
||||
<fa-icon *ngIf="msg.file.type == 'application/pdf'" icon="file-pdf" class="pdf-icon"></fa-icon>
|
||||
<fa-icon *ngIf="msg.file.type == 'application/word'" icon="file-word" class="word-icon">
|
||||
</fa-icon>
|
||||
<fa-icon *ngIf="msg.file.type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'" icon="file-word" class="word-icon"></fa-icon>
|
||||
<fa-icon
|
||||
*ngIf="msg.file.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'"
|
||||
icon="file-word" class="excel-icon"></fa-icon>
|
||||
@@ -198,9 +199,9 @@
|
||||
<ion-fab-button title="Nova Reunião" (click)="bookMeeting()" color="light">
|
||||
<ion-icon name="calendar"></ion-icon>
|
||||
</ion-fab-button>
|
||||
<!-- <ion-fab-button title="Adicionar Documento" (click)="addFile()" color="light">
|
||||
<ion-fab-button title="Adicionar Documento" (click)="addFile()" color="light">
|
||||
<ion-icon name="document"></ion-icon>
|
||||
</ion-fab-button> -->
|
||||
</ion-fab-button>
|
||||
<ion-fab-button title="Anexar Fotografia" (click)="addImage()" color="light">
|
||||
<ion-icon name="image"></ion-icon>
|
||||
</ion-fab-button>
|
||||
|
||||
@@ -36,6 +36,9 @@ import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, Cur
|
||||
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { AlertController, Platform, NavParams } from '@ionic/angular';
|
||||
import { File } from '@awesome-cordova-plugins/file/ngx';
|
||||
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
|
||||
|
||||
|
||||
const IMAGE_DIR = 'stored-images';
|
||||
@Component({
|
||||
@@ -77,7 +80,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
scrollToBottomBtn = false;
|
||||
longPressActive = false;
|
||||
frameUrl: any;
|
||||
downloadFile: any;
|
||||
downloadFile: string;
|
||||
massages: MessageService[] = []
|
||||
|
||||
showAvatar = true;
|
||||
@@ -86,8 +89,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
allowTyping = true;
|
||||
storedFileNames = [];
|
||||
lastAudioRecorded = '';
|
||||
audioRecorded:any = "";
|
||||
audioDownloaded:any = "";
|
||||
audioRecorded: any = "";
|
||||
audioDownloaded: any = "";
|
||||
durationDisplay = '';
|
||||
duration = 0;
|
||||
|
||||
@@ -121,7 +124,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
private processesService: ProcessesService,
|
||||
private fileToBase64Service: FileToBase64Service,
|
||||
private sanitiser: DomSanitizer,
|
||||
private alertController: AlertController
|
||||
private alertController: AlertController,
|
||||
private file: File,
|
||||
private platform: Platform,
|
||||
private fileOpener: FileOpener,
|
||||
) {
|
||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||
|
||||
@@ -258,7 +264,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
async getFile(fileName?:any){
|
||||
async getFile(fileName?: any) {
|
||||
const audioFile = await Filesystem.readFile({
|
||||
path: fileName,
|
||||
directory: Directory.Data
|
||||
@@ -276,16 +282,25 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
this.storage.get('recordData').then((recordData) => {
|
||||
console.log(recordData);
|
||||
if(recordData?.value?.recordDataBase64.includes('data:audio')){
|
||||
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
|
||||
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData?.value?.recordDataBase64);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`);
|
||||
}
|
||||
});
|
||||
} catch (error) {}
|
||||
} catch (error) { }
|
||||
|
||||
|
||||
this.storage.get('recordData').then((recordData) => {
|
||||
console.log(recordData);
|
||||
if (recordData.value.recordDataBase64.includes('data:audio')) {
|
||||
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64);
|
||||
}
|
||||
else {
|
||||
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async startRecording() {
|
||||
@@ -336,8 +351,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
//console.log(recordData);
|
||||
const fileName = new Date().getTime() + ".mp3";
|
||||
//Save file
|
||||
this.storage.set('fileName',fileName);
|
||||
this.storage.set('recordData',result).then(() => {
|
||||
this.storage.set('fileName', fileName);
|
||||
this.storage.set('recordData', result).then(() => {
|
||||
console.log('Audio recorded saved');
|
||||
})
|
||||
}
|
||||
@@ -347,7 +362,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
async deleteRecording(){
|
||||
async deleteRecording() {
|
||||
this.storage.remove('fileName');
|
||||
this.storage.remove('recordData');
|
||||
|
||||
@@ -397,6 +412,71 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).send({})
|
||||
}
|
||||
|
||||
|
||||
async sendAudio(fileName) {
|
||||
const roomId = this.roomId
|
||||
let audioFile;
|
||||
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 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",
|
||||
"msDuration": audioFile.value.msDuration,
|
||||
"mimeType": audioFile.value.mimeType,
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName,
|
||||
"title_link_download": true,
|
||||
"type": "audio"
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
|
||||
});
|
||||
this.deleteRecording();
|
||||
}
|
||||
|
||||
|
||||
deleteMessage(msgId: string, msg: MessageService) {
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId)
|
||||
if (msg.file.type == "application/webtrix") {
|
||||
this.openViewDocumentModal(msg.file);
|
||||
}
|
||||
else {
|
||||
console.log('PDF CLICK', msg)
|
||||
var str = msg.attachments[0].image_url;
|
||||
str = str.substring(1, ((str.length) - 1));
|
||||
|
||||
const encodedData = btoa(str);
|
||||
/* let fullUrl;
|
||||
fullUrl = "https://gabinetedigitalchat.dyndns.info" + url;
|
||||
//fullUrl = "http://www.africau.edu/images/default/sample.pdf";
|
||||
|
||||
this.frameUrl = fullUrl; */
|
||||
let file = this.base64toBlob(encodedData, 'application/pdf')
|
||||
let fileURL = URL.createObjectURL(file)
|
||||
console.log('PDF CLICK', fileURL)
|
||||
window.open(fileURL);
|
||||
|
||||
// this.chatService.getDocumentDetails(fullUrl);
|
||||
}
|
||||
}
|
||||
|
||||
base64toBlob(base64Data, contentType) {
|
||||
contentType = contentType || '';
|
||||
var sliceSize = 1024;
|
||||
@@ -406,88 +486,16 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
var byteArrays = new Array(slicesCount);
|
||||
|
||||
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
|
||||
var begin = sliceIndex * sliceSize;
|
||||
var end = Math.min(begin + sliceSize, bytesLength);
|
||||
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);
|
||||
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) => {
|
||||
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}`;
|
||||
}
|
||||
|
||||
console.log(this.audioRecorded);
|
||||
|
||||
//Converting base64 to 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",
|
||||
"msDuration":audioFile.value.msDuration,
|
||||
"mimeType":audioFile.value.mimeType,
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName ,
|
||||
"title_link_download": true,
|
||||
"type": "audio"
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
|
||||
});
|
||||
this.deleteRecording();
|
||||
}
|
||||
|
||||
|
||||
deleteMessage(msgId: string, msg:MessageService) {
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId)
|
||||
}
|
||||
|
||||
async viewDocument(msg: any, url?: string) {
|
||||
if (msg.file.type == "application/img") {
|
||||
let response: any = await this.AttachmentsService.getFile(msg.file.guid).toPromise();
|
||||
console.log(response);
|
||||
alert(response);
|
||||
|
||||
//this.openPreview(msg);
|
||||
|
||||
}
|
||||
else if (msg.file.type == "application/webtrix") {
|
||||
this.openViewDocumentModal(msg.file);
|
||||
}
|
||||
else {
|
||||
console.log('PDF CLICK', msg)
|
||||
/* let fullUrl;
|
||||
fullUrl = "https://gabinetedigitalchat.dyndns.info" + url;
|
||||
//fullUrl = "http://www.africau.edu/images/default/sample.pdf";
|
||||
|
||||
this.frameUrl = fullUrl; */
|
||||
let file = new Blob([msg.attachments[0].image_url], { type: 'application/pdf' });
|
||||
let fileURL = URL.createObjectURL(file)
|
||||
window.open(fileURL);
|
||||
|
||||
// this.chatService.getDocumentDetails(fullUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -737,6 +745,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss().then(async res => {
|
||||
console.log('webTrix ', res.data)
|
||||
const data = res.data;
|
||||
const roomId = this.roomId
|
||||
|
||||
@@ -750,6 +759,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
"DocId": res.data.selected.Id,
|
||||
"Assunto": res.data.selected.Assunto,
|
||||
},
|
||||
temporaryData: res,
|
||||
attachments: [{
|
||||
"title": res.data.selected.Assunto,
|
||||
"description": res.data.selected.DocTypeDesc,
|
||||
@@ -808,19 +818,23 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
const file: any = await this.fileService.getFileFromDevice(types);
|
||||
|
||||
//if (file.type == "application/pdf") {
|
||||
|
||||
console.log('Add file', file)
|
||||
/* const imageData = await this.fileToBase64Service.convert(file).then((filee) => {
|
||||
console.log('Add file', filee)
|
||||
}) */
|
||||
const blob = new Blob([file], { type: file.type })
|
||||
console.log('Add file', blob)
|
||||
console.log('Add file', JSON.stringify(await this.getBase64(file)))
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
if (file.type != "application/img" && file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/gif") {
|
||||
|
||||
const encodedData = btoa(JSON.stringify(await this.getBase64(file)));
|
||||
const blob = this.base64toBlob(encodedData, file.type)
|
||||
console.log('Add Blob file', blob)
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
|
||||
let pdfBase64;
|
||||
this.blobToBase64(blob).then(res => {
|
||||
console.log('Base64 pdf', res);
|
||||
this.wsChatMethodsService.getDmRoom(roomId).send({
|
||||
file: {
|
||||
"type": file.type,
|
||||
@@ -835,20 +849,33 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
});
|
||||
|
||||
} else {
|
||||
console.log('File type invalid')
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
blobToBase64 = blob => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(blob);
|
||||
getFileReader(): FileReader {
|
||||
const fileReader = new FileReader();
|
||||
const zoneOriginalInstance = (fileReader as any)["__zone_symbol__originalInstance"];
|
||||
return zoneOriginalInstance || fileReader;
|
||||
}
|
||||
|
||||
getBase64(file) {
|
||||
var reader = this.getFileReader();
|
||||
reader.readAsDataURL(file);
|
||||
return new Promise(resolve => {
|
||||
reader.onloadend = () => {
|
||||
resolve(reader.result);
|
||||
reader.onload = function () {
|
||||
resolve(reader.result)
|
||||
};
|
||||
reader.onerror = function (error) {
|
||||
console.log('Error: ', error);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
bookMeeting() {
|
||||
@@ -946,16 +973,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
msg.downloadFileMsg()
|
||||
}
|
||||
|
||||
_arrayBufferToBase64( buffer ) {
|
||||
var binary = '';
|
||||
var bytes = new Uint8Array( buffer );
|
||||
var len = bytes.byteLength;
|
||||
for (var i = 0; i < len; i++) {
|
||||
binary += String.fromCharCode( bytes[ i ] );
|
||||
}
|
||||
return window.btoa( binary );
|
||||
}
|
||||
|
||||
pdfPreview() {
|
||||
const options: DocumentViewerOptions = {
|
||||
title: 'My App'
|
||||
@@ -967,32 +984,123 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
console.log(msg);
|
||||
if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') {
|
||||
this.downloadFileMsg(msg)
|
||||
} else {}
|
||||
} else { }
|
||||
}
|
||||
|
||||
b64toBlob(b64Data, contentType) {
|
||||
contentType = contentType || '';
|
||||
var sliceSize = 512;
|
||||
b64Data = b64Data.replace(/^[^,]+,/, '');
|
||||
b64Data = b64Data.replace(/\s/g, '');
|
||||
var byteCharacters = window.atob(b64Data);
|
||||
var byteArrays = [];
|
||||
|
||||
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
||||
var slice = byteCharacters.slice(offset, offset + sliceSize);
|
||||
|
||||
var byteNumbers = new Array(slice.length);
|
||||
for (var i = 0; i < slice.length; i++) {
|
||||
byteNumbers[i] = slice.charCodeAt(i);
|
||||
}
|
||||
|
||||
var byteArray = new Uint8Array(byteNumbers);
|
||||
|
||||
byteArrays.push(byteArray);
|
||||
}
|
||||
|
||||
var blob = new Blob(byteArrays, { type: contentType });
|
||||
return blob;
|
||||
}
|
||||
|
||||
downloadFileFromBrowser(fileName: string, data: any): void {
|
||||
const linkSource = data;
|
||||
const downloadLink = document.createElement("a");
|
||||
downloadLink.href = linkSource;
|
||||
downloadLink.download = fileName;
|
||||
downloadLink.click();
|
||||
}
|
||||
|
||||
viewDocument(file: any, url?: string) {
|
||||
console.log()
|
||||
if (file.type == "application/webtrix") {
|
||||
this.openViewDocumentModal(file);
|
||||
}
|
||||
else {
|
||||
let fullUrl = "https://www.tabularium.pt" + url;
|
||||
this.fileService.viewDocumentByUrl(fullUrl);
|
||||
}
|
||||
}
|
||||
|
||||
openFile(pdfString, filename, type) {
|
||||
const blob = this.b64toBlob(pdfString, type)
|
||||
let pathFile = ''
|
||||
const fileName = filename
|
||||
const contentFile = blob
|
||||
if (this.platform.is('ios')) {
|
||||
pathFile = this.file.documentsDirectory
|
||||
} else {
|
||||
pathFile = this.file.externalRootDirectory
|
||||
}
|
||||
console.log(pdfString)
|
||||
console.log(pathFile)
|
||||
console.log(contentFile)
|
||||
this.file
|
||||
.writeFile(pathFile, fileName, contentFile, { replace: true })
|
||||
.then(success => {
|
||||
this.fileOpener
|
||||
.open(pathFile + fileName, type)
|
||||
.then(() => console.log('File is opened'))
|
||||
.catch(e => console.log('Error opening file', e));
|
||||
})
|
||||
.catch(e => console.log('Error writing file', e))
|
||||
}
|
||||
|
||||
async openPreview(msg) {
|
||||
console.log(msg);
|
||||
|
||||
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
|
||||
this.downloadFileMsg(msg)
|
||||
|
||||
if(msg.file.type === "application/webtrix") {
|
||||
this.viewDocument(msg.file, msg.attachments.image_url)
|
||||
} else {
|
||||
|
||||
/* if(msg.file.type === "application/pdf") {
|
||||
this.viewDocument(msg, msg.attachments.image_url)
|
||||
} else { */
|
||||
const modal = await this.modalController.create({
|
||||
component: ViewMediaPage,
|
||||
cssClass: 'modal modal-desktop',
|
||||
componentProps: {
|
||||
image: msg.attachments[0].image_url,
|
||||
type: msg.file.type,
|
||||
username: msg.u.name,
|
||||
_updatedAt: msg._updatedAt
|
||||
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
|
||||
this.downloadFileMsg(msg)
|
||||
|
||||
|
||||
/* } else if (msg.file.type === "application/pdf") {
|
||||
|
||||
|
||||
console.log(str);
|
||||
const win = window.open("", "_blank");
|
||||
let html = '';
|
||||
|
||||
html += '<html>';
|
||||
html += '<body style="margin:0!important">';
|
||||
html += '<iframe width="100%" height="100%" src="' + str + '" type="application/pdf" />';
|
||||
html += '</body>';
|
||||
html += '</html>';
|
||||
|
||||
setTimeout(() => {
|
||||
win.document.write(html);
|
||||
}, 0); */
|
||||
|
||||
|
||||
|
||||
//this.viewDocument(msg, msg.attachments.image_url)
|
||||
} else {
|
||||
|
||||
var str = msg.attachments[0].image_url;
|
||||
str = str.substring(1, ((str.length) - 1));
|
||||
|
||||
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
|
||||
this.downloadFileFromBrowser(msg.attachments[0].name, str)
|
||||
} else if (this.platform.is('tablet')) {
|
||||
this.openFile(str, msg.attachments[0].name, msg.file.type);
|
||||
}
|
||||
});
|
||||
modal.present();
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user