mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
add user list
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
Reference in New Issue
Block a user