improve chat remove loop

This commit is contained in:
Peter Maquiran
2022-01-11 15:43:09 +01:00
parent a8a1307bec
commit dcee5aa2f4
9 changed files with 96 additions and 84 deletions
+35 -6
View File
@@ -21,33 +21,41 @@ export class ChatService {
constructor(
private RocketChatClientService: RocketChatClientService
) {
this.getAllRoomAndSubscribe()
(async()=>{
await this.getAllRoom();
this.subscribeToRoom()
})()
}
async getAllRoomAndSubscribe () {
async getAllRoom () {
this.loadingWholeList = true
const rooms: any = await this.RocketChatClientService.getRooms();
rooms.result.update.forEach((roomData:any) => {
let room
let room:RoomService;
let roomId = roomData.lastMessage.rid
if(this.isIndividual(roomData)) {
room = new RoomService(new RocketChatClientService(), new MessageService())
room = new RoomService(this.RocketChatClientService, new MessageService())
room.setData({
id: this.getRoomId(roomData),
name: this.getChatName(roomData),
lastMessage: this.getRoomLastMessage(roomData)
})
room.receiveMessage()
this.individual[roomId] = room
this.individualCount++
} else {
room = new RoomService(new RocketChatClientService(), new MessageService())
room = new RoomService(this.RocketChatClientService, new MessageService())
room.setData({
id: this.getRoomId(roomData),
name: this.getChatName(roomData),
lastMessage: this.getRoomLastMessage(roomData)
})
room.receiveMessage()
this.group[roomId] = room
this.groupCount++
}
@@ -55,7 +63,28 @@ export class ChatService {
});
this.loadingWholeList = false
}
subscribeToRoom() {
for (const id in this.individual) {
this.RocketChatClientService.subscribe(id).then((subscription)=>{
console.log('subscription', subscription)
})
}
for (const id in this.group) {
this.RocketChatClientService.subscribe(id).then((subscription)=>{
console.log('subscription', subscription)
})
}
}
getRoom(id): RoomService {
try {
return this.individual[id]
} catch(e) {
return this.group[id]
}
}
getChatName(roomData) {