This commit is contained in:
Peter Maquiran
2022-02-08 17:44:15 +01:00
parent cef4c39d6e
commit 6a5a486293
15 changed files with 144 additions and 80 deletions
+47 -6
View File
@@ -5,6 +5,7 @@ import { SessionStore } from 'src/app/store/session.service';
import { capitalizeTxt } from 'src/plugin/text'
import { NfService } from 'src/app/services/chat/nf.service'
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { type } from 'os';
@Injectable({
providedIn: 'root'
})
@@ -27,6 +28,9 @@ export class MessageService {
temporaryData: any = {}
hasFile = false
hasSendAttachment = false
sendAttempt = 0
uploadingFile = false
errorUploadingAttachment = false
constructor(private storage: Storage,
private NfService: NfService,
@@ -90,34 +94,71 @@ export class MessageService {
}
}
sendFile() {
if(this.file == null && this.attachments == null) {
async send() {
this.sendAttempt++;
if(!this.hasFile) {
console.log('simple send')
this.WsChatService.send({roomId:this.rid, msg:this.msg}).then((data: any) => {
let ChatMessage = data.result
this.redefinedMessage(this, ChatMessage)
this.offline = false
})
} else {
console.log('complex send')
const result = this.NfService.beforeSendAttachment(this)
this.uploadingFile = true
if(result) {
let uploadSuccessfully = false
if(this.hasSendAttachment == false) {
uploadSuccessfully = await this.NfService.beforeSendAttachment(this)
}
this.uploadingFile = false
if(uploadSuccessfully || this.hasSendAttachment == false) {
this.hasSendAttachment = true
this.errorUploadingAttachment = false
this.temporaryData = {}
this.WsChatService.send({roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file}).then((data: any) => {
console.log('send sucees', data.result)
let ChatMessage = data.result
this.redefinedMessage(this, ChatMessage)
this.offline = false
})
} else if(this.WsChatService.isLogin == false) {
alert('registerCallback')
this.WsChatService.registerCallback({
type: 'reConnect',
funx:()=> {
alert('reConnect')
// this.send()
return true
}
})
} else if(uploadSuccessfully == false) {
alert('this.WsChatService.isLogin '+ this.WsChatService.isLogin+ '')
this.errorUploadingAttachment = true
}
}
}
redefinedMessage(messagem, ChatMessage){
redefinedMessage(messagem, ChatMessage) {
this.setData(ChatMessage)
}
async downloadFileMsg() {
const result = await this.NfService.beforeSendAttachment(this)
if(result) {
}
}
}