diff --git a/.gitignore b/.gitignore index d07aa35cf..5528da384 100644 --- a/.gitignore +++ b/.gitignore @@ -35,7 +35,7 @@ npm-debug.log* # Custom /package-lock.json - + src/app/architect/ src/environments/environment.e2e.ts .env @@ -52,4 +52,4 @@ node_modules_ node_modules__ plugins_ ios -src/plugin/beast-orm \ No newline at end of file +src/plugin/beast-orm 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/src/app/pages/chat/group-messages/group-messages.page.html b/src/app/pages/chat/group-messages/group-messages.page.html index 97c525f3d..e8b83b138 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.html +++ b/src/app/pages/chat/group-messages/group-messages.page.html @@ -118,7 +118,15 @@ {{file.title}} -
+
+ + + {{file.title}} + + + +
+
@@ -193,7 +201,7 @@ - +
{ console.log(res); @@ -432,46 +430,64 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { 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 - - try { - - this.storage.get('recordData').then((recordData) => { - console.log(recordData); - if(recordData.value.recordDataBase64.includes('data:audio')){ - this.audioRecorded = recordData.value.recordDataBase64; - } - else{ - this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; - } - }); - } catch (error) {} - + 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(); } @@ -959,40 +975,11 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { 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; - - 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 = 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); - } - }); - console.log('FILE TYPE 44', this.downloadFile) - //} + downloadFileMsg(msg: MessageService) { + msg.downloadFileMsg() } - async openPreview(msg) { + async openPreview(msg: MessageService) { if (!msg.attachments[0].image_url ||msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') { this.downloadFileMsg(msg) @@ -1012,5 +999,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 bcd95991b..a11653d83 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}} @@ -80,47 +84,78 @@
-
+
- - - + + + + + {{file.title}}
-
- +
+ + + {{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() : ''}}
@@ -164,24 +199,24 @@ -
- +
+ está a escrever ...
{{durationDisplay}} - +
- +
- - -
diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 75ae06f9c..110e45d2c 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -370,45 +370,63 @@ 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 - try { - - this.storage.get('recordData').then((recordData) => { - console.log(recordData); - if(recordData.value.recordDataBase64.includes('data:audio')){ - this.audioRecorded = recordData.value.recordDataBase64; - } - else{ - this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; - } - }); - } catch (error) {} - - + 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 => { @@ -749,14 +767,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: { @@ -896,39 +911,7 @@ 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) - 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; - } - - 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); - } - - }); - - //} - + msg.downloadFileMsg() } testDownlod(msg: MessageService) { @@ -938,7 +921,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) @@ -958,6 +941,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/services/auth.service.ts b/src/app/services/auth.service.ts index b28f8f4ec..a9c989a6c 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -174,6 +174,8 @@ export class AuthService { // // message.getFileFromDb() // }); + message.downloadFileMsg() + return true } catch(e) { console.log('failed to upload to server', e) diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 472164861..3dd75d4a3 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -10,6 +10,8 @@ import { ChatStorageService } from './chat-storage.service' import { ChatMethodsService } from './chat-methods.service' import { MessageModel, DeleteMessageModel } from '../../models/beast-orm' import { AESEncrypt } from '../aesencrypt.service' +import { HttpClient, HttpEventType } from '@angular/common/http'; +import { AttachmentsService } from 'src/app/services/attachments.service'; @Injectable({ providedIn: 'root' @@ -59,7 +61,8 @@ export class MessageService { private WsChatService: WsChatService, private ChatStorageService: ChatStorageService, private ChatMethodsService: ChatMethodsService, - private AESEncrypt: AESEncrypt) { + private AESEncrypt: AESEncrypt, + private AttachmentsService: AttachmentsService,) { } setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, }:Message) { @@ -102,10 +105,13 @@ export class MessageService { } if(this.hasFile) { - // this.getFileFromDb() + if(this.file.type != 'application/webtrix') { this.displayType = this.file.type.replace('application/','').toUpperCase() } + + this.downloadFileMsg() + } this.calDateDuration() @@ -118,19 +124,6 @@ export class MessageService { return firstName + ' ' + lastName } - // getFileFromDb() { - - // if(this.hasFile) { - // if (this.file.guid) { - // this.storage.get(this.file.guid).then((image) => { - // if(image != null) { - // this.file.image_url = image - // } - // }); - // } - // } - // } - async send(): Promise { this.sendAttempt++; @@ -186,6 +179,11 @@ export class MessageService { } async sendRequest(params) { + + if(params?.attachments?.image_url) { + delete params?.attachments?.image_url + } + this.ChatMethodsService.send(params).subscribe( (response: any) => { const ChatMessage = response.message @@ -222,11 +220,37 @@ export class MessageService { await this.save() } - async downloadFileMsg() { - const result = await this.NfService.beforeSendAttachment(this) - if(result) { + downloadFileMsg() { - } + let downloadFile = ""; + this.AttachmentsService.downloadFile(this.file.guid).subscribe(async (event) => { + + if (event.type === HttpEventType.DownloadProgress) { + + console.log('FILE TYPE 33', this.file.type) + } else if (event.type === HttpEventType.Response) { + if (this.file.type == "application/img") { + downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); + } else if (this.file.type === 'application/pdf') { + + downloadFile = event.body as any; + } else if (this.file.type == 'application/audio') { + downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''); + } + + this.attachments[0] = { + image_url: downloadFile, + name: this.attachments[0].name, + title: this.attachments[0].title, + title_link: downloadFile, + title_link_download: this.attachments[0].title_link_download, + ts: this.attachments[0].ts + } + + // save the changes to the storage + this.save() + } + }); } diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index bd46ff5a4..89d279ab6 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -21,6 +21,7 @@ import { ChatMethodsService } from './chat-methods.service' import { DeleteMessageModel, MessageModel } from '../../models/beast-orm' import { AESEncrypt } from '../aesencrypt.service' import { IncomingChatMessage, ChatMessageInterface, falseTypingMethod } from 'src/app/models/message.model'; +import { AttachmentsService } from 'src/app/services/attachments.service'; @Injectable({ providedIn: 'root' @@ -75,7 +76,8 @@ export class RoomService { private NfService: NfService, private ChatStorageService: ChatStorageService, private ChatMethodsService: ChatMethodsService, - private AESEncrypt: AESEncrypt + private AESEncrypt: AESEncrypt, + private AttachmentsService: AttachmentsService ) { this.NativeNotificationService.askForPermission() @@ -143,7 +145,7 @@ export class RoomService { } } - setData({members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt), _updatedAt }) { + setData({members, u, customFields = {}, id, name, t, lastMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService), _updatedAt }) { this.customFields = customFields this.id = id this.name = name @@ -670,7 +672,7 @@ export class RoomService { message = this.fix_updatedAt(message) - const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt) + const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory @@ -698,8 +700,6 @@ export class RoomService { } - - async ChatMessageIsPresentInTheView(ChatMessage:ChatMessageInterface) { let foundIndex; @@ -729,7 +729,7 @@ export class RoomService { async prepareCreate({message, save = true}): Promise { message = this.fix_updatedAt(message) - const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt) + const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory @@ -741,7 +741,7 @@ export class RoomService { simplePrepareMessage(message) { message = this.fix_updatedAt(message) - const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt) + const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService) wewMessage.setData(message) wewMessage.loadHistory = this.hasLoadHistory diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 789d0a453..8bf0bed1f 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -19,6 +19,7 @@ import { AuthService } from '../auth.service'; import { ChatStorageService } from './chat-storage.service' import { ChatMethodsService } from './chat-methods.service' import { AESEncrypt } from '../aesencrypt.service' +import { AttachmentsService } from 'src/app/services/attachments.service'; @Injectable({ providedIn: 'root' @@ -55,7 +56,8 @@ export class WsChatMethodsService { private authService: AuthService, private ChatStorageService: ChatStorageService, private ChatMethodsService:ChatMethodsService, - private AESEncrypt: AESEncrypt + private AESEncrypt: AESEncrypt, + private AttachmentsService:AttachmentsService ) { this.loggedUser = authService.ValidatedUserChat['data']; @@ -305,7 +307,7 @@ export class WsChatMethodsService { // create room if(!this.roomExist(roomId)) { - let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt) + let room:RoomService = new RoomService(this.WsChatService, new MessageService(this.storage, this.NfService, this.WsChatService, this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService , this.ChatStorageService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService) room.setData(setData) room.receiveMessage() room.getAllUsers = this.getUsers 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 8032aa779..ec38e0b7e 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.html +++ b/src/app/shared/chat/group-messages/group-messages.page.html @@ -92,7 +92,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 875afc895..7687b6519 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -420,46 +420,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 - - - - try { - this.storage.get('recordData').then((recordData) => { - console.log(recordData); - if(recordData.value.recordDataBase64.includes('data:audio')){ - this.audioRecorded = recordData.value.recordDataBase64; - } - else{ - this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; - } - }); - } catch (error) {} + 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) { @@ -979,41 +997,7 @@ 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; - - 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') - }); - } - - }); - - } - + msg.downloadFileMsg() } async openPreview(msg) { @@ -1037,5 +1021,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.html b/src/app/shared/chat/messages/messages.page.html index faee008e0..03901b8ea 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -109,7 +109,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 a27d82756..561c3b6a7 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -25,7 +25,6 @@ import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.serv import { WsChatService } from 'src/app/services/chat/ws-chat.service' import { MessageService } from 'src/app/services/chat/message.service'; import { AttachmentsService } from 'src/app/services/attachments.service'; - import { CameraService } from 'src/app/services/camera.service'; import { FileType } from 'src/app/models/fileType'; import { SearchPage } from 'src/app/pages/search/search.page'; @@ -270,7 +269,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } startRecording() { - console.log('Recording'); if (this.recording) { return; @@ -357,56 +355,69 @@ 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 let audioFile; - - try { - - 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}`; - } - }); - } catch (error) {} - + 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": "audio" }], temporaryData: formData }) - this.deleteRecording(); + }); + 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) { @@ -753,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) @@ -889,42 +900,7 @@ 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; - - 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 - } - - // save the changes to the storage - msg.save() - - - } - - }); - - // } - + msg.downloadFileMsg() } _arrayBufferToBase64( buffer ) { @@ -944,6 +920,13 @@ 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); 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{