This commit is contained in:
Peter Maquiran
2022-02-10 14:24:27 +01:00
2 changed files with 38 additions and 25 deletions
+23 -10
View File
@@ -112,10 +112,7 @@ export class RoomService {
});
}
if(this.isSenderIsNotMe(ChatMessage)) {
// this.addMessageDB(ChatMessage)
}
this.addMessageDB(ChatMessage)
this.scrollDown()
}
@@ -137,17 +134,34 @@ export class RoomService {
}
addMessageDB(ChatMessage) {
async addMessageDB(ChatMessage) {
if (environment.chatOffline) {
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
if(!Array.isArray(messages)) {
messages = []
}
if(!ChatMessage._id && environment.chatOffline) {
delete ChatMessage.temporaryData
messages.push(ChatMessage)
this.storage.set('chatmsg' + this.id, messages)
} else {
const find = messages.find((message)=> {
return message._id == ChatMessage._id
})
if(!find) {
delete ChatMessage.temporaryData
messages.push(ChatMessage)
this.storage.set('chatmsg' + this.id, messages)
}
}
})
}
}
async receiveMessageDelete() {
@@ -349,23 +363,22 @@ export class RoomService {
}
// runs onces only
async loadHistory({limit = 100, forceUpdate = false }) {
async loadHistory({limit = 50, forceUpdate = false }) {
if(forceUpdate == false) {
if (this.hasLoadHistory) {
return false
}
}
this.restoreMessageFromDB()
await this.restoreMessageFromDB()
await this.WsChatService.loadHistory(this.id, limit).then( async (chatHistory:chatHistory) => {
console.log('loadHistory', chatHistory)
await chatHistory.result.messages.reverse().forEach( async (message) => {
this.prepareMessage(message)
this.messages = this.sortService.sortDate(this.messages, '_updatedAt')
})