fixe chat message

This commit is contained in:
Peter Maquiran
2023-06-29 16:04:44 +01:00
parent 8c02c5abb8
commit 246ea2e4a6
16 changed files with 356 additions and 227 deletions
@@ -16,7 +16,6 @@ import { EventPerson } from 'src/app/models/eventperson.model';
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
import { ThemeService } from 'src/app/services/theme.service'
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
import { SqliteService } from 'src/app/services/sqlite.service';
import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
import { FileType } from 'src/app/models/fileType';
import { Storage } from '@ionic/storage';
@@ -463,32 +462,12 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.ChatSystemService.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) => {
this.storage.get('recordData').then(async (recordData) => {
audioFile = recordData;
if (recordData?.value?.recordDataBase64.includes('data:audio')) {
@@ -500,7 +479,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
//Converting base64 to blob
const encodedData = btoa(this.audioRecorded);
const blob = this.base64toBlob(encodedData, recordData.value.mimeType)
const blob = this.fileService.base64toBlob(encodedData, recordData.value.mimeType)
const formData = new FormData();
formData.append("blobFile", blob);
@@ -516,7 +495,10 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
"title_link_download": true,
"type": "audio"
}],
temporaryData: formData
temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
})
});
@@ -670,7 +652,10 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
"title": capturedImageTitle,
"text": "description",
"title_link_download": false,
}]
}],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
})
}
@@ -740,7 +725,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
const encodedData = btoa(JSON.stringify(await this.getBase64(file).catch ((error) => {
console.error(error);
})));
const blob = this.base64toBlob(encodedData, file.type)
const blob = this.fileService.base64toBlob(encodedData, file.type)
const formData = new FormData();
formData.append('blobFile', blob);
@@ -757,7 +742,10 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
// "text": "description",
"title_link_download": false,
}],
temporaryData: formData
temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
});
} else {
@@ -864,65 +852,6 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
});
}
/* async actionSheet() {
const actionSheet = await this.actionSheetController.create({
cssClass: 'my-custom-class',
buttons: [{
text: 'Sair do grupo',
handler: () => {
}
}, {
text: 'Alterar nome do grupo1',
handler: () => {
this.openChangeGroupName()
}
}, {
text: 'Apagar o grupo',
handler: () => {
}
},
]
});
await actionSheet.present();
}
*/
// getRoomMessageDB(roomId) {
// if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
// } else {
// this.sqlservice.getAllChatMSG(roomId).then((msg: any) => {
// let chatmsgArray = [];
// let array = []
// msg.forEach(element => {
// let msgChat = {
// _id: element.Id,
// attachments: this.isJson(element.Attachments),
// channels: this.isJson(element.Channels),
// file: this.isJson(element.File),
// mentions: this.isJson(element.Mentions),
// msg: element.Msg,
// rid: element.Rid,
// ts: element.Ts,
// u: this.isJson(element.U),
// _updatedAt: element.UpdatedAt,
// image_url: this.isJson(element.image_url)
// }
// chatmsgArray.push(msgChat)
// });
// // this.messages = chatmsgArray;
// })
// }
// }
isJson(str) {
try {
JSON.parse(str);