This commit is contained in:
tiago.kayaya
2022-03-29 00:03:54 +01:00
parent c4e9641ff5
commit 3a5f630a65
4 changed files with 34 additions and 27 deletions
+9 -9
View File
@@ -1,7 +1,7 @@
import { models } from 'beast-orm' import { models } from 'beast-orm'
import { AESEncrypt } from '../services/aesencrypt.service' import { AESEncrypt } from '../services/aesencrypt.service'
const _AESEncrypt = new AESEncrypt() const _AESEncrypt = new AESEncrypt()
const { ArrayField, JsonField} = models.indexedDB.fields const { ArrayField, JsonField} = models.indexedDB.fields
export class MessageModel extends models.Model { export class MessageModel extends models.Model {
@@ -10,17 +10,17 @@ export class MessageModel extends models.Model {
mentions = ArrayField() mentions = ArrayField()
msg = models.CharField() msg = models.CharField()
rid = models.CharField() rid = models.CharField()
ts = models.CharField() ts = models.CharField({blank:true})
u = JsonField() u = JsonField()
_id = models.CharField({unique:true}) _id = models.CharField()
_updatedAt = models.CharField() _updatedAt = models.CharField()
messageSend = models.BooleanField() messageSend = models.BooleanField()
offline = models.BooleanField() offline = models.BooleanField()
viewed = ArrayField() viewed = ArrayField({blank:true})
received = ArrayField() received = ArrayField({blank:true})
localReference = models.CharField({blank:true}) localReference = models.CharField({blank:true})
attachments = ArrayField() attachments = ArrayField({blank:true})
file = ArrayField() file = ArrayField({blank:true})
} }
@@ -38,7 +38,7 @@ export class DeleteMessageModel extends models.Model {
models.register({ models.register({
databaseName: 'chat-storage', databaseName: 'chat-storage',
type: 'indexedDB', type: 'indexedDB',
version: 1, version: 1,
models: [MessageModel, DeleteMessageModel] models: [MessageModel, DeleteMessageModel]
}) })
+3 -1
View File
@@ -392,7 +392,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
const roomId = this.roomId const roomId = this.roomId
let audioFile; let audioFile;
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then((recordData) => {
console.log(recordData);
audioFile = recordData; audioFile = recordData;
if(recordData.value.recordDataBase64.includes('data:audio')){ if(recordData.value.recordDataBase64.includes('data:audio')){
this.audioRecorded = recordData.value.recordDataBase64; this.audioRecorded = recordData.value.recordDataBase64;
@@ -401,6 +401,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`;
} }
console.log(this.audioRecorded);
//Converting base64 to blob //Converting base64 to blob
const encodedData = btoa(this.audioRecorded); const encodedData = btoa(this.audioRecorded);
const blob = this.base64toBlob(encodedData, recordData.value.mimeType) const blob = this.base64toBlob(encodedData, recordData.value.mimeType)
+13 -12
View File
@@ -22,10 +22,10 @@ export class MessageService {
msg = '' msg = ''
rid = '' rid = ''
ts = {} ts = {}
u = { u = {
name: '', name: '',
username: '', username: '',
_id: "" _id: ""
} }
@@ -138,7 +138,7 @@ export class MessageService {
if(!this.hasFile) { if(!this.hasFile) {
const params = {roomId:this.rid, msg:this.msg, localReference: this.localReference} const params = {roomId:this.rid, msg:this.msg, localReference: this.localReference}
await this.sendRequest(params) await this.sendRequest(params)
} else { } else {
@@ -178,7 +178,7 @@ export class MessageService {
return new Promise((resolve, reject)=>{ return new Promise((resolve, reject)=>{
reject(false) reject(false)
}) })
} }
} }
@@ -197,12 +197,12 @@ export class MessageService {
this.WsChatService.registerCallback({ this.WsChatService.registerCallback({
type: 'reConnect', type: 'reConnect',
funx: async ()=> { funx: async ()=> {
this.WsChatService.send(params).then(({message, requestId}) => { this.WsChatService.send(params).then(({message, requestId}) => {
let ChatMessage = message.result let ChatMessage = message.result
this.messageSend = true this.messageSend = true
this.redefinedMessage(ChatMessage) this.redefinedMessage(ChatMessage)
}) })
return true return true
} }
@@ -213,7 +213,7 @@ export class MessageService {
async redefinedMessage(ChatMessage , update = true) { async redefinedMessage(ChatMessage , update = true) {
ChatMessage = this.NfService.fix_updatedAt(ChatMessage) ChatMessage = this.NfService.fix_updatedAt(ChatMessage)
const message = this.getChatObj() const message = this.getChatObj()
ChatMessage = Object.assign(message, ChatMessage) ChatMessage = Object.assign(message, ChatMessage)
@@ -241,7 +241,7 @@ export class MessageService {
} }
async delateDB() { async delateDB() {
// alert('delete data') // alert('delete data')
const message = await MessageModel.get({_id: this._id}) const message = await MessageModel.get({_id: this._id})
await message.delete() await message.delete()
@@ -261,8 +261,8 @@ export class MessageService {
return { return {
channels: this.channels, channels: this.channels,
mentions: this.mentions, mentions: this.mentions,
//msg: this.AESEncrypt.encrypt(this.msg, SessionStore.user.RochetChatUser), //msg: this.AESEncrypt.encrypt(this.msg, SessionStore.user.RochetChatUser),
msg:this.msg, msg:this.msg,
rid: this.rid, rid: this.rid,
ts: this.ts, ts: this.ts,
u: this.u, u: this.u,
@@ -294,6 +294,7 @@ export class MessageService {
async save() { async save() {
const message = this.getChatObj() const message = this.getChatObj()
console.log(message);
await MessageModel.update(message) await MessageModel.update(message)
@@ -257,11 +257,13 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.storage.get('recordData').then((recordData) => { this.storage.get('recordData').then((recordData) => {
console.log(recordData); console.log(recordData);
if(recordData.value.recordDataBase64.includes('data:audio')){ if(recordData){
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64); if(recordData.value.recordDataBase64.includes('data:audio')){
} this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64);
else{ }
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`); else{
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`);
}
} }
}); });
} }
@@ -389,6 +391,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`; this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`;
} }
console.log(this.audioRecorded);
//Converting base64 to blob //Converting base64 to blob
const encodedData = btoa(this.audioRecorded); const encodedData = btoa(this.audioRecorded);
const blob = this.base64toBlob(encodedData, recordData.value.mimeType) const blob = this.base64toBlob(encodedData, recordData.value.mimeType)