diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 97ffd7398..fd74754e7 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -147,7 +147,9 @@ export class RoomService { addMessageDB(ChatMessage) { this.storage.get('chatmsg' + this.id).then((messages: any = []) => { - if(messages==null) messages = [] + if(!Array.isArray(messages)) { + messages = [] + } delete ChatMessage.temporaryData messages.push(ChatMessage) @@ -199,7 +201,9 @@ export class RoomService { */ private deleteMessageFromDb(id) { this.storage.get('chatmsg' + this.id).then((messages: any = []) => { - if(messages==null) messages = [] + if(!Array.isArray(messages)) { + messages = [] + } messages.forEach((message, index) => { @@ -330,7 +334,9 @@ export class RoomService { async restoreMessageFromDB() { await this.storage.get('chatmsg' + this.id).then( async (messages = []) => { - if(messages==null) messages = [] + if(!Array.isArray(messages)) { + messages = [] + } await messages.forEach( async (ChatMessage, index) => { const wewMessage = this.prepareMessage(ChatMessage, false) @@ -368,9 +374,9 @@ export class RoomService { this.prepareMessage(message) } - }); + }) - this.storage.set('chatmsg' + this.id, chatHistory) + this.storage.set('chatmsg' + this.id, chatHistory.result.messages) }) setTimeout(() => {