From 38fcf7e5140ab96c2a2578e35ccc535d08071b91 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Thu, 20 Jan 2022 15:33:55 +0100 Subject: [PATCH] fix load image --- src/app/services/chat/room.service.ts | 43 ++++++++++++------- .../shared/chat/messages/messages.page.html | 2 +- src/app/shared/chat/messages/messages.page.ts | 11 ++++- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 6aebbc683..7f787bca6 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -67,6 +67,16 @@ export class RoomService { this.scrollDown() }, 100) + + // save to ionic storage + this.storage.get('chatmsg'+ this.id).then((messages: any) => { + const newListMessages = messages.push(ChatMessage) + + this.storage.set('chatmsg'+ this.id, newListMessages).then((value) => { + console.log('MSG SAVED ON STORAGE', value) + }); + }) + } ) } @@ -80,25 +90,29 @@ export class RoomService { 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()) - this.mgsArray = chatHistory.result.messages.reverse(); - await this.storage.set('chatmsg', this.mgsArray).then((value) => { + //console.log('loadHistory 111', chatHistory.result.messages.reverse()) + const mgsArray = chatHistory.result.messages.reverse(); + await this.storage.set('chatmsg'+this.id, mgsArray).then((value) => { console.log('MSG SAVED ON STORAGE', value) - }); */ + }); - /* await this.storage.get('chatmsg').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) - }); - }) */ chatHistory.result.messages.reverse().forEach(message => { message = this.fix_updatedAt(message) @@ -152,7 +166,6 @@ export class RoomService { ts: element.ts, u: element.u, _updatedAt: element._updatedAt , - } this.mgsArray.push(chatmsg); diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 85f4f2ba3..a1bc9bcb1 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -132,7 +132,7 @@
- TTTT + File image
diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 9078f20df..4c652879d 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -813,7 +813,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy card.el.style['z-index'] = 11; } - downloadFileMsg(msg) { + downloadFileMsg(msg: MessageService) { console.log('FILE TYPE', msg.file.type) this.downloadFile = ""; if (msg.file.type == "application/img") { @@ -826,6 +826,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy console.log('FILE TYPE 33', msg.file.type) } else if (event.type === HttpEventType.Response) { this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); + + msg.file = { + guid: msg.file.guid, + image_url: this.downloadFile, + type: msg.file.type + } await this.storage.set(msg.file.guid, this.downloadFile).then(() => { console.log('IMAGE SAVED') @@ -839,7 +845,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy } async openPreview(msg) { - if (msg.file.image_url === null) { + + if (msg.file.image_url === null || msg.file.image_url === '' ) { this.downloadFileMsg(msg) } else {