This commit is contained in:
Peter Maquiran
2022-02-10 18:07:06 +01:00
parent 382ee2fd1b
commit 08da9419bb
12 changed files with 66 additions and 34 deletions
+14 -6
View File
@@ -34,13 +34,14 @@ export class MessageService {
errorUploadingAttachment = false
loadHistory = false
duration = ''
localReference = null
constructor(private storage: Storage,
private NfService: NfService,
private WsChatService: WsChatService) {
}
setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData}:Message) {
setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData, localReference}:Message) {
this.customFields = customFields
this.channels = channels || []
this.mentions = mentions || []
@@ -54,6 +55,7 @@ export class MessageService {
this.file = file
this.attachments = attachments
this.temporaryData = temporaryData
this.localReference = localReference || null
if(!this.ts) {
this.offline = true
@@ -104,8 +106,8 @@ export class MessageService {
this.sendAttempt++;
if(!this.hasFile) {
this.WsChatService.send({roomId:this.rid, msg:this.msg}).then((data: any) => {
let ChatMessage = data.result
this.WsChatService.send({roomId:this.rid, msg:this.msg, requestId: this.localReference}).then(({message, requestId}) => {
let ChatMessage = message.result
if (environment.chatOffline) {
this.redefinedMessage(this, ChatMessage)
@@ -132,8 +134,8 @@ export class MessageService {
this.errorUploadingAttachment = false
this.temporaryData = {}
this.WsChatService.send({roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file}).then((data: any) => {
let ChatMessage = data.result
this.WsChatService.send({roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file, requestId: this.localReference}).then(({message, requestId}) => {
let ChatMessage = message.result
if (environment.chatOffline) {
this.redefinedMessage(this, ChatMessage)
@@ -154,14 +156,19 @@ export class MessageService {
})
} else if(uploadSuccessfully == false) {
this.errorUploadingAttachment = true
return new Promise((resolve, reject)=>{
reject(false)
})
}
}
}
redefinedMessage(message, ChatMessage) {
ChatMessage = this.NfService.fix_updatedAt(ChatMessage)
this.setData(ChatMessage)
}
@@ -178,4 +185,5 @@ export class MessageService {
this.duration = showDateDuration(date || this._updatedAt);
}
}