mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 05:45:50 +00:00
improve chat remove loop
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user