mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
ChatStorage done!
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user