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
+1 -1
View File
@@ -254,7 +254,7 @@ export class DespachoService {
});
despachoList = this.sortService.sortDate(despachoList, 'CreateDate')
if(updateStore) {
this.despachoStore.reset(despachoList);
}
+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)
});
})
}
@@ -8,6 +8,7 @@ import { Rooms, Update as room } 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'
@@ -29,6 +30,7 @@ export class WsChatMethodsService {
private storage: Storage,
private platform: Platform,
private sqlservice: SqliteService,
private sortService: SortService
) {
(async()=>{
await this.getAllRooms();
@@ -100,7 +102,7 @@ export class WsChatMethodsService {
prepareRoom(roomData){
let room:RoomService;
room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice)
room = new RoomService(this.WsChatService, new MessageService(), this.storage, this.platform, this.sqlservice, this.sortService)
room.setData({
customFields: roomData.customFields,
id: this.getRoomId(roomData),
+2 -7
View File
@@ -15,7 +15,7 @@ export class SortService {
});
}
}
sortArrayByDate(myArray: any) {
console.log(myArray[0].taskStartDate);
if(myArray.length > 0){
@@ -26,13 +26,8 @@ export class SortService {
}
sortDate(array = [], path: string) {
return array.sort( (a,b)=> {
return new Date(this.ObjectService.deepFind(b, path)).getTime() -
new Date(this.ObjectService.deepFind(a, path)).getTime()
return new Date(this.ObjectService.deepFind(b, path)).getTime() - new Date(this.ObjectService.deepFind(a, path)).getTime()
})
}
}
@@ -44,7 +44,7 @@
<ion-label>A conversa original mantêm-se como chat individual</ion-label>
</div>
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of wsChatMethodsService.getGroupRoom(roomId).massages; let last = last">
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of wsChatMethodsService.getGroupRoom(roomId).messages; let last = last">
<div class="message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45" *ngIf="msg.t != 'r' && msg.t != 'ul' && msg.t != 'au' && msg.t != 'ru' && msg.msg !=''" >
<div class="message-item-options d-flex justify-content-end">
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"></fa-icon>
@@ -112,7 +112,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
//this.scrollToBottom();
this.wsChatMethodsService.getGroupRoom(this.roomId).loadHistory();
this.wsChatMethodsService.getGroupRoom(this.roomId).getMsgFromDB();
console.log('MESSAGES'+ this.wsChatMethodsService.getGroupRoom(this.roomId).massages);
console.log('MESSAGES'+ this.wsChatMethodsService.getGroupRoom(this.roomId).messages);
this.wsChatMethodsService.getGroupRoom(this.roomId).scrollDown = this.scrollToBottomClicked
setTimeout(()=>{
@@ -38,7 +38,7 @@
</ion-refresher-content>
</ion-refresher>
<div class="messages" #scrollMe>
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of wsChatMethodsService.getDmRoom(roomId).massages; let last = last">
<div class="messages-list-item-wrapper container-width-100" *ngFor="let msg of wsChatMethodsService.getDmRoom(roomId).messages; let last = last">
<div class='message-item incoming-{{msg.u.username!=loggedUser.me.username}} max-width-45' *ngIf="msg.msg !=''">
<div class="message-item-options d-flex justify-content-end">
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer">