From 7fce5d006ee03d013c053138ff4dee81f2213743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Mon, 21 Mar 2022 10:44:53 +0100 Subject: [PATCH 1/7] converte file to blob --- src/app/pages/chat/messages/messages.page.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 023896572..b88119734 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -681,14 +681,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { /* 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 blob = new Blob(file, { type: file.type }) + console.log('Add file', blob) const formData = new FormData(); - formData.append("blobFile", blob2); + formData.append("blobFile", blob); this.wsChatMethodsService.getDmRoom(roomId).send({ file: { From 78126883ddb8a34166c407116e818f47dd7acfb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Mon, 21 Mar 2022 13:33:57 +0100 Subject: [PATCH 2/7] Send audio bug solved --- android/app/src/main/AndroidManifest.xml.orig | 17 ++ .../app/src/main/assets/capacitor.config.json | 3 + .../pages/chat/messages/messages.page.html | 160 +++++++++++------- src/app/pages/chat/messages/messages.page.ts | 6 +- .../shared/chat/messages/messages.page.html | 2 +- src/app/shared/chat/messages/messages.page.ts | 51 +++++- 6 files changed, 171 insertions(+), 68 deletions(-) create mode 100644 android/app/src/main/AndroidManifest.xml.orig diff --git a/android/app/src/main/AndroidManifest.xml.orig b/android/app/src/main/AndroidManifest.xml.orig new file mode 100644 index 000000000..66301e3a7 --- /dev/null +++ b/android/app/src/main/AndroidManifest.xml.orig @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/android/app/src/main/assets/capacitor.config.json b/android/app/src/main/assets/capacitor.config.json index 2399c4927..2b001f42e 100644 --- a/android/app/src/main/assets/capacitor.config.json +++ b/android/app/src/main/assets/capacitor.config.json @@ -16,5 +16,8 @@ "sound" ] } + }, + "server": { + "url": "http://192.168.1.8:8100" } } diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index b3676740b..011300b64 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -1,4 +1,4 @@ - +
-
-
+
+
{{msg.u.name}} {{msg.duration}} @@ -61,7 +65,8 @@
-
+
{{msg.u.name}} {{msg.duration}} @@ -74,61 +79,86 @@
-
-
- {{msg.u.name}} - {{msg.duration}} -
-
-
-
-
- image - -
-
+
+
+ {{msg.u.name}} + {{msg.duration}} +
+
+
+
+
+ image + +
+
-
+
- - - + + + + + {{file.title}}
-
- +
+
{{file.description}} - {{msg.displayType}} + {{msg.displayType}}
+
+ {{last ? scrollToBottom() : ''}}
- {{last ? scrollToBottom() : ''}}
-
-
- {{msg.u.name}} criou esta reunião
-
- De {{showDateDuration(msg.file.start_date)}} a {{showDateDuration(msg.file.end_date)}}
- {{msg.file.venue}}
-
+
+ {{msg.u.name}} criou esta reunião
+
+ + De {{showDateDuration(msg.file.start_date)}} a + {{showDateDuration(msg.file.end_date)}} +
+ + + {{msg.file.venue}} +
+
{{msg.u.name}} criou esta reunião
-
- De {{showDateDuration(msg.file.start_date)}} a {{showDateDuration(msg.file.end_date)}}
- {{msg.file.venue}}
+
+ + De {{showDateDuration(msg.file.start_date)}} a + {{showDateDuration(msg.file.end_date)}} +
+ + + {{msg.file.venue}} +
{{last ? scrollToBottom() : ''}}
@@ -168,24 +198,24 @@ -
- +
+ está a escrever ...
{{durationDisplay}} - +
- +
- - -
- + \ No newline at end of file diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index ec4c0deef..72e36abbc 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -389,11 +389,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { this.wsChatMethodsService.getDmRoom(roomId).send({ file: { "type": "application/audio", - /* "guid": '', */ + "guid": '', }, attachments: [{ "title": fileName , - "title_link": this.audioRecorded, + //"title_link": this.audioRecorded, "title_link_download": true, "type": "file" }], @@ -929,7 +929,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { async openPreview(msg) { console.log(msg); - if (!msg.attachments[0].image_url || 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 === '' || !msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') { this.downloadFile(msg) //this.testDownlod(msg) diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 6abb082f5..f35ba63cb 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -106,7 +106,7 @@ {{file.title}}
-
+
diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 9a45aa8fb..3cc67abe7 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -356,6 +356,27 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.wsChatMethodsService.getDmRoom(this.roomId).send({}) } + base64toBlob(base64Data, contentType) { + contentType = contentType || ''; + var sliceSize = 1024; + var byteCharacters = atob(base64Data); + var bytesLength = byteCharacters.length; + var slicesCount = Math.ceil(bytesLength / sliceSize); + var byteArrays = new Array(slicesCount); + + for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) { + var begin = sliceIndex * sliceSize; + var end = Math.min(begin + sliceSize, bytesLength); + + var bytes = new Array(end - begin); + for (var offset = begin, i = 0; offset < end; ++i, ++offset) { + bytes[i] = byteCharacters[offset].charCodeAt(0); + } + byteArrays[sliceIndex] = new Uint8Array(bytes); + } + return new Blob(byteArrays, { type: contentType }); +} + async sendAudio(fileName) { const roomId = this.roomId @@ -369,12 +390,16 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy else{ this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; } - }); + + + console.log(this.audioRecorded) //Converting base64 to blob - const base64Response = await fetch(this.audioRecorded); - const blob = await base64Response.blob(); - + //const base64Response = await fetch(this.audioRecorded); + //console.log(base64Response) + const encodedData = btoa(this.audioRecorded); + const blob = this.base64toBlob(encodedData,'audio/webm') + console.log(blob) const formData = new FormData(); formData.append("blobFile", blob); @@ -387,12 +412,14 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy }, attachments: [{ "title": fileName , - "title_link": this.audioRecorded, + //"title_link": this.audioRecorded, "title_link_download": true, "type": "audio" }], temporaryData: formData }) + + }); this.deleteRecording(); } @@ -898,12 +925,15 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } else if (msg.file.type === 'application/pdf') { this.downloadFile = event.body; + } else if (msg.file.type == 'application/audio') { + this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''); } msg.attachments[0] = { image_url: this.downloadFile, name: msg.attachments[0].name, title: msg.attachments[0].title, + title_link: this.downloadFile, title_link_download: msg.attachments[0].title_link_download, ts: msg.attachments[0].ts } @@ -936,6 +966,17 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy DocumentViewer.viewDocument } + async audioPreview(msg) { + console.log(msg); + if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') { + this.downloadFileMsg(msg) + + } else { + + } + + } + async openPreview(msg) { console.log(msg); From 5ca23e0bd75e206aff328a54b42562be90ab205e Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Mon, 21 Mar 2022 15:18:47 +0100 Subject: [PATCH 3/7] improve gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 338c1eeb4..9c25768b9 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,4 @@ node_modules_ node_modules__ plugins_ ios +src/plugin/beast-orm/ \ No newline at end of file From f70013d2a9e02a6ca25ce0c0281dfc33a1b9939e Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Mon, 21 Mar 2022 17:39:44 +0100 Subject: [PATCH 4/7] save --- .../shared/chat/messages/messages.page.html | 10 +++++- .../shared/chat/messages/messages.page.scss | 12 +++++++ src/app/shared/chat/messages/messages.page.ts | 4 +-- .../icon/theme/default/icons-download.svg | 18 ++++++++++ src/assets/icon/theme/gov/icons-download.svg | 18 ++++++++++ .../images/gabinete-success-despacho.svg | 33 +++++++++++++++++++ src/global.scss | 12 +++++-- 7 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 src/assets/icon/theme/default/icons-download.svg create mode 100644 src/assets/icon/theme/gov/icons-download.svg create mode 100644 src/assets/images/gabinete-success-despacho.svg diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index f35ba63cb..1ad5f56c5 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -106,7 +106,15 @@ {{file.title}}
-
+
+ + + {{file.title}} + + + +
+
diff --git a/src/app/shared/chat/messages/messages.page.scss b/src/app/shared/chat/messages/messages.page.scss index f594b8b3f..9933b4de3 100644 --- a/src/app/shared/chat/messages/messages.page.scss +++ b/src/app/shared/chat/messages/messages.page.scss @@ -227,6 +227,13 @@ margin-top: 4px; } + .chat-icon-download{ + font-size: 95px; + margin: 0 auto; + margin-top: 4px; + border: 1px solid red; + } + .type-message{ display: flex; border: 1px solid #ebebeb; @@ -329,3 +336,8 @@ display: block; .typing ngx-letters-avatar { padding-right: 5px; } + +.div-do-audio{ + border: 1px solid red !important; + overflow: auto; +} diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 3cc67abe7..ee1f8d7ae 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -390,7 +390,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy else{ this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; } - + console.log(this.audioRecorded) @@ -398,7 +398,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy //const base64Response = await fetch(this.audioRecorded); //console.log(base64Response) const encodedData = btoa(this.audioRecorded); - const blob = this.base64toBlob(encodedData,'audio/webm') + const blob = this.base64toBlob(encodedData, recordData.value.mimeType) console.log(blob) const formData = new FormData(); formData.append("blobFile", blob); diff --git a/src/assets/icon/theme/default/icons-download.svg b/src/assets/icon/theme/default/icons-download.svg new file mode 100644 index 000000000..58ee5221c --- /dev/null +++ b/src/assets/icon/theme/default/icons-download.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/assets/icon/theme/gov/icons-download.svg b/src/assets/icon/theme/gov/icons-download.svg new file mode 100644 index 000000000..58ee5221c --- /dev/null +++ b/src/assets/icon/theme/gov/icons-download.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/assets/images/gabinete-success-despacho.svg b/src/assets/images/gabinete-success-despacho.svg new file mode 100644 index 000000000..85fb58031 --- /dev/null +++ b/src/assets/images/gabinete-success-despacho.svg @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/global.scss b/src/global.scss index 4e6f94865..13612d07a 100644 --- a/src/global.scss +++ b/src/global.scss @@ -1148,9 +1148,16 @@ ngx-mat-datetime-content{ } } .audio-contentainer{ - width: 200px !important; + min-width: 200px !important; display: flex; overflow: auto !important; + .icon-download{ + font-size:35px !important; + } + .item-prior-download{ + --background:#000000e7; + } + } .title{ @@ -1190,7 +1197,8 @@ ngx-mat-datetime-content{ } .add-attachment-bg-color{ - background-color: #42b9fe13; + background-color: #42b9fe13 !important; + --background: #42b9fe0a !important; } .message-attachments{ From 1b95d74cb76264fa3ba78012a572d6fc2a374fd2 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Mon, 21 Mar 2022 21:09:05 +0100 Subject: [PATCH 5/7] save --- package-lock.json | 54 +--------- .../group-messages/group-messages.page.html | 12 ++- .../group-messages/group-messages.page.ts | 79 +++++++++----- .../pages/chat/messages/messages.page.html | 12 ++- src/app/pages/chat/messages/messages.page.ts | 66 ++++++++---- .../group-messages/group-messages.page.html | 10 +- .../group-messages/group-messages.page.ts | 100 +++++++++++------- src/app/shared/chat/messages/messages.page.ts | 27 +---- 8 files changed, 202 insertions(+), 158 deletions(-) diff --git a/package-lock.json b/package-lock.json index f9eacf4e2..6584646ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2202,21 +2202,6 @@ "integrity": "sha512-HCFwOxmK7igEgNm20y+zYi+XQ0OlZYnE4oCaI82TGmA7sehlDpBBKbjmI2Bd8aM09+BXFbAAtq7JCxkEfY8nIg==" }, "@capacitor/filesystem": { -<<<<<<< HEAD - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@capacitor/filesystem/-/filesystem-1.0.6.tgz", - "integrity": "sha512-8xqUbDZFGBMhgqoBSn9wEd9OBPdHIRegQ9zCCZcpHNf3FFAIby1ck+aDFnoq+Da49xhD6ks1SKCBSxz/26qWTw==" - }, - "@capacitor/haptics": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/@capacitor/haptics/-/haptics-1.1.3.tgz", - "integrity": "sha512-ui2mY/riK1Y4bxnJKJfclWO61obZ0RHmtErPhpmt4wIEVjG1segYdFop45R2PxyEwoUJgzEsAxnviM/T6k8seQ==" - }, - "@capacitor/ios": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/@capacitor/ios/-/ios-3.3.0.tgz", - "integrity": "sha512-KImT4hVoQJuAfe01wUYiMLnutMu7PxVCv4c8HVWiW+OuyyOua3lC8wQ5gAauGDugAo6mdM7fVva5a0Vtyhnbdg==" -======= "version": "1.1.0", "resolved": "https://registry.npmjs.org/@capacitor/filesystem/-/filesystem-1.1.0.tgz", "integrity": "sha512-8O3UuvL8HNUEJvZnmn8yUmvgB1evtXfcF0oxIo3YbSlylqywJwS3JTiuhKmsvSxCdpbTy8IaTsutVh3gZgWbKg==" @@ -2230,7 +2215,6 @@ "version": "3.4.1", "resolved": "https://registry.npmjs.org/@capacitor/ios/-/ios-3.4.1.tgz", "integrity": "sha512-ycFCyKI8DsgedVg7PW5MpCVgqFuD0PMHQGVfC5ichXc2C/jAATX32EVdEMCB0N3guKoH2k6T3Efwg59+Fcdx2w==" ->>>>>>> 0b14c4c0c63a6d55c9945163d7afb971a7375994 }, "@capacitor/keyboard": { "version": "1.1.3", @@ -3013,16 +2997,6 @@ "integrity": "sha512-68hdPn0hA7yn4YNTgmLF32x/l7arFulboGhNiyFQ35/QxqrOmppf77p4xaPOyJtNyICKHLaiStC6w1eEAtl9MA==", "requires": { "@types/cordova": "^0.0.34" -<<<<<<< HEAD - }, - "dependencies": { - "@types/cordova": { - "version": "0.0.34", - "resolved": "https://registry.npmjs.org/@types/cordova/-/cordova-0.0.34.tgz", - "integrity": "sha1-6nrd907Ow9dimCegw54smt3HPQQ=" - } -======= ->>>>>>> 0b14c4c0c63a6d55c9945163d7afb971a7375994 } }, "@ionic-native/core": { @@ -4943,6 +4917,11 @@ "integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==", "dev": true }, + "@types/cordova": { + "version": "0.0.34", + "resolved": "https://registry.npmjs.org/@types/cordova/-/cordova-0.0.34.tgz", + "integrity": "sha1-6nrd907Ow9dimCegw54smt3HPQQ=" + }, "@types/cors": { "version": "2.8.12", "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.12.tgz", @@ -16568,29 +16547,6 @@ "tslib": "^2.3.0" } }, -<<<<<<< HEAD - "ng2-pdf-viewer": { - "version": "3.0.8", - "resolved": "https://registry.npmjs.org/ng2-pdf-viewer/-/ng2-pdf-viewer-3.0.8.tgz", - "integrity": "sha512-p2qndFu1wQW4y+xXXw7yk1BhpRo5PGHKWD3PTc7pUULujx9d2vT26lhXR3p9WHitySadGqdCQpkA7W3v1dBlSg==", - "requires": { - "@types/pdfjs-dist": "^0.1.1", - "pdfjs-dist": "1.9.489" - }, - "dependencies": { - "pdfjs-dist": { - "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" - } - } - } - }, -======= ->>>>>>> 0b14c4c0c63a6d55c9945163d7afb971a7375994 "ngx-cookie-service": { "version": "12.0.3", "resolved": "https://registry.npmjs.org/ngx-cookie-service/-/ngx-cookie-service-12.0.3.tgz", 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 62dc32da5..4f1862878 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.html +++ b/src/app/pages/chat/group-messages/group-messages.page.html @@ -117,7 +117,15 @@ {{file.title}}
-
+
+ + + {{file.title}} + + + +
+
@@ -190,7 +198,7 @@ - +
{ console.log(recordData); + audioFile = recordData; if(recordData.value.recordDataBase64.includes('data:audio')){ this.audioRecorded = recordData.value.recordDataBase64; } else{ this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; } - }); //Converting base64 to blob - const base64Response = await fetch(this.audioRecorded); - const blob = await base64Response.blob(); - + const encodedData = btoa(this.audioRecorded); + const blob = this.base64toBlob(encodedData, recordData.value.mimeType) + console.log(blob) const formData = new FormData(); formData.append("blobFile", blob); this.wsChatMethodsService.getGroupRoom(roomId).send({ file: { "type": "application/audio", - /* "guid": '', */ + "msDuration":audioFile.value.msDuration, + "mimeType":audioFile.value.mimeType, }, attachments: [{ "title": fileName , - "title_link": this.audioRecorded, "title_link_download": true, - "type": "file" + "type": "audio" }], temporaryData: formData }) - this.deleteRecording(); + }); + this.deleteRecording(); } @@ -953,34 +976,35 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { 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; + 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") { + 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 { + } else if (msg.file.type === 'application/pdf') { this.downloadFile = event.body; + } else if (msg.file.type == 'application/audio') { + this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''); } - msg.attachments[0] = { image_url: this.downloadFile, name: msg.attachments[0].name, title: msg.attachments[0].title, + title_link: this.downloadFile, 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) - //} + // save the changes to the storage + msg.save() + } + }); + } async openPreview(msg) { @@ -1003,5 +1027,12 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } } + + async audioPreview(msg) { + console.log(msg); + if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') { + this.downloadFileMsg(msg) + } else {} + } } diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index 5af534892..89c5c8110 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -110,7 +110,15 @@ {{file.title}}
-
+
+ + + {{file.title}} + + + +
+
@@ -259,4 +267,4 @@
- \ No newline at end of file + diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 83b87f5cf..4468a1960 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -366,41 +366,64 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { this.wsChatMethodsService.getDmRoom(this.roomId).send({}) } + base64toBlob(base64Data, contentType) { + contentType = contentType || ''; + var sliceSize = 1024; + var byteCharacters = atob(base64Data); + var bytesLength = byteCharacters.length; + var slicesCount = Math.ceil(bytesLength / sliceSize); + var byteArrays = new Array(slicesCount); + + for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) { + var begin = sliceIndex * sliceSize; + var end = Math.min(begin + sliceSize, bytesLength); + + var bytes = new Array(end - begin); + for (var offset = begin, i = 0; offset < end; ++i, ++offset) { + bytes[i] = byteCharacters[offset].charCodeAt(0); + } + byteArrays[sliceIndex] = new Uint8Array(bytes); + } + return new Blob(byteArrays, { type: contentType }); +} + async sendAudio(fileName) { const roomId = this.roomId + let audioFile; this.storage.get('recordData').then((recordData) => { console.log(recordData); + audioFile = recordData; if(recordData.value.recordDataBase64.includes('data:audio')){ this.audioRecorded = recordData.value.recordDataBase64; } else{ this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; } - }); //Converting base64 to blob - const base64Response = await fetch(this.audioRecorded); - const blob = await base64Response.blob(); - + const encodedData = btoa(this.audioRecorded); + const blob = this.base64toBlob(encodedData, recordData.value.mimeType) + console.log(blob) const formData = new FormData(); formData.append("blobFile", blob); this.wsChatMethodsService.getDmRoom(roomId).send({ file: { "type": "application/audio", - "guid": '', + "msDuration":audioFile.value.msDuration, + "mimeType":audioFile.value.mimeType, }, attachments: [{ "title": fileName , - //"title_link": this.audioRecorded, "title_link_download": true, - "type": "file" + "type": "audio" }], temporaryData: formData }) - this.deleteRecording(); + }); + this.deleteRecording(); } blobToBase64 = blob => { @@ -887,37 +910,35 @@ 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 (event.type === HttpEventType.DownloadProgress) { - this.downloadProgess = Math.round((100 * event.loaded) / event.total); - console.log(this.downloadProgess) + //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 { - //console.log('TRY THIS LIBRARY ',fromByteArray(event.body)); - this.downloadFile = event.body; - } + } else if (msg.file.type === 'application/pdf') { + this.downloadFile = event.body; + } else if (msg.file.type == 'application/audio') { + this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''); + } msg.attachments[0] = { image_url: this.downloadFile, name: msg.attachments[0].name, title: msg.attachments[0].title, + title_link: this.downloadFile, title_link_download: msg.attachments[0].title_link_download, ts: msg.attachments[0].ts } - this.sqlservice.updateChatMsg(msg._id, this.downloadFile); + // save the changes to the storage + msg.save() } - }); - //} - } testDownlod(msg: MessageService) { @@ -947,6 +968,13 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } + async audioPreview(msg) { + console.log(msg); + if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') { + this.downloadFileMsg(msg) + } else {} + } + imageSize(img) { var canvas = document.createElement('canvas'); 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 3972a4591..23a735b7d 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -94,7 +94,15 @@ {{file.title}}
-
+
+ + + {{file.title}} + + + +
+
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 245533836..d55190f61 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -417,41 +417,64 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe this.wsChatMethodsService.getGroupRoom(this.roomId).send({}) } + base64toBlob(base64Data, contentType) { + contentType = contentType || ''; + var sliceSize = 1024; + var byteCharacters = atob(base64Data); + var bytesLength = byteCharacters.length; + var slicesCount = Math.ceil(bytesLength / sliceSize); + var byteArrays = new Array(slicesCount); + + for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) { + var begin = sliceIndex * sliceSize; + var end = Math.min(begin + sliceSize, bytesLength); + + var bytes = new Array(end - begin); + for (var offset = begin, i = 0; offset < end; ++i, ++offset) { + bytes[i] = byteCharacters[offset].charCodeAt(0); + } + byteArrays[sliceIndex] = new Uint8Array(bytes); + } + return new Blob(byteArrays, { type: contentType }); +} + async sendAudio(fileName) { const roomId = this.roomId + let audioFile; this.storage.get('recordData').then((recordData) => { console.log(recordData); + audioFile = recordData; if(recordData.value.recordDataBase64.includes('data:audio')){ this.audioRecorded = recordData.value.recordDataBase64; } else{ this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; } - }); //Converting base64 to blob - const base64Response = await fetch(this.audioRecorded); - const blob = await base64Response.blob(); - + const encodedData = btoa(this.audioRecorded); + const blob = this.base64toBlob(encodedData, recordData.value.mimeType) + console.log(blob) const formData = new FormData(); formData.append("blobFile", blob); this.wsChatMethodsService.getGroupRoom(roomId).send({ file: { "type": "application/audio", - /* "guid": '', */ + "msDuration":audioFile.value.msDuration, + "mimeType":audioFile.value.mimeType, }, attachments: [{ "title": fileName , - "title_link": this.audioRecorded, "title_link_download": true, - "type": "file" + "type": "audio" }], temporaryData: formData }) - this.deleteRecording(); + }); + this.deleteRecording(); } deleteMessage(msgId: string) { @@ -973,38 +996,34 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe 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; + this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => { + console.log('FILE TYPE 22', msg.file.guid) + var name = msg.file.guid; - if (event.type === HttpEventType.DownloadProgress) { - //this.downloadProgess = Math.round((100 * event.loaded) / event.total); - console.log('FILE TYPE 33', msg.file.type) - } else if (event.type === HttpEventType.Response) { - if (msg.file.type == "application/img") { - this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); - } else if (msg.file.type === 'application/pdf') { + if (event.type === HttpEventType.DownloadProgress) { + //this.downloadProgess = Math.round((100 * event.loaded) / event.total); + console.log('FILE TYPE 33', msg.file.type) + } else if (event.type === HttpEventType.Response) { + if (msg.file.type == "application/img") { + this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); + } else if (msg.file.type === 'application/pdf') { - this.downloadFile = event.body; - } - - msg.attachments[0] = { - image_url: this.downloadFile, - name: msg.attachments[0].name, - title: msg.attachments[0].title, - title_link_download: msg.attachments[0].title_link_download, - ts: msg.attachments[0].ts - } - - await this.storage.set(msg.file.guid, this.downloadFile).then(() => { - console.log('IMAGE SAVED') - }); + this.downloadFile = event.body; + } else if (msg.file.type == 'application/audio') { + this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''); } - - }); - - } + msg.attachments[0] = { + image_url: this.downloadFile, + name: msg.attachments[0].name, + title: msg.attachments[0].title, + title_link: this.downloadFile, + title_link_download: msg.attachments[0].title_link_download, + ts: msg.attachments[0].ts + } + // save the changes to the storage + msg.save() + } + }); } @@ -1029,5 +1048,12 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } + async audioPreview(msg) { + console.log(msg); + if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') { + this.downloadFileMsg(msg) + } else {} + } + } diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 6d3a4c68d..34fcd92ec 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -389,12 +389,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; } - - console.log(this.audioRecorded) - //Converting base64 to blob - //const base64Response = await fetch(this.audioRecorded); - //console.log(base64Response) const encodedData = btoa(this.audioRecorded); const blob = this.base64toBlob(encodedData, recordData.value.mimeType) console.log(blob) @@ -404,13 +399,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.wsChatMethodsService.getDmRoom(roomId).send({ file: { "type": "application/audio", - /* "guid": '', */ "msDuration":audioFile.value.msDuration, "mimeType":audioFile.value.mimeType, }, attachments: [{ "title": fileName , - //"title_link": this.audioRecorded, "title_link_download": true, "type": "audio" }], @@ -419,14 +412,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy }); this.deleteRecording(); - } - deleteMessage(msgId: string, msg:MessageService) { + deleteMessage(msgId: string, msg:MessageService) { msg.delateStatusFalse() this.wsChatMethodsService.getDmRoom(this.roomId).sendDeleteRequest(msgId) - } async viewDocument(msg: any, url?: string) { @@ -773,7 +764,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy const roomId = this.roomId const file: any = await this.fileService.getFileFromDevice(types); - + console.log('Add file', file) /* const imageData = await this.fileToBase64Service.convert(file).then((filee) => { console.log('Add file', filee) @@ -911,7 +902,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy downloadFileMsg(msg: MessageService) { console.log('FILE TYPE', msg.file.type) this.downloadFile = ""; - //if (msg.file.type == "application/img") { this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => { console.log('FILE TYPE 22', msg.file.guid) var name = msg.file.guid; @@ -928,7 +918,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } else if (msg.file.type == 'application/audio') { this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''); } - msg.attachments[0] = { image_url: this.downloadFile, name: msg.attachments[0].name, @@ -937,17 +926,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy title_link_download: msg.attachments[0].title_link_download, ts: msg.attachments[0].ts } - // save the changes to the storage msg.save() - - } - }); - // } - } _arrayBufferToBase64( buffer ) { @@ -971,11 +954,7 @@ 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 {} } async openPreview(msg) { From a76ebbbf0d3426edfedc034b5176412cb433fe64 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Mon, 21 Mar 2022 21:16:03 +0100 Subject: [PATCH 6/7] save --- src/app/pages/chat/messages/messages.page.html | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index 06dfbc98d..91ac2f850 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -62,24 +62,8 @@ {{msg.duration}}
-<<<<<<< HEAD - {{msg.msg}} - {{last ? scrollToBottom() : ''}} -
-
- -
-
- {{msg.u.name}} - {{msg.duration}} -
-
- {{msg.msg}} -======= {{msg.msg}} {{msg.msg}} ->>>>>>> c9af986ae8181cf24741ac7407264daea648d27e {{last ? scrollToBottom() : ''}}
From b4d008ef576e06dbbdf0ef9b5360f11634328d79 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Tue, 22 Mar 2022 11:04:18 +0100 Subject: [PATCH 7/7] save --- android/app/src/main/assets/capacitor.config.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/android/app/src/main/assets/capacitor.config.json b/android/app/src/main/assets/capacitor.config.json index 2b001f42e..2399c4927 100644 --- a/android/app/src/main/assets/capacitor.config.json +++ b/android/app/src/main/assets/capacitor.config.json @@ -16,8 +16,5 @@ "sound" ] } - }, - "server": { - "url": "http://192.168.1.8:8100" } }