mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +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) {
|
||||
|
||||
@@ -5,5 +5,9 @@ import { Injectable } from '@angular/core';
|
||||
})
|
||||
export class MessageService {
|
||||
|
||||
channels = []
|
||||
mentions = []
|
||||
msg = ''
|
||||
rid = ''
|
||||
constructor() { }
|
||||
}
|
||||
|
||||
@@ -13,21 +13,53 @@ export class RoomService {
|
||||
chatUser: ChatUserService[] = []
|
||||
id = ''
|
||||
name = ''
|
||||
mmm = []
|
||||
private hasLoadHistory = false
|
||||
|
||||
constructor(
|
||||
private RocketChatClientService: RocketChatClientService,
|
||||
public RocketChatClientService: RocketChatClientService,
|
||||
private MessageService: MessageService
|
||||
) {}
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
setData({id, name, lastMessage}) {
|
||||
|
||||
this.id = id
|
||||
this.name = name
|
||||
this.lastMessage = lastMessage
|
||||
}
|
||||
|
||||
receiveMessage() {
|
||||
this.RocketChatClientService.receiveLiveMessageFromRoom(
|
||||
this.id,
|
||||
this.constructor.name+this.id,
|
||||
(Chatmessage)=>{
|
||||
this.hasLoadHistory = false
|
||||
this.loadHistory()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
send(msg) {
|
||||
this.RocketChatClientService.send(this.id, msg)
|
||||
}
|
||||
|
||||
// runs onces only
|
||||
loadHistory(limit= 100) {
|
||||
|
||||
if(this.hasLoadHistory){ return false }
|
||||
|
||||
this.RocketChatClientService.loadHistory(this.id, limit).then((message:any)=>{
|
||||
console.log('loadHistory', message)
|
||||
this.mmm = message.result.messages.reverse()
|
||||
})
|
||||
|
||||
this.hasLoadHistory = true
|
||||
}
|
||||
|
||||
create() {}
|
||||
sendMessage() {}
|
||||
deleteMessage() {}
|
||||
deleteMessage(msgId) {}
|
||||
ReactToMessage() {}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user