mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
fix load image
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
<div>
|
||||
<div (click)="openPreview(msg)">
|
||||
<!-- <img *ngIf="file.image_url" src="{{file.image_url}}" alt="image" (click)="imageSize(file.image_url)"> -->
|
||||
TTTT
|
||||
File
|
||||
<img *ngIf="msg.file.image_url" src="{{msg.file.image_url}}" alt="image">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user