mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
fix chat
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user