From 5c210928c0feaec59d2045ca3492a06580b3cca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Thu, 3 Mar 2022 08:21:22 +0100 Subject: [PATCH] lasta chnages --- .../app/src/main/assets/capacitor.config.json | 2 +- package-lock.json | 97 ++++- package.json | 3 +- .../modals/view-media/view-media.module.ts | 4 +- .../modals/view-media/view-media.page.html | 8 +- src/app/modals/view-media/view-media.page.ts | 2 + .../group-messages/group-messages.page.html | 2 +- .../group-messages/group-messages.page.ts | 390 +++++++++--------- .../pages/chat/messages/messages.page.html | 2 +- src/app/pages/chat/messages/messages.page.ts | 96 +++-- .../group-messages/group-messages.page.html | 2 +- .../group-messages/group-messages.page.ts | 73 +++- .../shared/chat/messages/messages.module.ts | 4 +- .../shared/chat/messages/messages.page.html | 66 +-- src/app/shared/chat/messages/messages.page.ts | 141 ++++--- 15 files changed, 527 insertions(+), 365 deletions(-) diff --git a/android/app/src/main/assets/capacitor.config.json b/android/app/src/main/assets/capacitor.config.json index 4cdf5187c..f9d5f88c0 100644 --- a/android/app/src/main/assets/capacitor.config.json +++ b/android/app/src/main/assets/capacitor.config.json @@ -18,6 +18,6 @@ } }, "server": { - "url": "http://192.168.0.92:8100" + "url": "http://192.168.1.5:8100" } } diff --git a/package-lock.json b/package-lock.json index 4efb94fea..84f153db9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4999,6 +4999,11 @@ "integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==", "dev": true }, + "@types/pdfjs-dist": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@types/pdfjs-dist/-/pdfjs-dist-0.1.2.tgz", + "integrity": "sha512-BvRLWz6RCI8FMKbgfdTCadVwimUv8920gLsnBEAkECjtqIy95jtt+G1ebNQE2b8PTnLjJICPpmBOGhgkSsiPKA==" + }, "@types/prettier": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.4.1.tgz", @@ -6159,8 +6164,7 @@ "big.js": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/big.js/-/big.js-5.2.2.tgz", - "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==", - "dev": true + "integrity": "sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==" }, "binary-extensions": { "version": "2.2.0", @@ -7181,8 +7185,7 @@ "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", - "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", - "dev": true + "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=" }, "code-point-at": { "version": "1.1.0", @@ -9453,8 +9456,7 @@ "emojis-list": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/emojis-list/-/emojis-list-3.0.0.tgz", - "integrity": "sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==", - "dev": true + "integrity": "sha512-/kyM18EfinwXZbno9FyUGeFh87KC8HRQBQGildHZbEuRyWFOmv1U10o9BBp8XVZDVNNuQKyIGIu5ZYAAXJ0V2Q==" }, "enabled": { "version": "2.0.0", @@ -16465,18 +16467,22 @@ } }, "ng2-pdf-viewer": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/ng2-pdf-viewer/-/ng2-pdf-viewer-7.0.1.tgz", - "integrity": "sha512-kjjsvHd5t1Ff7ydb3Far3d6cSyw/XJH5KXgcp/0bFzSFBAV2c5aOghxoY/yQVjgG+R6F16nVUh2UrZdngLXLSg==", + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/ng2-pdf-viewer/-/ng2-pdf-viewer-3.0.8.tgz", + "integrity": "sha512-p2qndFu1wQW4y+xXXw7yk1BhpRo5PGHKWD3PTc7pUULujx9d2vT26lhXR3p9WHitySadGqdCQpkA7W3v1dBlSg==", "requires": { - "pdfjs-dist": "~2.7.570", - "tslib": "^2.0.0" + "@types/pdfjs-dist": "^0.1.1", + "pdfjs-dist": "1.9.489" }, "dependencies": { "pdfjs-dist": { - "version": "2.7.570", - "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-2.7.570.tgz", - "integrity": "sha512-/ZkA1FwkEOyDaq11JhMLazdwQAA0F9uwrP7h/1L9Akt9KWh1G5/tkzS+bPuUELq2s2GDFnaT+kooN/aSjT7DXQ==" + "version": "1.9.489", + "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-1.9.489.tgz", + "integrity": "sha1-yuWf7d0WouXRlappUnlVz+QALB0=", + "requires": { + "node-ensure": "^0.0.0", + "worker-loader": "^0.8.0" + } } } }, @@ -16565,6 +16571,11 @@ "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz", "integrity": "sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==" }, + "node-ensure": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/node-ensure/-/node-ensure-0.0.0.tgz", + "integrity": "sha1-7K52QVDemYYexcgQ/V0Jaxg5Mqc=" + }, "node-fetch": { "version": "2.6.1", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", @@ -24774,6 +24785,64 @@ "resolved": "https://registry.npmjs.org/wordcloud/-/wordcloud-1.2.2.tgz", "integrity": "sha512-fUnDsGrHXou+49j1OeKaC7nOeZPx+sWjIet0L/j6eAcm0nXy+a+AuUs/iDAX4PLBg1Zc6wgXWXhoXdQsXRWAEw==" }, + "worker-loader": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/worker-loader/-/worker-loader-0.8.1.tgz", + "integrity": "sha1-6OmVMx6jTfW/aCloJL+38K1XjUM=", + "requires": { + "loader-utils": "^1.0.2", + "schema-utils": "^0.3.0" + }, + "dependencies": { + "ajv": { + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", + "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", + "requires": { + "co": "^4.6.0", + "fast-deep-equal": "^1.0.0", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.3.0" + } + }, + "fast-deep-equal": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", + "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=" + }, + "json-schema-traverse": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", + "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=" + }, + "json5": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", + "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "requires": { + "minimist": "^1.2.0" + } + }, + "loader-utils": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz", + "integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==", + "requires": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^1.0.1" + } + }, + "schema-utils": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-0.3.0.tgz", + "integrity": "sha1-9YdyIs4+kx7a4DnxfrNxbnE3+M8=", + "requires": { + "ajv": "^5.0.0" + } + } + } + }, "wrap-ansi": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", diff --git a/package.json b/package.json index 00ed7e276..25f754e7e 100644 --- a/package.json +++ b/package.json @@ -97,6 +97,7 @@ "angular-cropperjs": "^0.1.5", "angular-svg-icon": "^12.0.0", "angular-tag-cloud-module": "^5.2.2", + "base64-js": "^1.5.1", "bootstrap": "^4.5.0", "build": "0.1.4", "capacitor-voice-recorder": "^2.0.0", @@ -133,7 +134,7 @@ "lite-server": "^2.6.1", "moment": "^2.29.1", "ng-lazyload-image": "^9.1.2", - "ng2-pdf-viewer": "^7.0.1", + "ng2-pdf-viewer": "^3.0.8", "ngx-cookie-service": "^12.0.3", "ngx-image-compress": "^11.0.3", "ngx-image-cropper": "^5.0.1", diff --git a/src/app/modals/view-media/view-media.module.ts b/src/app/modals/view-media/view-media.module.ts index 7a78f5148..772ba6e59 100644 --- a/src/app/modals/view-media/view-media.module.ts +++ b/src/app/modals/view-media/view-media.module.ts @@ -8,6 +8,7 @@ import { ViewMediaPageRoutingModule } from './view-media-routing.module'; import { ViewMediaPage } from './view-media.page'; import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; +import { PdfViewerModule } from 'ng2-pdf-viewer'; @NgModule({ imports: [ @@ -15,7 +16,8 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; FormsModule, IonicModule, FontAwesomeModule, - ViewMediaPageRoutingModule + ViewMediaPageRoutingModule, + PdfViewerModule ], declarations: [ViewMediaPage] }) diff --git a/src/app/modals/view-media/view-media.page.html b/src/app/modals/view-media/view-media.page.html index ddbfc30d6..3334943bd 100644 --- a/src/app/modals/view-media/view-media.page.html +++ b/src/app/modals/view-media/view-media.page.html @@ -20,7 +20,13 @@
- +
+ +
+
+ + +
diff --git a/src/app/modals/view-media/view-media.page.ts b/src/app/modals/view-media/view-media.page.ts index d9b316c3d..ff6820f19 100644 --- a/src/app/modals/view-media/view-media.page.ts +++ b/src/app/modals/view-media/view-media.page.ts @@ -9,6 +9,7 @@ import { ModalController, NavParams } from '@ionic/angular'; export class ViewMediaPage implements OnInit { image: any; + type: any; name: string _updatedAt: string @@ -22,6 +23,7 @@ export class ViewMediaPage implements OnInit { private navParams:NavParams, ) { this.image = this.navParams.get('image') + this.type = this.navParams.get('type') this.name = this.navParams.get('username') this._updatedAt = this.navParams.get('_updatedAt') } diff --git a/src/app/pages/chat/group-messages/group-messages.page.html b/src/app/pages/chat/group-messages/group-messages.page.html index 9cd924709..2796ce272 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.html +++ b/src/app/pages/chat/group-messages/group-messages.page.html @@ -107,7 +107,7 @@
-
+
diff --git a/src/app/pages/chat/group-messages/group-messages.page.ts b/src/app/pages/chat/group-messages/group-messages.page.ts index 6dc135f23..0180b6f80 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -1,5 +1,5 @@ import { Component, ElementRef, OnInit, ViewChild, AfterViewChecked, AfterViewInit, OnDestroy, ChangeDetectorRef, } from '@angular/core'; -import { ActionSheetController, IonSlides, MenuController, ModalController, NavParams, PopoverController,Platform } from '@ionic/angular'; +import { ActionSheetController, IonSlides, MenuController, ModalController, NavParams, 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'; @@ -8,7 +8,7 @@ import { ChatPopoverPage } from 'src/app/shared/popover/chat-popover/chat-popove import { ContactsPage } from '../new-group/contacts/contacts.page'; import { NewGroupPage } from '../new-group/new-group.page'; import { GroupContactsPage } from './group-contacts/group-contacts.page'; -import {Router} from '@angular/router' +import { Router } from '@angular/router' import { EditGroupPage } from '../edit-group/edit-group.page'; import { TimeService } from 'src/app/services/functions/time.service'; import { FileLoaderService } from 'src/app/services/file/file-loader.service'; @@ -43,33 +43,33 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { showLoader: boolean; - isGroupCreated:boolean; + isGroupCreated: boolean; loggedUser: any; - room:any; - roomName:any; - members:any; + room: any; + roomName: any; + members: any; contacts: string[] = [" Ana M.", "Andre F.", "Bruno G.", "Catarina T", "Tiago"]; - allUsers:any[] = []; + allUsers: any[] = []; roomId: string; - loggedUserChat:any; + loggedUserChat: any; eventSelectedDate: Date = new Date(); - scrollingOnce:boolean = true; + scrollingOnce: boolean = true; private scrollChangeCallback: () => void; currentPosition: any; startPosition: number; - capturedImage:any; - capturedImageTitle:any; + capturedImage: any; + capturedImageTitle: any; attendees: EventPerson[] = []; scrollToBottomBtn = false; longPressActive = false; showMessageOptions = false; - selectedMsgId:string; - roomCountDownDate:any; + selectedMsgId: string; + roomCountDownDate: any; downloadFile: any; @ViewChild('scrollMe') private myScrollContainer: ElementRef; @@ -104,7 +104,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.isGroupCreated = true; this.roomId = this.navParams.get('roomId'); window.onresize = (event) => { - if( window.innerWidth > 701){ + if (window.innerWidth > 701) { this.modalController.dismiss(); } }; @@ -113,7 +113,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked; this.wsChatMethodsService.openRoom(this.roomId) - setTimeout(()=>{ + setTimeout(() => { this.scrollToBottomClicked() }, 50) @@ -121,7 +121,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { ngOnInit() { console.log(this.roomId); - this.loggedUser=this.loggedUserChat; + this.loggedUser = this.loggedUserChat; this.getRoomInfo(); this.scrollToBottom(); this.serverLongPull(); @@ -134,7 +134,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }) } - setStatus(status:string){ + setStatus(status: string) { let body = { message: '', status: status, @@ -144,16 +144,16 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }) } - deleteMessage(msgId:string){ + deleteMessage(msgId: string) { let body = { "roomId": this.roomId, "msgId": msgId, "asUser": false, } - if(msgId){ + if (msgId) { //this.alertService.confirmDeleteMessage(body); } - else{ + else { this.toastService.badRequest('Não foi possível apagar'); } this.showMessageOptions = false; @@ -166,12 +166,12 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.roomCountDownDate = this.timeService.countDownDate(this.room.customFields.countDownDate, this.room._id); } - handlePress(id?:string){ + handlePress(id?: string) { this.selectedMsgId = id; this.showMessageOptions = true; } - handleClick(){ + handleClick() { this.showMessageOptions = false; this.selectedMsgId = ""; } @@ -188,10 +188,10 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { //alert('UP'); this.scrollingOnce = false; } - if((containerHeight - 100) > scroll){ + if ((containerHeight - 100) > scroll) { this.scrollToBottomBtn = true; } - else{ + else { this.scrollToBottomBtn = false; } this.currentPosition = scroll; @@ -225,25 +225,25 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { scrollToBottom(): void { try { - if(this.scrollingOnce){ + if (this.scrollingOnce) { this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight; //this.scrollingOnce = false; } - } catch(err) { } + } catch (err) { } } scrollToBottomClicked = () => { try { this.myScrollContainer.nativeElement.scrollTop = this.myScrollContainer.nativeElement.scrollHeight; - } catch(err) { } + } catch (err) { } } - getRoomInfo(){ + getRoomInfo() { this.showLoader = true; - this.chatService.getRoomInfo(this.roomId).subscribe(room=>{ + this.chatService.getRoomInfo(this.roomId).subscribe(room => { this.room = room['room']; this.roomName = this.room.name.split('-').join(' '); - if(this.room.customFields.countDownDate){ + if (this.room.customFields.countDownDate) { this.roomCountDownDate = this.timeService.countDownDateTimer(this.room.customFields.countDownDate, this.room._id); } this.getGroupContacts(this.room); @@ -251,9 +251,9 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }); } - async getChatMembers(){ + async getChatMembers() { //return await this.chatService.getMembers(roomId).toPromise(); - this.chatService.getAllUsers().subscribe(res=> { + this.chatService.getAllUsers().subscribe(res => { console.log(res); this.allUsers = res['users'].filter(data => data.username != this.loggedUserChat.me.username); @@ -266,28 +266,28 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.loadGroupMessages(); } */ - close(){ + close() { this.modalController.dismiss(); } - doRefresh(ev:any){ + doRefresh(ev: any) { this.getRoomInfo(); ev.target.complete(); } - getGroupContacts(room:any){ + getGroupContacts(room: any) { this.showLoader = true; //If group is private call getGroupMembers - if(this.room.t === 'p'){ - this.chatService.getGroupMembers(this.roomId).subscribe(res=>{ + if (this.room.t === 'p') { + this.chatService.getGroupMembers(this.roomId).subscribe(res => { console.log(res); this.members = res['members']; this.showLoader = false; }); } //Otherwise call getChannelMembers for públic groups - else{ - this.chatService.getChannelMembers(this.roomId).subscribe(res=>{ + else { + this.chatService.getChannelMembers(this.roomId).subscribe(res => { console.log(res); this.members = res['members']; this.showLoader = false; @@ -296,10 +296,10 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } - showDateDuration(start:any){ + showDateDuration(start: any) { return this.timeService.showDateDuration(start); } - countDownDate(date:any, roomId:string){ + countDownDate(date: any, roomId: string) { this.roomCountDownDate = this.timeService.countDownDate(date, roomId); return this.timeService.countDownDateTimer(date, roomId); } @@ -328,33 +328,33 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }, }); await modal.present(); - modal.onDidDismiss().then(res=>{ - if(res.data == 'leave'){ + modal.onDidDismiss().then(res => { + if (res.data == 'leave') { console.log('saiu do grupo'); //this.wsChatMethodsService.subscribeToRoomUpdate(this.roomId, this.room); } - else if(res.data == 'cancel'){ + else if (res.data == 'cancel') { console.log('cancel'); } - else if(res.data == 'edit'){ + else if (res.data == 'edit') { this.editGroup(this.roomId); } }); } - viewDocument(file:any, url?:string){ + viewDocument(file: any, url?: string) { - if(file.type == "application/webtrix") { + if (file.type == "application/webtrix") { this.openViewDocumentModal(file); } - else{ + else { let fullUrl = "https://www.tabularium.pt" + url; this.fileService.viewDocumentByUrl(fullUrl); } } - async openViewDocumentModal(file:any){ + async openViewDocumentModal(file: any) { let task = { serialNumber: '', @@ -371,17 +371,17 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } let doc = { - "Id": "", - "ParentId": "", - "Source": 1, - "ApplicationId": file.ApplicationId, - "CreateDate": "", - "Data": null, - "Description":"", - "Link": null, - "SourceId": file.DocId, - "SourceName": file.Assunto, - "Stakeholders": "", + "Id": "", + "ParentId": "", + "Source": 1, + "ApplicationId": file.ApplicationId, + "CreateDate": "", + "Data": null, + "Description": "", + "Link": null, + "SourceId": file.DocId, + "SourceName": file.Assunto, + "Stakeholders": "", } const modal = await this.modalController.create({ @@ -406,19 +406,19 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } async bookMeeting() { - this.attendees = this.members.map((val)=>{ + this.attendees = this.members.map((val) => { return { Name: val.name, - EmailAddress: val.username+"@"+environment.domain, + EmailAddress: val.username + "@" + environment.domain, IsRequired: "true", } }); console.log(this.attendees); this.popoverController.dismiss(); - if( window.innerWidth <= 1024){ + if (window.innerWidth <= 1024) { const modal = await this.modalController.create({ component: NewEventPage, - componentProps:{ + componentProps: { attendees: this.attendees, }, cssClass: 'modal modal-desktop', @@ -426,7 +426,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }); await modal.present(); modal.onDidDismiss().then((data) => { - if(data){ + if (data) { } }); @@ -441,7 +441,7 @@ export class GroupMessagesPage 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); const blob = await base64.blob(); const formData = new FormData(); @@ -454,8 +454,8 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }, temporaryData: formData, attachments: [{ - "title": capturedImageTitle , - "image_url": capturedImage, // rocketchat + "title": capturedImageTitle, + //"image_url": capturedImage, // rocketchat "text": "description", "title_link_download": false, }] @@ -482,13 +482,13 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } }); 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(this.roomId).send({ - file:{ + file: { "name": res.data.selected.Assunto, "type": "application/webtrix", "ApplicationId": res.data.selected.ApplicationType, @@ -515,26 +515,37 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { async addFileToChat(types: typeof FileType[] ) { + + const roomId = this.roomId + const file: any = await this.fileService.getFileFromDevice(types); - const imageData = await this.fileToBase64Service.convert(file) + 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(); + console.log('Add file', blob) const formData = new FormData(); - formData.append("blobFile", file); + formData.append("blobFile", blob); - this.wsChatMethodsService.getGroupRoom(this.roomId).send({ + this.wsChatMethodsService.getGroupRoom(roomId).send({ file: { - "type": "application/img", - "guid": '' + "type": file.type, + "guid": '', }, - temporaryData: formData, attachments: [{ "title": file.name , - "text": "description", - "image_url": imageData, + "name": file.name , + // "text": "description", + //"image_url": file.base64String, // rocketchat "title_link_download": false, - }] + }], + temporaryData: formData }) + } async openChatOptions(ev?: any) { @@ -553,7 +564,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { translucent: true }); await popover.present(); - await popover.onDidDismiss().then( async(res)=>{ + await popover.onDidDismiss().then(async (res) => { console.log(res['data']); if (res['data'] == 'meeting') { this.bookMeeting(); @@ -575,7 +586,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }); } - async addContacts(){ + async addContacts() { console.log(this.members); const modal = await this.modalController.create({ @@ -592,12 +603,12 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { await modal.present(); - modal.onDidDismiss().then(()=>{ + modal.onDidDismiss().then(() => { this.getRoomInfo(); }); } - async editGroup(roomId){ + async editGroup(roomId) { const modal = await this.modalController.create({ component: EditGroupPage, cssClass: 'modal modal-desktop', @@ -606,7 +617,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }, }); await modal.present(); - modal.onDidDismiss().then((res)=>{ + modal.onDidDismiss().then((res) => { console.log(res.data); this.getRoomInfo(); //this.modalController.dismiss(res.data); @@ -711,42 +722,42 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } - async serverLongPull(){ + async serverLongPull() { this.chatService.getPrivateGroupMessages(this.roomId).subscribe(async res => { - if (res == 502) { - // Connection timeout - // happens when the connection was pending for too long - // let's reconnect - await this.serverLongPull(); - } else if (res != 200) { - // Show Error - //showMessage(response.statusText); - //this.loadMessages() - let msgOnly = res['messages'].filter(data => data.t != 'au'); - //this.messages = msgOnly.reverse(); - // console.log('MOBILE MSG ROCKET',this.messages); - this.transformDataMSG(msgOnly.reverse()); - this.getRoomMessageDB(this.roomId); - // Reconnect in one second - if(this.route.url != "/home/chat"){ - console.log("Timer message stop") - } else { - //Check if modal is opened - if(document.querySelector('.isGroupChatOpened')){ - await new Promise(resolve => setTimeout(resolve, 5000)); - await this.serverLongPull(); - console.log('Timer message running') + if (res == 502) { + // Connection timeout + // happens when the connection was pending for too long + // let's reconnect + await this.serverLongPull(); + } else if (res != 200) { + // Show Error + //showMessage(response.statusText); + //this.loadMessages() + let msgOnly = res['messages'].filter(data => data.t != 'au'); + //this.messages = msgOnly.reverse(); + // console.log('MOBILE MSG ROCKET',this.messages); + this.transformDataMSG(msgOnly.reverse()); + this.getRoomMessageDB(this.roomId); + // Reconnect in one second + if (this.route.url != "/home/chat") { + console.log("Timer message stop") + } else { + //Check if modal is opened + if (document.querySelector('.isGroupChatOpened')) { + await new Promise(resolve => setTimeout(resolve, 5000)); + await this.serverLongPull(); + console.log('Timer message running') + } } - } - } else { - // Got message - //let message = await response.text(); - //this.loadMessages() - await this.serverLongPull(); - } - }); + } else { + // Got message + //let message = await response.text(); + //this.loadMessages() + await this.serverLongPull(); + } + }); } sliderOpts = { @@ -756,86 +767,93 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { centeredSlides: true }; zoomActive = false; -zoomScale = 1; + zoomScale = 1; -sliderZoomOpts = { - allowSlidePrev: false, - allowSlideNext: false, - zoom: { - maxRatio: 5 - }, - on: { - zoomChange: (scale, imageEl, slideEl) => { - this.zoomActive = true; - this.zoomScale = scale/5; - this.changeDetectorRef.detectChanges(); + sliderZoomOpts = { + allowSlidePrev: false, + allowSlideNext: false, + zoom: { + maxRatio: 5 + }, + on: { + zoomChange: (scale, imageEl, slideEl) => { + this.zoomActive = true; + this.zoomScale = scale / 5; + this.changeDetectorRef.detectChanges(); + } } } -} -async touchEnd(zoomslides: IonSlides, card) { - // Zoom back to normal - const slider = await zoomslides.getSwiper(); - const zoom = slider.zoom; - zoom.out(); + async touchEnd(zoomslides: IonSlides, card) { + // Zoom back to normal + const slider = await zoomslides.getSwiper(); + const zoom = slider.zoom; + zoom.out(); - // Card back to normal - card.el.style['z-index'] = 9; + // Card back to normal + card.el.style['z-index'] = 9; - this.zoomActive = false; - this.changeDetectorRef.detectChanges(); -} + this.zoomActive = false; + this.changeDetectorRef.detectChanges(); + } -touchStart(card) { - // Make card appear above backdrop - card.el.style['z-index'] = 11; -} + touchStart(card) { + // Make card appear above backdrop + card.el.style['z-index'] = 11; + } -downloadFileMsg(msg) { - 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; + downloadFileMsg(msg) { + 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) { - this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - console.log('FILE TYPE 44', this.downloadFile) + 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 { - msg.file = { - guid: msg.file.guid, - image_url: this.downloadFile, - type: msg.file.type + this.downloadFile = event.body; } - this.sqlservice.updateChatMsg(msg._id, this.downloadFile); - } - }); - console.log('FILE TYPE 44', this.downloadFile) + + 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); + } + }); + console.log('FILE TYPE 44', this.downloadFile) + //} + } + + async openPreview(msg) { + + if (!msg.attachments[0].image_url ||msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') { + this.downloadFileMsg(msg) + + } 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 + } + }); + modal.present(); + } + } } -async openPreview(msg) { - - if (msg.attachments[0].image_url === null || msg.attachments[0].image_url === '' ) { - this.downloadFileMsg(msg) - - } else { - const modal = await this.modalController.create({ - component: ViewMediaPage, - cssClass: 'modal modal-desktop', - componentProps: { - image: msg.attachments[0].image_url, - username: msg.u.name, - _updatedAt: msg._updatedAt - } - }); - modal.present(); - } - -} -} - diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index 09568e7c0..8ea3666ff 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -88,7 +88,7 @@
-
+
diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 82d9b9020..a8d6bc0e4 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -40,9 +40,10 @@ 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 { Plugins } from '@capacitor/core'; +import { fromByteArray } from 'base64-js'; - const { Filesystem } = Plugins; +const { Filesystem } = Plugins; const IMAGE_DIR = 'stored-images'; @@ -133,7 +134,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) @@ -364,7 +365,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } if (msg.attachments.type == "application/pdf") { - + try { const writeSecretFile = async () => { await Filesystem.writeFile({ @@ -375,7 +376,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { }); }; - console.log('WRITE',writeSecretFile); + console.log('WRITE', writeSecretFile); const readSecretFile = async () => { const contents = await Filesystem.readFile({ @@ -383,11 +384,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { directory: Directory.Documents, encoding: Encoding.UTF8, }); - + console.log('secrets:', contents); }; - console.log('READ',readSecretFile); + console.log('READ', readSecretFile); } catch (e) { console.error("Unable to write file", e); @@ -558,7 +559,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); @@ -573,8 +574,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { "guid": '' }, attachments: [{ - "image_url": capturedImage, - "title": capturedImageTitle , + "title": capturedImageTitle, "text": "description", "title_link_download": false, }], @@ -606,14 +606,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, @@ -636,7 +636,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({ @@ -649,7 +649,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(); @@ -662,8 +662,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, }] @@ -673,7 +672,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { - async addFileToChat(types: typeof FileType[] ) { + async addFileToChat(types: typeof FileType[]) { const roomId = this.roomId @@ -682,8 +681,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { /* 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 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", blob); @@ -694,10 +696,9 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { "guid": '', }, attachments: [{ - "title": file.name , - "name": file.name , + "title": file.name, + "name": file.name, // "text": "description", - "image_url": file, // rocketchat "title_link_download": false, }], temporaryData: formData @@ -708,7 +709,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { 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, @@ -722,7 +723,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(); @@ -824,34 +825,42 @@ export class MessagesPage implements OnInit, 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 (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('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) { + console.log(msg); - if (msg.attachments[0].image_url === null || msg.attachments[0].image_url === '' ) { + if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') { this.downloadFileMsg(msg) } else { @@ -860,6 +869,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 } diff --git a/src/app/shared/chat/group-messages/group-messages.page.html b/src/app/shared/chat/group-messages/group-messages.page.html index 3c57ada49..7c23085b7 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -83,7 +83,7 @@
-
+
diff --git a/src/app/shared/chat/group-messages/group-messages.page.ts b/src/app/shared/chat/group-messages/group-messages.page.ts index bef09ff69..04ade1457 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -695,29 +695,52 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe async addFileToChat(types: typeof FileType[] ) { + const roomId = this.roomId const file: any = await this.fileService.getFileFromDevice(types); - const imageData = await this.fileToBase64Service.convert(file) + 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", file); + formData.append("blobFile", blob); + + let pdfBase64; + this.blobToBase64(blob).then(res => { + console.log('Base64 pdf', res); + this.wsChatMethodsService.getGroupRoom(roomId).send({ + file: { + "type": file.type, + "guid": '', + }, + attachments: [{ + "title": file.name , + "name": file.name , + "image_url": res, + // "text": "description", + "title_link_download": false, + }], + temporaryData: formData + }) + }); + - this.wsChatMethodsService.getGroupRoom(roomId).send({ - file: { - "type": "application/img", - "guid": '' - }, - temporaryData: formData, - attachments: [{ - "title": file.name , - "image_url": imageData, - "text": "description", - "title_link_download": false, - }] - }) } + blobToBase64 = blob => { + const reader = new FileReader(); + reader.readAsDataURL(blob); + return new Promise(resolve => { + reader.onloadend = () => { + resolve(reader.result); + }; + }); + }; + bookMeeting() { let data = { roomId: this.roomId, @@ -812,12 +835,19 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe //this.downloadProgess = Math.round((100 * event.loaded) / event.total); console.log('FILE TYPE 33', msg.file.type) } else if (event.type === HttpEventType.Response) { - this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - - msg.file = { - guid: msg.file.guid, + 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, - type: msg.file.type + name: msg.attachments[0].name, + title: msg.attachments[0].title, + title_link_download: msg.attachments[0].title_link_download, + ts: msg.attachments[0].ts } await this.storage.set(msg.file.guid, this.downloadFile).then(() => { @@ -833,7 +863,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe async openPreview(msg) { - if (msg.attachments[0].image_url === null || msg.attachments[0].image_url === '' ) { + if (!msg.attachments[0].image_url || msg.attachments[0].image_url === null || msg.attachments[0].image_url === '' ) { this.downloadFileMsg(msg) } else { @@ -842,6 +872,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe cssClass: 'modal modal-desktop', componentProps: { image: msg.attachments[0].image_url, + type: msg.file.type, username: msg.u.name, _updatedAt: msg._updatedAt } diff --git a/src/app/shared/chat/messages/messages.module.ts b/src/app/shared/chat/messages/messages.module.ts index 5e072c254..aec854bf1 100644 --- a/src/app/shared/chat/messages/messages.module.ts +++ b/src/app/shared/chat/messages/messages.module.ts @@ -12,6 +12,7 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; import { MatButtonModule } from '@angular/material/button'; import {MatMenuModule} from '@angular/material/menu'; import { LettersAvatarModule } from "ngx-letters-avatar"; +import { PdfViewerModule } from 'ng2-pdf-viewer'; @NgModule({ imports: [ @@ -22,7 +23,8 @@ import { LettersAvatarModule } from "ngx-letters-avatar"; MessagesPageRoutingModule, MatButtonModule, MatMenuModule, - LettersAvatarModule + LettersAvatarModule, + PdfViewerModule ], exports: [MessagesPage], diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 14e69814e..0c94e1c4e 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -38,7 +38,8 @@
-
+
@@ -52,9 +53,10 @@ {{msg.duration}}
- {{msg.msg}} - - + {{msg.msg}} + + + @@ -63,7 +65,8 @@
-
+
@@ -72,7 +75,7 @@
- {{msg.u.name}} + {{msg.u.name}} {{msg.duration}}
@@ -81,23 +84,28 @@
image - - - + + + + + +
-
+
- + + - - + + + + {{file.title}}
@@ -106,13 +114,15 @@ {{file.description}} - {{msg.displayType}} + {{msg.displayType}} - - - + + + + +
@@ -197,13 +207,10 @@ - -
- + +
+ A escrever...
@@ -240,8 +247,9 @@
- @@ -261,4 +269,4 @@
-
+ \ No newline at end of file diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 2c768a2c7..c52649b9b 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -33,7 +33,7 @@ import { SearchPage } from 'src/app/pages/search/search.page'; import { ProcessesService } from 'src/app/services/processes.service'; import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service'; import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; -import { DocumentViewer, DocumentViewerOptions} from '@ionic-native/document-viewer'; +import { DocumentViewer, DocumentViewerOptions } from '@ionic-native/document-viewer'; const IMAGE_DIR = 'stored-images'; @Component({ @@ -274,11 +274,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy //fullUrl = "http://www.africau.edu/images/default/sample.pdf"; this.frameUrl = fullUrl; */ - let file = new Blob([msg.attachments.image_url], {type:'application/pdf'}); + let file = new Blob([msg.attachments[0].image_url], { type: 'application/pdf' }); let fileURL = URL.createObjectURL(file) - window.open(fileURL,"_blank"); + window.open(fileURL); - // this.chatService.getDocumentDetails(fullUrl); + // this.chatService.getDocumentDetails(fullUrl); } } @@ -457,7 +457,7 @@ export class MessagesPage implements OnInit, OnChanges, 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(); @@ -470,8 +470,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy }, 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, }] @@ -485,7 +485,7 @@ export class MessagesPage implements OnInit, OnChanges, 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); console.log('imsge take picture', image) const blob = await base64.blob(); @@ -501,7 +501,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy }, temporaryData: formData, attachments: [{ - "title": capturedImageTitle , + "title": capturedImageTitle, "image_url": capturedImage, "text": "description", "title_link_download": false, @@ -529,14 +529,14 @@ export class MessagesPage implements OnInit, OnChanges, 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, @@ -558,7 +558,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy }); } - async addFileToChatMobile(types: typeof FileType[] ) { + async addFileToChatMobile(types: typeof FileType[]) { const roomId = this.roomId const file = await Camera.getPhoto({ @@ -571,7 +571,7 @@ export class MessagesPage implements OnInit, OnChanges, 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(); @@ -584,8 +584,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy }, 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, }] @@ -595,7 +595,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy - async addFileToChat(types: typeof FileType[] ) { + async addFileToChat(types: typeof FileType[]) { const roomId = this.roomId @@ -604,7 +604,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy /* const imageData = await this.fileToBase64Service.convert(file).then((filee) => { console.log('Add file', filee) }) */ - const blob = new Blob([file],{type: file.type}) + const blob = new Blob([file], { type: file.type }) console.log('Add file', blob) const formData = new FormData(); @@ -619,11 +619,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy "guid": '', }, attachments: [{ - "title": file.name , - "name": file.name , + "title": file.name, + "name": file.name, + //"image_url": res, // "text": "description", "title_link_download": false, - "image_url": res, }], temporaryData: formData }) @@ -632,7 +632,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } - blobToBase64 = blob => { + blobToBase64 = blob => { const reader = new FileReader(); reader.readAsDataURL(blob); return new Promise(resolve => { @@ -694,7 +694,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } }); await modal.present(); - modal.onDidDismiss().then( async (res) => { + modal.onDidDismiss().then(async (res) => { console.log(res['data']); @@ -738,38 +738,50 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy 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; + 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 { - this.downloadFile = btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - } + 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') { - - msg.file = { - guid: msg.file.guid, - image_url: this.downloadFile, - type: msg.file.type - } - - await this.storage.set(msg.file.guid, this.downloadFile).then(() => { - console.log('IMAGE SAVED') - }); + 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 + } - // } + await this.storage.set(msg.file.guid, this.downloadFile).then(() => { + console.log('IMAGE SAVED') + }); + } + + }); + + // } } + _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' @@ -778,34 +790,35 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } async openPreview(msg) { -console.log(msg); + console.log(msg); - if (msg.file.image_url === null || msg.file.image_url === '' ) { + 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") { + /* 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, - username: msg.u.name, - _updatedAt: msg._updatedAt - } - }); - modal.present(); - } - + } 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 + } + }); + modal.present(); + //} + } } - testEditMessage(msg:MessageService) { + testEditMessage(msg: MessageService) { msg.receptorReceive() // alert('cool!') }