This commit is contained in:
Peter Maquiran
2022-03-04 14:20:39 +01:00
parent f5880fec2a
commit c112080917
6 changed files with 205 additions and 89 deletions
+58 -44
View File
@@ -8,6 +8,8 @@ import { WsChatService } from 'src/app/services/chat/ws-chat.service';
import { environment } from 'src/environments/environment';
import { showDateDuration } from 'src/plugin/showDateDuration';
import { ChatStorageService } from './chat-storage.service'
import { ChatMethodsService } from './chat-methods.service'
@Injectable({
providedIn: 'root'
@@ -51,7 +53,8 @@ export class MessageService {
constructor(private storage: Storage,
private NfService: NfService,
private WsChatService: WsChatService,
private ChatStorageService: ChatStorageService) {
private ChatStorageService: ChatStorageService,
private ChatMethodsService: ChatMethodsService) {
}
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = []}:Message) {
@@ -70,17 +73,9 @@ export class MessageService {
this.temporaryData = temporaryData
this.localReference = localReference || null
if(this.msg.includes('***********')) {
console.log('-=-=--=-=-=',JSON.stringify(viewed), JSON.stringify(this.viewed))
}
this.viewed = [...new Set([...viewed,...this.viewed])];
this.received = [...new Set([...received,...this.received])];
if(this.msg.includes('***********')) {
console.log('-=-=--=-=-=',JSON.stringify(viewed), JSON.stringify(this.viewed))
}
if(!this.ts) {
this.offline = true
@@ -133,20 +128,37 @@ export class MessageService {
this.sendAttempt++;
if(!this.hasFile) {
this.WsChatService.send({roomId:this.rid, msg:this.msg, localReference: this.localReference}).then(({message, requestId}) => {
let ChatMessage = message.result
this.messageSend = true
this.redefinedMessage(ChatMessage)
const params = {roomId:this.rid, msg:this.msg, localReference: this.localReference}
this.ChatMethodsService.send(params).subscribe(
(response: any) => {
const ChatMessage = response.message
this.messageSend = true
this.redefinedMessage(ChatMessage)
},
(error) => {
this.WsChatService.registerCallback({
type: 'reConnect',
funx: async ()=> {
this.WsChatService.send(params).then(({message, requestId}) => {
let ChatMessage = message.result
this.messageSend = true
this.redefinedMessage(ChatMessage)
})
return true
}
})
if (environment.chatOffline) {
this.offline = false
}
)
return new Promise((resolve, reject)=>{
resolve(ChatMessage)
})
})
} else {
this.uploadingFile = true
@@ -164,30 +176,43 @@ export class MessageService {
this.temporaryData = {}
this.WsChatService.send({roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file, localReference: this.localReference}).then(({message, requestId}) => {
const params = {roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file, localReference: this.localReference}
this.ChatMethodsService.send(params).subscribe(
(response: any) => {
const ChatMessage = response.message
this.messageSend = true
this.redefinedMessage(ChatMessage)
},
(error) => {
let ChatMessage = message.result
this.messageSend = true
this.redefinedMessage(ChatMessage)
if (environment.chatOffline) {
this.offline = false
this.WsChatService.registerCallback({
type: 'reConnect',
funx: async ()=> {
this.WsChatService.send(params).then(({message, requestId}) => {
let ChatMessage = message.result
this.messageSend = true
this.redefinedMessage(ChatMessage)
})
return true
}
})
}
)
return new Promise((resolve, reject)=>{
resolve(ChatMessage)
})
})
} else if(this.WsChatService.isLogin == false) {
this.WsChatService.registerCallback({
type: 'reConnect',
funx: async ()=> {
return await this.send()
this.send()
return true
}
})
@@ -214,19 +239,8 @@ export class MessageService {
reference = 'localReference'
}
const message = this.getChatObj()
// const viewed = [...new Set([...ChatMessage.viewed,...this.viewed])];
// const received = [...new Set([...ChatMessage.received,...this.received])];
// if(ChatMessage.msg.includes('***********')) {
// console.log('redefinedMessage')
// console.log(JSON.stringify(ChatMessage))
// console.log(JSON.stringify(message))
// console.log(JSON.stringify(Object.assign(message, ChatMessage)))
// }
ChatMessage = Object.assign(message, ChatMessage)