mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
save
This commit is contained in:
@@ -5,7 +5,6 @@ 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'
|
||||
})
|
||||
|
||||
@@ -93,11 +93,14 @@ export class RoomService {
|
||||
(ChatMessage) => {
|
||||
ChatMessage = ChatMessage.fields.args[0]
|
||||
|
||||
if(environment.chatOffline == false || this.isSenderIsNotMe(ChatMessage)) {
|
||||
|
||||
ChatMessage = this.fix_updatedAt(ChatMessage)
|
||||
console.log('recivemessage', ChatMessage)
|
||||
|
||||
ChatMessage = this.fix_updatedAt(ChatMessage)
|
||||
// console.log('recivemessage', ChatMessage)
|
||||
|
||||
const messageIsFound = this.messages.find((message) => {
|
||||
message._id == ChatMessage._id
|
||||
})
|
||||
|
||||
if(!messageIsFound) {
|
||||
const message = this.prepareMessage(ChatMessage)
|
||||
|
||||
this.lastMessage = message
|
||||
@@ -114,8 +117,8 @@ export class RoomService {
|
||||
});
|
||||
|
||||
this.addMessageDB(ChatMessage)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
@@ -323,10 +326,10 @@ export class RoomService {
|
||||
if(messages==null) messages = []
|
||||
|
||||
await messages.forEach( async (ChatMessage, index) => {
|
||||
const wewMessage = this.prepareMessage(ChatMessage)
|
||||
const wewMessage = this.prepareMessage(ChatMessage, false)
|
||||
|
||||
if(wewMessage.offline == true) {
|
||||
wewMessage.send()
|
||||
if(wewMessage.offline == false) {
|
||||
this.prepareMessage(ChatMessage)
|
||||
}
|
||||
|
||||
});
|
||||
@@ -335,7 +338,6 @@ export class RoomService {
|
||||
this.scrollDown()
|
||||
}, 50)
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -344,7 +346,7 @@ export class RoomService {
|
||||
|
||||
if (this.hasLoadHistory) { return false }
|
||||
|
||||
await this.restoreMessageFromDB()
|
||||
this.restoreMessageFromDB()
|
||||
|
||||
await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
|
||||
console.log('loadHistory', chatHistory)
|
||||
@@ -352,13 +354,6 @@ export class RoomService {
|
||||
|
||||
await chatHistory.result.messages.reverse().forEach( async (message) => {
|
||||
this.prepareMessage(message)
|
||||
|
||||
// const result = alasql(`SELECT * FROM ? WHERE _id = "${message._id}" `,[ this.messages]);
|
||||
// if(result.length == 0) {
|
||||
// this.prepareMessage(message)
|
||||
// this.storage.set('chatmsg' + this.id, chatHistory.result.messages.concat([message]))
|
||||
// }
|
||||
|
||||
});
|
||||
|
||||
})
|
||||
@@ -372,11 +367,15 @@ export class RoomService {
|
||||
|
||||
|
||||
|
||||
prepareMessage(message): MessageService {
|
||||
prepareMessage(message, save = true): MessageService {
|
||||
message = this.fix_updatedAt(message)
|
||||
const wewMessage = new MessageService(this.storage, this.NfService, this.WsChatService)
|
||||
wewMessage.setData(message)
|
||||
this.messages.push(wewMessage)
|
||||
|
||||
if (save) {
|
||||
this.messages.push(wewMessage)
|
||||
}
|
||||
|
||||
return wewMessage
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ export class WsChatMethodsService {
|
||||
}
|
||||
})
|
||||
|
||||
// console.log("ROOMS" + JSON.stringify(rooms))
|
||||
|
||||
// this.WsChatService.registerCallback({
|
||||
// type:'Onmessage',
|
||||
// funx:(message) => {
|
||||
@@ -85,10 +85,8 @@ export class WsChatMethodsService {
|
||||
// }, 100)
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
// if(message.msg =='changed' && message.collection == "stream-notify-room") {
|
||||
// if(message.fields.eventName.includes('deleteMessage')){
|
||||
// } else if(message.msg =='changed' && message.collection == "stream-notify-room") {
|
||||
// if(message.fields.eventName.includes('deleteMessage')) {
|
||||
// // delete message
|
||||
// const DeletedMessageId = message.fields.args[0]._id;
|
||||
|
||||
@@ -96,6 +94,8 @@ export class WsChatMethodsService {
|
||||
// this.sortRoomList()
|
||||
// }, 100)
|
||||
|
||||
// } else if(message.fields.eventName.includes('typing')) {
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -614,7 +614,6 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
||||
let id = params.requestId || params.key || uuidv4()
|
||||
this.wsCallbacks[id] = params
|
||||
this.n++
|
||||
console.log('n', this.n)
|
||||
return id
|
||||
},
|
||||
connect:()=> {
|
||||
@@ -680,6 +679,8 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
||||
onmessage: async (event: any)=> {
|
||||
const data = JSON.parse(event.data)
|
||||
|
||||
console.log('data', data)
|
||||
|
||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||
if(value.type== 'Onmessage') {
|
||||
const dontRepeat = await value.funx(data)
|
||||
|
||||
Reference in New Issue
Block a user