diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index df13a2278..712b4bddc 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -136,7 +136,9 @@ export class ChatPage implements OnInit { this.modalController.dismiss(); } }; + this.showLoader = true; + this.load() } ngOnInit() { @@ -144,45 +146,6 @@ export class ChatPage implements OnInit { console.log(this.loggedUserChat); this.segment = "Contactos"; - - // this.authService.userData$.subscribe((res: any) => { - // this.loggedUser = res; - // console.log(this.loggedUser); - // this.load(); - - // // this.getDirectMessagesDB(); - // }); - - /* websocket functions */ - //this.sendMsg(); - - /* Fim websocket functions */ - // this.hideRefreshButton(); - // this.getChatMembers(); - - //Teste - // let t = this.showDateDuration(new Date()); - // console.log(t); - - // this.setStatus('away'); - /* if(this.dataService.get("newGroup")){ - this.openNewGroupPage(); - } */ - - // this.router.events.forEach((event) => { - // if (event instanceof NavigationStart && event.url.startsWith('/home/chat')) { - // if (this.dataService.get("newGroup")) { - // this.openNewGroupPage(); - // } - // else{ - // this.closeAllDesktopComponents(); - // this.showEmptyComponent = true; - // } - // } - // else{ - // this.dataService.set("newGroup", false); - // } - // }); } numSequence(n: number): Array { @@ -224,21 +187,6 @@ export class ChatPage implements OnInit { } } - - /* loadMessage(){ - this.chatService.messages.subscribe(msg => { - console.log("Response from websocket: " + msg); - }); - } */ - /* sendMsg() { - console.log("new message from client to websocket: ", this.message); - this.chatService.messages.next(this.message); - this.message.msg = ""; - } */ - - - /* Fim websockets functions */ - closeAllDesktopComponents() { this.showMessages = false; this.showContacts = false; @@ -570,7 +518,7 @@ export class ChatPage implements OnInit { //Check if modal is opened if (this.segment == "Contactos" && this.showMessages != true) { await new Promise(resolve => setTimeout(resolve, 1000)); - await this.getDirectMessages(); + //await this.getDirectMessages(); //console.log('Timer contactos list running') } else { @@ -579,7 +527,7 @@ export class ChatPage implements OnInit { } } else { - await this.getDirectMessages(); + //await this.getDirectMessages(); } }); } @@ -734,12 +682,12 @@ export class ChatPage implements OnInit { //Check if modal is opened if (this.segment == "Grupos" && this.showGroupMessages != true) { await new Promise(resolve => setTimeout(resolve, 1000)); - await this.getGroups(); + //await this.getGroups(); } } } else { - await this.getGroups(); + //await this.getGroups(); } }); } diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html index dd895bbfc..836d6ff58 100644 --- a/src/app/pages/chat/messages/messages.page.html +++ b/src/app/pages/chat/messages/messages.page.html @@ -49,7 +49,7 @@ -->
-
diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 0637c7516..66e228556 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -9,5 +9,24 @@ export class MessageService { mentions = [] msg = '' rid = '' + ts = {} + u = {} + _id ='' + _updatedAt = {} + constructor() { } + + setData({channels, mentions, msg ,rid ,ts, u, _id, _updatedAt}) { + this.channels = channels + this.mentions = mentions + this.msg = msg + this.rid = rid + this.ts = ts + this.u = u + this._id = _id + this._updatedAt = _updatedAt + } + + delete() {} + } diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 873b3d240..2c483140d 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -7,7 +7,7 @@ import { ChatUserService } from 'src/app/services/chat/chat-user.service' }) export class RoomService { - massages: {[key: string]: MessageService} = {} + massages: MessageService[] = [] lastMessage: MessageService; chatUser: ChatUserService[] = [] @@ -35,8 +35,7 @@ export class RoomService { this.id, this.constructor.name+this.id, (Chatmessage)=>{ - this.hasLoadHistory = false - this.loadHistory() + this.massages.push(Chatmessage.result) } ) } @@ -50,9 +49,15 @@ export class RoomService { if(this.hasLoadHistory){ return false } - this.RocketChatClientService.loadHistory(this.id, limit).then((message:any)=>{ + this.RocketChatClientService.loadHistory(this.id, limit).then((message:any) => { console.log('loadHistory', message) - this.mmm = message.result.messages.reverse() + + message.result.messages.reverse().forEach(element => { + const message = new MessageService() + message.setData(element) + this.massages.push(message) + }); + }) this.hasLoadHistory = true diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index d5ac2116f..cf0913ab6 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -37,7 +37,7 @@
-
+