This commit is contained in:
Peter Maquiran
2022-03-11 10:28:15 +01:00
117 changed files with 34570 additions and 1031 deletions
+11 -12
View File
@@ -61,7 +61,7 @@
</div>
</div>
<!-- <div (press)="handlePress(msg._id)" class='message-container incoming-{{msg.u.username!=loggedUser.me.username}}' (click)="openPreview(msg)" *ngIf="msg.msg !=''">
<div (press)="handlePress(msg._id)" class='message-container incoming-{{msg.u.username!=loggedUser.me.username}}' (click)="openPreview(msg)" *ngIf="msg.msg !=''">
<div class="title">
<ion-label>{{msg.u.name}}</ion-label>
<span class="time">{{msg.duration}}</span>
@@ -70,7 +70,7 @@
<ion-label>{{msg.msg}}</ion-label>
{{last ? scrollToBottom() : ''}}
</div>
</div> -->
</div>
<div *ngIf="msg.file">
@@ -88,7 +88,7 @@
</div>
<div *ngIf="msg.file.type != 'application/img'">
<div class="file">
<div (click)="docIndex(i); viewDocument(msg.file, file.title_link)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<div (click)="docIndex(i); openPreview(msg)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<span *ngIf="msg.file.type">
<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>
@@ -120,7 +120,7 @@
</div>
<!-- <div *ngIf="msg.file">
<div *ngIf="msg.file">
<div *ngIf="msg.file.type == 'application/meeting'" class="info-meeting">
<ion-label class="info-meeting-small">{{msg.u.name}} criou esta reunião</ion-label><br />
<button (click)="goToEvent(msg.file.id)" class="btn-no-color info-meeting-normal"><ion-label class="info-meeting-normal">{{msg.file.subject}}</ion-label></button><br />
@@ -128,7 +128,7 @@
<ion-label class="info-meeting-medium"><ion-icon></ion-icon><ion-icon name="location-outline"></ion-icon> {{msg.file.venue}}</ion-label><br />
</div>
{{last ? scrollToBottom() : ''}}
</div> -->
</div>
</div>
</div>
<ion-fab horizontal="end" vertical="bottom" slot="fixed">
@@ -168,13 +168,13 @@
<div class="typing" *ngIf="wsChatMethodsService.getDmRoom(roomId).otherUserType == true">
<ngx-letters-avatar
[avatarName]= "wsChatMethodsService.getGroupRoom(roomId).name"
[width]="30"
[width]="30"
[circular]="true"
fontFamily="Roboto"></ngx-letters-avatar>
Está a escrever ...
está a escrever ...
</div>
<ion-list hidden>
<ion-list>
<ion-item (click)="playFile(storedFileNames)">
{{storedFileNames}}
</ion-item>
@@ -182,14 +182,13 @@
{{storedFileNames}}
</ion-item>
</ion-list>
<audio hidden controls>
<audio controls>
<!-- <source src="https://www.tabularium.pt/file-upload/5g6DkyMC4MHcuaDyp/Audio%20record.mp3" type="audio/mpeg"> -->
</audio>
<!-- <button (click)="startRecording()">Start Recording</button>
<button (click)="stopRecording()">Stop Recording</button> -->
<button (click)="startRecording()">Start Recording</button>
<button (click)="stopRecording()">Stop Recording</button>
<div class="container width-100 d-flex">
<div>
<button class="btn-no-color" (click)="openChatOptions()">
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " class="chat-icon-options" src="assets/images/icons-add.svg"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " class="chat-icon-options" src="assets/images/theme/gov/icons-add.svg"></ion-icon>
+114 -50
View File
@@ -19,7 +19,8 @@ import { ChatMessageStore } from 'src/app/store/chat/chat-message.service';
import { ChatUserStorage } from 'src/app/store/chat/chat-user.service';
import { environment } from 'src/environments/environment';
import { ThemeService } from 'src/app/services/theme.service'
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
import { Directory, Encoding, FilesystemDirectory } from '@capacitor/filesystem';
import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder';
import { Haptics, ImpactStyle } from '@capacitor/haptics';
import { PreviewCameraPage } from 'src/app/modals/preview-camera/preview-camera.page';
@@ -39,6 +40,11 @@ import { SearchPage } from 'src/app/pages/search/search.page';
import { Storage } from '@ionic/storage';
import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service';
import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
import { Plugins } from '@capacitor/core';
import { fromByteArray } from 'base64-js';
const { Filesystem } = Plugins;
const IMAGE_DIR = 'stored-images';
@@ -88,6 +94,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
myAudio: any;
downloadfile: any;
downloadFile: any;
downloadProgess: number;
constructor(
public popoverController: PopoverController,
@@ -128,7 +135,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked
this.wsChatMethodsService.openRoom(this.roomId)
setTimeout(()=>{
setTimeout(() => {
this.scrollToBottomClicked()
}, 150)
@@ -195,7 +202,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
const temp: any[] = result.files.reverse();
this.storedFileNames = temp[0];
console.log(this.storedFileNames);
})
}
@@ -352,10 +358,41 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.wsChatMethodsService.getDmRoom(this.roomId).send({})
}
viewDocument(file: any, url?: string) {
viewDocument(msg: any, url?: string) {
console.log(msg)
if (msg.attachments.type == "application/webtrix") {
//this.openViewDocumentModal(file);
}
if (file.type == "application/webtrix") {
this.openViewDocumentModal(file);
if (msg.attachments.type == "application/pdf") {
try {
const writeSecretFile = async () => {
await Filesystem.writeFile({
path: msg.attachments.name,
data: msg.attachments.image_url,
directory: Directory.Documents,
encoding: Encoding.UTF8,
});
};
console.log('WRITE', writeSecretFile);
const readSecretFile = async () => {
const contents = await Filesystem.readFile({
path: msg.attachments.name,
directory: Directory.Documents,
encoding: Encoding.UTF8,
});
console.log('secrets:', contents);
};
console.log('READ', readSecretFile);
} catch (e) {
console.error("Unable to write file", e);
}
}
}
@@ -373,7 +410,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
FolderID: '',
Subject: file.Assunto,
SourceSecFsID: file.ApplicationId,
SourceType: 'DOC',
SourceType: 'PDF',
SourceID: file.DocId,
DispatchNumber: ''
}
@@ -520,7 +557,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
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);
@@ -535,8 +572,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
"guid": ''
},
attachments: [{
"image_url": capturedImage,
"title": capturedImageTitle ,
"title": capturedImageTitle,
"text": "description",
"title_link_download": false,
}],
@@ -568,14 +604,14 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
});
await modal.present();
modal.onDidDismiss().then(async res=>{
modal.onDidDismiss().then(async res => {
const data = res.data;
const roomId = this.roomId
if(data.selected) {
if (data.selected) {
this.wsChatMethodsService.getDmRoom(roomId).send({
file:{
file: {
"name": res.data.selected.Assunto,
"type": "application/webtrix",
"ApplicationId": res.data.selected.ApplicationType,
@@ -598,7 +634,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
});
}
async addFileToChatMobile(types: typeof FileType[] ) {
async addFileToChatMobile(types: typeof FileType[]) {
const roomId = this.roomId
const file = await Camera.getPhoto({
@@ -611,7 +647,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
//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();
@@ -624,8 +660,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
},
temporaryData: formData,
attachments: [{
"title": file.path ,
"image_url": 'data:image/jpeg;base64,' +file.base64String,
"title": file.path,
"text": "description",
"title_link_download": false,
}]
@@ -635,36 +670,44 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
async addFileToChat(types: typeof FileType[] ) {
async addFileToChat(types: typeof FileType[]) {
const roomId = this.roomId
const file: any = await this.fileService.getFileFromDevice(types);
console.log('ADDFILECHAT', file)
const imageData = await this.fileToBase64Service.convert(file)
console.log('ADDFILECHAT', imageData)
console.log('Add file', file)
/* const imageData = await this.fileToBase64Service.convert(file).then((filee) => {
console.log('Add file', filee)
}) */
const response = await fetch(file);
const blob = await response.blob();
const blob2 = new Blob([blob])
console.log('Add file base64', file)
console.log('Add file blob', blob)
const formData = new FormData();
formData.append("blobFile", file);
formData.append("blobFile", blob2);
this.wsChatMethodsService.getDmRoom(roomId).send({
file: {
"type": "application/img",
"type": file.type,
"guid": '',
},
temporaryData: formData,
attachments: [{
"title": file.name ,
"image_url": imageData,
"text": "description",
"title": file.name,
"name": file.name,
// "text": "description",
"title_link_download": false,
}]
}],
temporaryData: formData
})
}
async openChatOptions(ev?: any) {
const roomId = this.roomId
console.log('MOBILE CHAT OPTION',this.members);
console.log('MOBILE CHAT OPTION', this.members);
const popover = await this.popoverController.create({
component: ChatOptionsPopoverPage,
@@ -678,7 +721,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
translucent: true
});
await popover.present();
popover.onDidDismiss().then( async (res) => {
popover.onDidDismiss().then(async (res) => {
console.log(res['data']);
if (res['data'] == 'meeting') {
this.bookMeeting();
@@ -776,39 +819,58 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
testeDownload(msg: MessageService) {
this.downloadFile = "";
this.AttachmentsService.downloadFileAndStore(msg.file.guid);
}
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 (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 (event.type === HttpEventType.DownloadProgress) {
this.downloadProgess = Math.round((100 * event.loaded) / event.total);
console.log(this.downloadProgess)
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), ''));
msg.file = {
guid: msg.file.guid,
image_url: this.downloadFile,
type: msg.file.type
}
this.sqlservice.updateChatMsg(msg._id, this.downloadFile);
} else {
//console.log('TRY THIS LIBRARY ',fromByteArray(event.body));
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
}
this.sqlservice.updateChatMsg(msg._id, this.downloadFile);
}
}
});
//}
}
async openPreview(msg) {
testDownlod(msg: MessageService) {
this.AttachmentsService.downloadFileAndStore(msg.file.guid)
}
if (msg.attachments[0].image_url === null || msg.attachments[0].image_url === '' ) {
this.downloadFileMsg(msg)
async openPreview(msg) {
console.log(msg);
if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
this.downloadFile(msg)
//this.testDownlod(msg)
} else {
const modal = await this.modalController.create({
@@ -816,6 +878,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
cssClass: 'modal modal-desktop',
componentProps: {
image: msg.attachments[0].image_url,
type: msg.file.type,
username: msg.u.name,
_updatedAt: msg._updatedAt
}
@@ -845,6 +908,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
// async ShareEmail(msg){
// // Check if sharing via email is supported
// await Share.share({