save, work in progress!

This commit is contained in:
tiago.kayaya
2022-03-14 08:09:33 +01:00
parent 43b7e4ade0
commit 218f2d597f
12 changed files with 109 additions and 50 deletions
+25 -25
View File
@@ -99,29 +99,29 @@ export class RoomService {
let ChatMessage = _ChatMessage.fields.args[0]
ChatMessage = this.fix_updatedAt(ChatMessage)
if(!this.messagesLocalReference.includes(ChatMessage.localReference)) {
const message = this.prepareMessage(ChatMessage)
this.lastMessage = message
this.calDateDuration(ChatMessage._updatedAt)
if (message.t == 'r') {
this.name = message.msg
}
if(this.isSenderIsNotMe(ChatMessage)) {
this.NativeNotificationService.sendNotificationChat({
message: message.msg,
title: this.name
});
}
this.addMessageDB(ChatMessage)
setTimeout(()=>{
this.scrollDown()
}, 50)
}, 50)
}
@@ -175,7 +175,7 @@ export class RoomService {
}
async updateMessageDB(ChatMessage, localReference) {
if (environment.chatOffline) {
if (environment.chatOffline) {
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
if(!Array.isArray(messages)) {
messages = []
@@ -197,14 +197,14 @@ export class RoomService {
messages[index] = ChatMessage
this.storage.set('chatmsg' + this.id, messages)
}
})
}
}
async updateViewedMessage(id, userId) {
if (environment.chatOffline) {
if (environment.chatOffline) {
this.storage.get('chatmsg' + this.id).then((messages: any = []) => {
if(!Array.isArray(messages)) {
messages = []
@@ -212,12 +212,12 @@ export class RoomService {
let index;
const find = messages.find((message, _index)=> {
if(message._id == id) {
index = _index
return true
}
return false
})
@@ -231,7 +231,7 @@ export class RoomService {
this.storage.set('chatmsg' + this.id, messages)
}
})
}
@@ -247,15 +247,15 @@ export class RoomService {
if(!Array.isArray(messages)) {
messages = []
}
messages.forEach((message, index) => {
if(message._id == id) {
messages.splice(index, 1)
}
})
this.storage.set('chatmsg' + this.id, messages).then((value) => {
console.log('MSG SAVED ON STORAGE', value)
});
@@ -332,7 +332,7 @@ export class RoomService {
if (environment.chatOffline) {
this.messagesLocalReference.push(localReference)
this.addMessageDB(offlineChatMessage)
setTimeout(() => {
this.scrollDown()
}, 150)
@@ -347,9 +347,9 @@ export class RoomService {
/**
*
* @param message
* @param ChatMessage
*
* @param message
* @param ChatMessage
* @description when creating message we use offline data, then we need redefined with live data
*/
redefinedMessage (message: MessageService, ChatMessage) {
@@ -497,9 +497,9 @@ export class RoomService {
/**
* @description find or create message
* @param message
* @param save
* @returns
* @param message
* @param save
* @returns
*/
prepareMessage(message, save = true): MessageService {
message = this.fix_updatedAt(message)
@@ -515,7 +515,7 @@ export class RoomService {
const found = this.messages.find((MessageService) => {
if (MessageService._id == message._id) {
if(this.hasLoadHistory) console.log(`${MessageService._id} == ${message._id}`)
if(this.hasLoadHistory) /* console.log(`${MessageService._id} == ${message._id}`) */
return true
} else {
return false