From a8a1307becf34cabf01b3d1705c6e082dda63a07 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Tue, 11 Jan 2022 13:03:43 +0100 Subject: [PATCH] add user list --- src/app/pages/chat/chat.page.html | 104 +++++++++++++------------- src/app/pages/chat/chat.page.ts | 55 +++++++------- src/app/services/chat/chat.service.ts | 73 +++++++++++++++--- src/app/services/chat/room.service.ts | 13 +++- 4 files changed, 153 insertions(+), 92 deletions(-) diff --git a/src/app/pages/chat/chat.page.html b/src/app/pages/chat/chat.page.html index d65c8aa73..c6dcc827c 100644 --- a/src/app/pages/chat/chat.page.html +++ b/src/app/pages/chat/chat.page.html @@ -43,64 +43,64 @@
- -
-
- - - -
-
-
-
- - -
-
- {{t.name}} -
+ +
+
+ + + +
+
+
+
+ + +
+
+ {{room.value.name}}
- - +
+
+
+
+ +
+
+ {{room.value.lastMessage.msg}} + + + + {{room.value.lastMessage.file.name || room.value.lastMessage.file.subject }} + + +
+ + Fotografia
-
{{showDateDuration(dm._updatedAt)}}
-
-
- {{dm.lastMessage.msg}} - - - - {{dm.lastMessage.file.name || dm.lastMessage.file.subject }} - - -
- - Fotografia -
-
-
+
-
- -
-
-
-
-
-
-
-
- - -
+
+ + +
+
+
+
+
+
+
+
+ +
- +
+
diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 247df586f..df13a2278 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -12,6 +12,7 @@ import { import { ModalController, Platform } from '@ionic/angular'; import { AuthService } from 'src/app/services/auth.service'; import { ChatService } from 'src/app/services/chat.service'; +import { ChatService as ChatServiceGPR} from 'src/app/services/chat/chat.service' import { GroupMessagesPage } from './group-messages/group-messages.page'; import { ContactsPage } from './messages/contacts/contacts.page'; import { MessagesPage } from './messages/messages.page'; @@ -123,9 +124,11 @@ export class ChatPage implements OnInit { private router: Router, private sqlservice: SqliteService, private platform: Platform, - private storageservice: StorageService + private storageservice: StorageService, + public ChatServiceGPR: ChatServiceGPR ) { + this.loggedUserChat = authService.ValidatedUserChat['data']; this.headers = new HttpHeaders(); window.onresize = (event) => { @@ -142,44 +145,44 @@ export class ChatPage implements OnInit { this.segment = "Contactos"; - this.authService.userData$.subscribe((res: any) => { - this.loggedUser = res; - console.log(this.loggedUser); - this.load(); + // this.authService.userData$.subscribe((res: any) => { + // this.loggedUser = res; + // console.log(this.loggedUser); + // this.load(); - this.getDirectMessagesDB(); - }); + // // this.getDirectMessagesDB(); + // }); /* websocket functions */ //this.sendMsg(); /* Fim websocket functions */ - this.hideRefreshButton(); - this.getChatMembers(); + // this.hideRefreshButton(); + // this.getChatMembers(); //Teste - let t = this.showDateDuration(new Date()); - console.log(t); + // let t = this.showDateDuration(new Date()); + // console.log(t); - this.setStatus('away'); + // 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); - } - }); + // 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 { diff --git a/src/app/services/chat/chat.service.ts b/src/app/services/chat/chat.service.ts index 1686dd66a..89c2b440f 100644 --- a/src/app/services/chat/chat.service.ts +++ b/src/app/services/chat/chat.service.ts @@ -2,14 +2,21 @@ import { Injectable } from '@angular/core'; import { RoomService } from './room.service'; import { RocketChatClientService } from 'src/app/services/socket/rocket-chat-client.service'; import { MessageService } from 'src/app/services/chat/message.service' +import { SessionStore } from 'src/app/store/session.service'; @Injectable({ providedIn: 'root' }) export class ChatService { - rooms: RoomService[] = [] - group = [] + + individual: {[key: string]: RoomService} = {} + group: {[key: string]: RoomService} = {} + + loadingWholeList = false + + individualCount = 0; + groupCount = 0; constructor( private RocketChatClientService: RocketChatClientService @@ -17,17 +24,63 @@ export class ChatService { this.getAllRoomAndSubscribe() } - getAllRoomAndSubscribe() { - this.RocketChatClientService.getRooms().then((rooms: any) => { - rooms.result.update.forEach((roomData:any) => { - const room = new RoomService(new RocketChatClientService(), new MessageService()) - room.setData({id: roomData.lastMessage.rid}) - }); + async getAllRoomAndSubscribe () { + this.loadingWholeList = true + + const rooms: any = await this.RocketChatClientService.getRooms(); + + rooms.result.update.forEach((roomData:any) => { + let room + let roomId = roomData.lastMessage.rid + if(this.isIndividual(roomData)) { + room = new RoomService(new RocketChatClientService(), new MessageService()) + room.setData({ + id: this.getRoomId(roomData), + name: this.getChatName(roomData), + lastMessage: this.getRoomLastMessage(roomData) + }) + this.individual[roomId] = room + this.individualCount++ + } else { + room = new RoomService(new RocketChatClientService(), new MessageService()) + room.setData({ + id: this.getRoomId(roomData), + name: this.getChatName(roomData), + lastMessage: this.getRoomLastMessage(roomData) + }) + this.group[roomId] = room + this.groupCount++ + } + }); + + this.loadingWholeList = false + } - onJoinRoom() { - // live + getChatName(roomData) { + if(this.isIndividual(roomData)) { + const names: String[] = roomData.usernames + const roomName = names.filter((name)=>{ + return name != SessionStore.user.RochetChatUser + })[0] + + return roomName + } else { + return roomData.fName + } + } + + getRoomId(roomData) { + return roomData.lastMessage.rid + } + + getRoomLastMessage(roomData) { + return roomData.lastMessage + } + + private isIndividual(roomData) { + return !roomData.fname } } diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index c921a754c..67a751fe9 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -7,17 +7,22 @@ import { ChatUserService } from 'src/app/services/chat/chat-user.service' }) export class RoomService { - massages: MessageService[] = [] + massages: {[key: string]: MessageService} = {} + lastMessage: MessageService; + chatUser: ChatUserService[] = [] - id = [] + id = '' + name = '' constructor( private RocketChatClientService: RocketChatClientService, private MessageService: MessageService ) {} - setData({id}){ - this.id= id + setData({id, name, lastMessage}) { + this.id = id + this.name = name + this.lastMessage = lastMessage } create() {}