mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
fix bug
This commit is contained in:
@@ -7,6 +7,8 @@ import { NfService } from 'src/app/services/chat/nf.service'
|
||||
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'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -26,7 +28,7 @@ export class MessageService {
|
||||
}
|
||||
|
||||
t = ''
|
||||
_id =''
|
||||
_id = ''
|
||||
_updatedAt
|
||||
file
|
||||
attachments
|
||||
@@ -44,13 +46,16 @@ export class MessageService {
|
||||
viewed = []
|
||||
received = []
|
||||
|
||||
messageSend = false
|
||||
|
||||
constructor(private storage: Storage,
|
||||
private NfService: NfService,
|
||||
private WsChatService: WsChatService) {
|
||||
private WsChatService: WsChatService,
|
||||
private ChatStorageService: ChatStorageService) {
|
||||
}
|
||||
|
||||
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData, localReference}:Message) {
|
||||
this.customFields = customFields
|
||||
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = []}:Message) {
|
||||
|
||||
this.channels = channels || []
|
||||
this.mentions = mentions || []
|
||||
this.msg = msg || ""
|
||||
@@ -65,9 +70,23 @@ 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
|
||||
this.messageSend = false
|
||||
} else {
|
||||
this.messageSend = true
|
||||
this.offline = false
|
||||
}
|
||||
|
||||
@@ -79,10 +98,6 @@ export class MessageService {
|
||||
}
|
||||
}
|
||||
|
||||
// if(typeof(this.file?.type)) {
|
||||
// this.hasFile = true
|
||||
// }
|
||||
|
||||
if(this.hasFile) {
|
||||
this.getFileFromDb()
|
||||
if(this.file.type != 'application/webtrix') {
|
||||
@@ -90,7 +105,6 @@ export class MessageService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.calDateDuration()
|
||||
}
|
||||
|
||||
@@ -121,10 +135,11 @@ export class MessageService {
|
||||
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)
|
||||
|
||||
if (environment.chatOffline) {
|
||||
|
||||
// this.redefinedMessage(ChatMessage)
|
||||
this.offline = false
|
||||
}
|
||||
|
||||
@@ -151,17 +166,21 @@ export class MessageService {
|
||||
|
||||
this.WsChatService.send({roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file, localReference: this.localReference}).then(({message, requestId}) => {
|
||||
|
||||
console.log('message', message)
|
||||
let ChatMessage = message.result
|
||||
this.messageSend = true
|
||||
|
||||
|
||||
this.redefinedMessage(ChatMessage)
|
||||
|
||||
if (environment.chatOffline) {
|
||||
// this.redefinedMessage(ChatMessage)
|
||||
this.offline = false
|
||||
}
|
||||
|
||||
|
||||
return new Promise((resolve, reject)=>{
|
||||
resolve(ChatMessage)
|
||||
})
|
||||
|
||||
})
|
||||
} else if(this.WsChatService.isLogin == false) {
|
||||
|
||||
@@ -185,12 +204,39 @@ export class MessageService {
|
||||
|
||||
}
|
||||
|
||||
redefinedMessage(ChatMessage) {
|
||||
async redefinedMessage(ChatMessage , update = true) {
|
||||
ChatMessage = this.NfService.fix_updatedAt(ChatMessage)
|
||||
|
||||
let reference
|
||||
if(this._id) {
|
||||
reference = '_id'
|
||||
} else {
|
||||
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)
|
||||
|
||||
|
||||
if(update) {
|
||||
await this.ChatStorageService.updateMessageDB(ChatMessage, this.rid, reference)
|
||||
}
|
||||
|
||||
this.setData(ChatMessage)
|
||||
}
|
||||
|
||||
|
||||
async downloadFileMsg() {
|
||||
const result = await this.NfService.beforeSendAttachment(this)
|
||||
if(result) {
|
||||
@@ -207,43 +253,54 @@ export class MessageService {
|
||||
return this.u.username != SessionStore.user.RochetChatUser
|
||||
}
|
||||
|
||||
receptorReceive() {
|
||||
|
||||
if(this.messageReceptor()) {
|
||||
let newMessage = {
|
||||
rid: this._id,
|
||||
msg: this.msg,
|
||||
attachments: this.attachments,
|
||||
file: this.file,
|
||||
localReference: this.localReference,
|
||||
viewed: this.viewed.push('123'),
|
||||
received: this.viewed.push('123'),
|
||||
}
|
||||
|
||||
this.WsChatService.updateMessage(newMessage).then(()=>{
|
||||
console.log('newMessage', newMessage)
|
||||
})
|
||||
}
|
||||
|
||||
async delete() {
|
||||
await this.ChatStorageService.deleteMessageFromDb(this._id, this.rid)
|
||||
}
|
||||
|
||||
receptorView() {
|
||||
if(this.messageReceptor()) {
|
||||
let newMessage = {
|
||||
rid: this._id,
|
||||
msg: this.msg,
|
||||
attachments: this.attachments,
|
||||
file: this.file,
|
||||
localReference: this.localReference,
|
||||
viewed: this.viewed.push('123'),
|
||||
received: this.viewed.push('123'),
|
||||
}
|
||||
|
||||
this.WsChatService.updateMessage(newMessage).then(()=>{
|
||||
console.log('newMessage', newMessage)
|
||||
})
|
||||
isSenderIsNotMe(ChatMessage) {
|
||||
return SessionStore.user.RochetChatUser != ChatMessage.u.username
|
||||
}
|
||||
|
||||
messageOwnerById(id) {
|
||||
return SessionStore.user.RochetChatUser != this.u.username
|
||||
}
|
||||
|
||||
private getChatObj() {
|
||||
return {
|
||||
channels: this.channels,
|
||||
mentions: this.mentions,
|
||||
msg: this.msg,
|
||||
rid: this.rid,
|
||||
ts: this.ts,
|
||||
u: this.u,
|
||||
_id: this._id,
|
||||
_updatedAt: this._updatedAt,
|
||||
messageSend: this.messageSend,
|
||||
offline: this.offline,
|
||||
viewed: this.viewed,
|
||||
received: this.received,
|
||||
localReference: this.localReference
|
||||
}
|
||||
}
|
||||
|
||||
async addMessageDB() {
|
||||
|
||||
const message = this.getChatObj()
|
||||
|
||||
await this.ChatStorageService.addMessageDB(message, this.rid)
|
||||
}
|
||||
|
||||
async save() {
|
||||
const message = this.getChatObj()
|
||||
|
||||
let reference
|
||||
if(this._id) {
|
||||
reference = '_id'
|
||||
} else {
|
||||
reference = 'localReference'
|
||||
}
|
||||
|
||||
await this.ChatStorageService.updateMessageDB(message, this.rid, reference)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user