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
@@ -114,11 +114,15 @@
<div (click)="openPreview(msg)" class="file-details add-ellipsis cursor-pointer" *ngIf="msg.file">
<div *ngIf="!msg.attachments[0].image_url">
<ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button">
<ion-icon *ngIf="msg.attachments[0].type != 'webtrix'" name="document" class="file-icon"></ion-icon>
<ion-icon *ngIf="msg.attachments[0].type == 'webtrix'" src="assets/icon/webtrix.svg" class="file-icon"></ion-icon>
<ion-label>{{file.title}}</ion-label>
<ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon>
<ion-label>{{ file.title}}</ion-label>
<ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="( msg.downloadLoader == true || msg.uploadingFile == true )" class="icon-download" src="assets/gif/theme/{{ThemeService.currentTheme}}/Blocks-loader.svg" slot="end"></ion-icon>
</ion-item>
</div>
<div *ngIf="msg.attachments[0].image_url">
@@ -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);
@@ -114,11 +114,14 @@
<div *ngIf="!msg.attachments[0].image_url">
<ion-item class="add-attachment-bg-color" shape="round" lines="none" type="button">
<ion-icon *ngIf="msg.attachments[0].type != 'webtrix'" name="document" class="file-icon"></ion-icon>
<ion-icon *ngIf="msg.attachments[0].type == 'webtrix'" src="assets/icon/webtrix.svg" class="file-icon"></ion-icon>
<ion-label>{{file.title}}</ion-label>
<ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon>
<ion-label>{{ file.title}}</ion-label>
<ion-icon *ngIf="ThemeService.currentTheme == 'default' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' && msg.attachments[0].type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon>
<ion-icon *ngIf="( msg.downloadLoader == true || msg.uploadingFile == true )" class="icon-download" src="assets/gif/theme/{{ThemeService.currentTheme}}/Blocks-loader.svg" slot="end"></ion-icon>
</ion-item>
</div>
+22 -32
View File
@@ -401,31 +401,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
})
} */
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')) {
@@ -439,7 +418,7 @@ export class MessagesPage 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);
@@ -455,7 +434,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
"title_link_download": true,
"type": "audio"
}],
temporaryData: formData
temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
})
});
@@ -658,14 +640,12 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
source: CameraSource.Camera
});
const blob = this.dataURItoBlob('data:image/jpeg;base64,' + file.base64String)
console.log('data:image/jpeg;base64,' + file.base64String)
const base64 = 'data:image/jpeg;base64,' + file.base64String
const blob = this.dataURItoBlob(base64)
const formData = new FormData();
formData.append("blobFile", blob);
// console.log('capturedImage', capturedImage);
this.ChatSystemService.getDmRoom(roomId).send({
file: {
"type": "application/img",
@@ -676,7 +656,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
"text": "description",
"title_link_download": false,
}],
temporaryData: formData
temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
})
}
@@ -789,7 +773,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
"title": file.path,
"text": "description",
"title_link_download": false,
}]
}],
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
})
}
@@ -813,7 +800,7 @@ export class MessagesPage 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();
@@ -831,7 +818,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
// "text": "description",
"title_link_download": false,
}],
temporaryData: formData
temporaryData: formData,
attachmentsModelData: {
fileBase64: await this.fileService.blobToBase64(blob),
}
});
} else {