This commit is contained in:
tiago.kayaya
2022-01-28 15:59:01 +01:00
parent 5a214aebf4
commit 252bd24eee
7 changed files with 22 additions and 22 deletions
+13 -10
View File
@@ -8,12 +8,13 @@ import { chatHistory, ChatMessage } from 'src/app/models/chatMethod'
import { Storage } from '@ionic/storage';
import { Platform } from '@ionic/angular';
import { SqliteService } from 'src/app/services/sqlite.service';
import { SortService } from '../functions/sort.service';
@Injectable({
providedIn: 'root'
})
export class RoomService {
massages: MessageService[] = []
messages: MessageService[] = []
storageMessage: any[] = [];
lastMessage: MessageService;
@@ -37,6 +38,7 @@ export class RoomService {
private storage: Storage,
private platform: Platform,
private sqlservice: SqliteService,
private sortService: SortService,
) { }
setData({ customFields, id, name, t, lastMessage = new MessageService(), _updatedAt }) {
@@ -67,12 +69,13 @@ export class RoomService {
this.lastMessage = message
if (message.t == 'r') { this.name = message.msg }
this.calDateDuration(ChatMessage._updatedAt)
this.massages.push(message)
this.messages.push(message)
setTimeout(() => {
this.scrollDown()
}, 100)
//this.sortService.sortDate(this.messages, '')
// save to ionic storage
this.storage.get('chatmsg' + this.id).then((messages: any) => {
@@ -97,15 +100,15 @@ export class RoomService {
async (ChatMessage) => {
console.log(ChatMessage.fields.args[0]._id);
const messageId = ChatMessage.fields.args[0]._id;
this.massages.forEach((message, index)=>{
this.messages.forEach((message, index)=>{
if(message._id == messageId){
this.massages.splice(index, 1)
this.storage.set('chatmsg' + this.id, this.massages).then((value) => {
this.messages.splice(index, 1)
this.storage.set('chatmsg' + this.id, this.messages).then((value) => {
//console.log('MSG DELETE ON STORAGE', value)
});
//Get previous last message from room
const previousLastMessage = this.massages.slice(-1)[0];
const previousLastMessage = this.messages.slice(-1)[0];
this.lastMessage = previousLastMessage;
this.calDateDuration(previousLastMessage._updatedAt)
@@ -156,8 +159,8 @@ export class RoomService {
console.log('FROM DB WEB', mmessage)
const wewMessage = new MessageService()
wewMessage.setData(mmessage)
this.massages.push(wewMessage)
console.log('loadHistory 222', this.massages)
this.messages.push(wewMessage)
console.log('loadHistory 222', this.messages)
});
});
}
@@ -190,8 +193,8 @@ export class RoomService {
console.log('FROM DB WEB', mmessage)
const wewMessage = new MessageService()
wewMessage.setData(mmessage)
this.massages.push(wewMessage)
console.log('loadHistory 222', this.massages)
this.messages.push(wewMessage)
console.log('loadHistory 222', this.messages)
});
})
}