This commit is contained in:
Peter Maquiran
2023-01-24 15:56:47 +01:00
parent 0748612054
commit fbd50137f3
153 changed files with 5997 additions and 953 deletions
+35 -9
View File
@@ -61,6 +61,9 @@ export class MessageService {
downloadAttachmentsTemp = 0;
UploadAttachmentsTemp = 0;
manualRetry = false
origin: 'history' | 'stream' | 'local'
rowInstance: MessageModel
constructor(
private NfService: NfService,
@@ -72,7 +75,7 @@ export class MessageService {
private ChatSystemService: ChatSystemService) {
}
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference = 'out-'+uuidv4() , viewed = [], received = [], delate = false, delateRequest =false, from, sendAttempt = 0 }:Message) {
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference = 'out-'+uuidv4() , viewed = [], received = [], delate = false, delateRequest =false, from, sendAttempt = 0, origin }:Message) {
this.channels = channels || []
this.mentions = mentions || []
@@ -90,6 +93,7 @@ export class MessageService {
this.delate = delate
this.delateRequest = delateRequest
this.sendAttempt = 0
this.origin = origin
if(this.attachments?.length >= 1 && attachments?.length >= 1) {
this.attachments[0] = Object.assign(this.attachments[0], attachments[0])
@@ -257,6 +261,7 @@ export class MessageService {
} catch (error) {
this.uploadingFile = false
this.errorUploadingAttachment = true
this.UploadAttachmentsTemp++
console.error('beforeSendAttachment error:', error)
}
@@ -441,9 +446,11 @@ export class MessageService {
async delateDB() {
const message = await MessageModel.get({id: this.id})
await message.delete()
if(!this.rowInstance) {
this.rowInstance = await this.getRowInstance()
}
await this.rowInstance.delete()
}
@@ -467,6 +474,7 @@ export class MessageService {
u: this.u,
_id: this._id,
id: this.id,
origin: this.origin,
_updatedAt: this._updatedAt,
messageSend: this.messageSend,
offline: this.offline,
@@ -489,6 +497,7 @@ export class MessageService {
delete message.id
const createdMessage = await MessageModel.create(message)
this.rowInstance = createdMessage
this.id = createdMessage.id
if(this.earlySave) {
@@ -497,8 +506,8 @@ export class MessageService {
}
}
async saveChanges() {
async getRowInstance () {
if(this.save) {
const message = this.getChatObj()
@@ -516,12 +525,29 @@ export class MessageService {
a = await MessageModel.get({id: this.id})
}
if(a) {
for( const [name, value] of Object.entries(message)) {
a[name] = value
}
await a.save()
return a
}
}
async saveChanges() {
if(!this.rowInstance) {
this.rowInstance = await this.getRowInstance()
}
if(this.save && this.rowInstance) {
const message = this.getChatObj()
if(!message.id) {
delete message.id
}
for( const [name, value] of Object.entries(message)) {
this.rowInstance[name] = value
}
await this.rowInstance.save()
} else {
this.earlySave = true