This commit is contained in:
Peter Maquiran
2022-02-09 14:07:34 +01:00
parent 012c5ccce6
commit 9a35ea30f0
6 changed files with 26 additions and 31 deletions
+19 -20
View File
@@ -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
}