From 80aaf352b61d724e12074bf3ab8e50fc658a35da Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Fri, 4 Feb 2022 08:00:10 +0100 Subject: [PATCH] improve --- .../group-messages/group-messages.page.ts | 119 ++----------- src/app/pages/chat/messages/messages.page.ts | 49 +----- .../group-messages/group-messages.page.ts | 162 +----------------- src/app/shared/chat/messages/messages.page.ts | 4 +- 4 files changed, 24 insertions(+), 310 deletions(-) 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 ffb265c32..b6023c121 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -249,7 +249,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.roomCountDownDate = this.timeService.countDownDateTimer(this.room.customFields.countDownDate, this.room._id); } this.getGroupContacts(this.room); - this.loadGroupMessages(this.room); this.showLoader = false; }); } @@ -298,27 +297,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } } - loadGroupMessages(room:any){ - this.showLoader = true; - //If group is private call getGroupMembers - if(this.room.t === 'p'){ - this.chatService.getPrivateGroupMessages(this.roomId).subscribe(res=>{ - console.log(res); - let msgOnly = res['messages'].filter(data => data.t != 'au'); - //this.messages = msgOnly.reverse(); - this.transformDataMSG(msgOnly.reverse()); - this.getRoomMessageDB(this.roomId); - this.showLoader = false; - }); - } - //Otherwise call getChannelMembers for públic groups - /* else{ - this.chatService.getPublicGroupMessages(this.roomId).subscribe(res=>{ - console.log(res); - this.messages = res['messages'].reverse(); - }); - } */ - } showDateDuration(start:any){ return this.timeService.showDateDuration(start); @@ -366,42 +344,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { }); } - loadPicture() { - const input = this.fileLoaderService.createInput({ - accept: ['image/apng', 'image/jpeg', 'image/png'] - }) - - input.onchange = async () => { - const file = this.fileLoaderService.getFirstFile(input) - - console.log(file); - - const imageData = await this.fileToBase64Service.convert(file) - this.capturedImage = imageData; - this.capturedImageTitle = file.name; - - let body = { - "message": - { - "rid": this.roomId, - "msg": "", - "attachments": [{ - //"title": this.capturedImageTitle , - //"text": "description", - "title_link_download": false, - "image_url": this.capturedImage, - }] - } - } - - this.chatService.sendMessage(body).subscribe(res=> { - console.log(res); - },(error) => { - - }); - //console.log(this.capturedImage) - }; - } viewDocument(file:any, url?:string){ @@ -608,7 +550,9 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { "title_link_download": true, //"thumb_url": "assets/images/webtrix-logo.png", "message_link": url_no_options, - "type": "webtrix" + "type": "webtrix", + "text": res.data.selected.DocTypeDesc, + "thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png", }] }) @@ -619,7 +563,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } - async addFileToChat(types: typeof FileType[] ) { const file = await this.fileService.getFileFromDevice(types); const imageData = await this.fileToBase64Service.convert(file) @@ -684,65 +627,23 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { await popover.present(); await popover.onDidDismiss().then( async(res)=>{ console.log(res['data']); - if(res['data'] == 'meeting'){ + if (res['data'] == 'meeting') { this.bookMeeting(); } - else if(res['data'] == 'take-picture') { - 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 base64 = await fetch(capturedImage); - const blob = await base64.blob(); - const formData = new FormData(); - formData.append("blobFile", blob); - console.log('ALL IMAGE', formData) - let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise() - console.log(guid.path); - - this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => { - - 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) { - var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - console.log('add picture to chat',fileImage); - await this.storage.set(guid.path, fileImage).then(() => { - console.log('add picture to chat IMAGE SAVED') - - this.wsChatMethodsService.getDmRoom(this.roomId).send({ - file: { - "type": "application/img", - "guid": guid.path, - "image_url": fileImage - }, - attachments: [{ - //"title": this.capturedImageTitle , - //"text": "description", - "title_link_download": false, - //"image_url": this.capturedImage, - }] - }) - - }); - } - - }); + else if (res['data'] == 'take-picture') { + this.takePicture() } - else if(res['data'] == 'add-picture'){ - + else if (res['data'] == 'add-picture') { this.addImage() } - else if(res['data'] == 'add-document'){ + else if (res['data'] == 'add-document') { this.addFile() } - else if(res['data'] == 'documentoGestaoDocumental'){ + else if (res['data'] == 'documentoGestaoDocumental') { + this.addFileWebtrix() } - this.loadGroupMessages(this.roomId); }); } diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 8b03a1439..1bbcebd38 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -526,7 +526,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { const lastphoto: any = await this.fileService.loadFiles(); const { capturedImage, capturedImageTitle} = await this.fileService.loadFileData(lastphoto); - const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(this.roomId).send({ + const { message, updateMessage} = this.wsChatMethodsService.getDmRoom(roomId).send({ file: { "type": "application/img", "guid": '', @@ -631,7 +631,9 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { "title_link_download": true, //"thumb_url": "assets/images/webtrix-logo.png", "message_link": url_no_options, - "type": "webtrix" + "type": "webtrix", + "text": res.data.selected.DocTypeDesc, + "thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png", }] }) @@ -711,48 +713,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { this.bookMeeting(); } else if (res['data'] == 'take-picture') { - 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 base64 = await fetch(capturedImage); - const blob = await base64.blob(); - const formData = new FormData(); - formData.append("blobFile", blob); - console.log('ALL IMAGE', formData) - let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise() - console.log(guid.path); - - this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => { - - 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) { - var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - console.log('add picture to chat',fileImage); - await this.storage.set(guid.path, fileImage).then(() => { - console.log('add picture to chat IMAGE SAVED') - - this.wsChatMethodsService.getDmRoom(this.roomId).send({ - file: { - "type": "application/img", - "guid": guid.path, - "image_url": fileImage - }, - attachments: [{ - "title": capturedImageTitle , - "text": "description", - "title_link_download": false, - "image_url": capturedImage, - }] - }) - - }); - } - - }); + this.takePicture() } else if (res['data'] == 'add-picture') { this.addImage() 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 d25537edb..fbff28265 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -398,10 +398,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe else { this.roomName = res.data.name.split('-').join(' '); console.log(this.roomName); - - //this.getRoomInfo(); - this.loadGroupMessages(this.roomId); - //this.modalController.dismiss(); }; }); @@ -478,85 +474,6 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe }); } - loadPicture() { - const input = this.fileLoaderService.createInput({ - accept: ['image/apng', 'image/jpeg', 'image/png'] - }) - - input.onchange = async () => { - const file = this.fileLoaderService.getFirstFile(input) - - console.log(file); - - const imageData = await this.fileToBase64Service.convert(file) - this.capturedImage = imageData; - this.capturedImageTitle = file.name; - - let body = { - "message": - { - "rid": this.roomId, - "msg": "", - "attachments": [{ - //"title": this.capturedImageTitle , - //"text": "description", - "title_link_download": false, - "image_url": this.capturedImage, - }] - } - } - - this.chatService.sendMessage(body).subscribe(res => { - console.log(res); - }, (error) => { - - }); - //console.log(this.capturedImage) - }; - } - - loadDocument() { - const input = this.fileLoaderService.createInput({ - accept: ['.doc', '.docx', '.pdf'] - }) - - input.onchange = async () => { - const file = this.fileLoaderService.getFirstFile(input) - - console.log(file); - - const imageData = await this.fileToBase64Service.convert(file) - this.capturedImage = imageData; - this.capturedImageTitle = file.name; - - let body = { - "message": - { - "rid": this.roomId, - "msg": "", - "attachments": [{ - "title": this.capturedImageTitle, - "text": "", - "title_link": this.capturedImage, - "title_link_download": true, - "thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png", - "message_link": this.capturedImage, - }], - "file": { - "name": this.capturedImageTitle, - "type": "application/pdf", - } - } - } - - this.chatService.sendMessage(body).subscribe(res => { - //console.log(res); - }, (error) => { - - }); - //console.log(this.capturedImage) - }; - } async addDocGestaoDocumental() { const modal = await this.modalController.create({ @@ -573,36 +490,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe if (res) { const data = res.data; this.documents.push(data.selected); - console.log(res.data.selected); - console.log(res.data.selected.Id); - console.log(res.data.selected.ApplicationType); - - let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise(); - let url_no_options: string = url.replace("webTRIX.Viewer", "webTRIX.Viewer.Branch1"); - console.log(url_no_options); - //console.log('Oie'); - - let body = { - "message": - { - "rid": this.roomId, - "msg": "", - "attachments": [{ - "title": res.data.selected.Assunto, - "text": res.data.selected.DocTypeDesc, - "title_link": url_no_options, - "title_link_download": true, - "thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png", - "message_link": url_no_options, - }] - } - } - this.chatService.sendMessage(body).subscribe(res => { - console.log(res); - }, (error) => { - - }); - + + this.addFileWebtrix() } }); } @@ -779,7 +668,9 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe "title_link_download": true, //"thumb_url": "assets/images/webtrix-logo.png", "message_link": url_no_options, - "type": "webtrix" + "type": "webtrix", + "text": res.data.selected.DocTypeDesc, + "thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png", }] }) @@ -895,48 +786,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } else if (res['data'] == 'take-picture') { - 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 base64 = await fetch(capturedImage); - const blob = await base64.blob(); - const formData = new FormData(); - formData.append("blobFile", blob); - console.log('ALL IMAGE', formData) - let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise() - console.log(guid.path); - - this.AttachmentsService.downloadFile(guid.path).subscribe(async (event) => { - - 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) { - var fileImage = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - console.log('add picture to chat',fileImage); - await this.storage.set(guid.path, fileImage).then(() => { - console.log('add picture to chat IMAGE SAVED') - - this.wsChatMethodsService.getDmRoom(this.roomId).send({ - file: { - "type": "application/img", - "guid": guid.path, - "image_url": fileImage - }, - attachments: [{ - //"title": this.capturedImageTitle , - //"text": "description", - "title_link_download": false, - //"image_url": this.capturedImage, - }] - }) - - }); - } - - }); + this.takePicture() } else if (res['data'] == 'add-picture') { diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 21675134e..8faa411ec 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -555,7 +555,9 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy "title_link_download": true, //"thumb_url": "assets/images/webtrix-logo.png", "message_link": url_no_options, - "type": "webtrix" + "type": "webtrix", + "text": res.data.selected.DocTypeDesc, + "thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png", }] })