diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 7f787bca6..aada27c11 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -69,10 +69,10 @@ export class RoomService { // save to ionic storage - this.storage.get('chatmsg'+ this.id).then((messages: any) => { + this.storage.get('chatmsg' + this.id).then((messages: any) => { const newListMessages = messages.push(ChatMessage) - this.storage.set('chatmsg'+ this.id, newListMessages).then((value) => { + this.storage.set('chatmsg' + this.id, newListMessages).then((value) => { console.log('MSG SAVED ON STORAGE', value) }); }) @@ -85,35 +85,54 @@ export class RoomService { this.WsChatService.send(this.id, msg) } + getMsgFromDB() { + + this.storage.get('chatmsg' + this.id).then((message) => { + + message.forEach(message => { + + if (message.file) { + if (message.file.guid) { + this.storage.get(message.file.guid).then((image) => { + console.log('IMAGE FROM STORAGE', image) + message.file.image_url = image + }); + } + } + + let mmessage = this.fix_updatedAt(message) + console.log('FROM DB WEB', mmessage) + const wewMessage = new MessageService() + wewMessage.setData(mmessage) + this.massages.push(wewMessage) + console.log('loadHistory 222', this.massages) + }); + }) + } + // runs onces only loadHistory(limit = 100) { if (this.hasLoadHistory) { return false } // ionic store - this.storage.get('chatmsg'+ this.id).then((message) => { - message.forEach(message => { - console.log('FROM DB WEB', message) - message = this.fix_updatedAt(message) - const wewMessage = new MessageService() - wewMessage.setData(message) - this.massages.push(wewMessage) - console.log('loadHistory 222', this.massages) - }); - }) - + // websocket this.WsChatService.loadHistory(this.id, limit).then(async (chatHistory: chatHistory) => { //await this.transformData(chatHistory.result.messages.reverse()); //console.log('loadHistory 111', chatHistory.result.messages.reverse()) - const mgsArray = chatHistory.result.messages.reverse(); - await this.storage.set('chatmsg'+this.id, mgsArray).then((value) => { + const mgsArray = chatHistory.result.messages.reverse(); + await this.storage.remove('chatmsg' + this.id).then(() => { + console.log('MSG REMOVE ON STORAGE') + }) + await this.storage.set('chatmsg' + this.id, mgsArray).then((value) => { console.log('MSG SAVED ON STORAGE', value) + this.getMsgFromDB() }); - chatHistory.result.messages.reverse().forEach(message => { + /* chatHistory.result.messages.reverse().forEach(message => { message = this.fix_updatedAt(message) console.log('loadHistory', message) @@ -121,7 +140,7 @@ export class RoomService { const wewMessage = new MessageService() wewMessage.setData(message) this.massages.push(wewMessage) - }); + }); */ }) @@ -165,7 +184,7 @@ export class RoomService { rid: element.rid, ts: element.ts, u: element.u, - _updatedAt: element._updatedAt , + _updatedAt: element._updatedAt, } this.mgsArray.push(chatmsg); diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 4c652879d..d051b9b08 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -101,7 +101,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } ngOnChanges(changes: SimpleChanges): void { this.wsChatMethodsService.getDmRoom(this.roomId).loadHistory() - + this.wsChatMethodsService.getDmRoom(this.roomId).getMsgFromDB() this.wsChatMethodsService.getDmRoom(this.roomId).scrollDown = this.scrollToBottomClicked /* console.log('DATATATA', this.wsChatMethodsService.getDmRoom(this.roomId).massages) this.wsChatMethodsService.getDmRoom(this.roomId).massages.forEach((element) => {