mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
improve
This commit is contained in:
@@ -19,9 +19,8 @@ import { NfService } from 'src/app/services/chat/nf.service'
|
||||
})
|
||||
export class WsChatMethodsService {
|
||||
|
||||
dm = {}
|
||||
group = {}
|
||||
|
||||
dm: {[key: string]: RoomService} = {}
|
||||
group: {[key: string]: RoomService} = {}
|
||||
|
||||
_dm = []
|
||||
_group = []
|
||||
@@ -31,8 +30,7 @@ export class WsChatMethodsService {
|
||||
dmCount = 0;
|
||||
groupCount = 0;
|
||||
|
||||
|
||||
currentRoom = null
|
||||
currentRoom: RoomService = null
|
||||
users: chatUser[] = []
|
||||
|
||||
constructor(
|
||||
@@ -57,20 +55,23 @@ export class WsChatMethodsService {
|
||||
|
||||
})()
|
||||
|
||||
|
||||
/**
|
||||
* @description when the phone is in the background for a long time it could disconnects from the socket then the socket reconnects automatically,
|
||||
* when the connection is lost the subscribe is also lost, so we have to subscribe again when reconnection is establish.
|
||||
*/
|
||||
this.WsChatService.registerCallback({
|
||||
type: 'reConnect',
|
||||
funx: ()=>{
|
||||
/**
|
||||
* @description when the phone is in the background for a long time it could disconnects from the socket then the socket reconnects automatically,
|
||||
* when the connection is lost the subscribe is also lost, so we have to subscribe again when reconnection is establish.
|
||||
*/
|
||||
this.subscribeToRoom()
|
||||
|
||||
if(this.getDmRoom(this.currentRoom)) {
|
||||
this.getDmRoom(this.currentRoom).loadHistory({forceUpdate: true})
|
||||
} else if(this.getGroupRoom(this.currentRoom)) {
|
||||
this.getGroupRoom(this.currentRoom).loadHistory({forceUpdate: true})
|
||||
this.currentRoom.loadHistory({forceUpdate: true})
|
||||
|
||||
for (const id in this.dm) {
|
||||
this.dm[id].hasLoadHistory = false
|
||||
}
|
||||
|
||||
for (const id in this.group) {
|
||||
this.group[id].hasLoadHistory = false
|
||||
}
|
||||
|
||||
}
|
||||
@@ -117,27 +118,22 @@ export class WsChatMethodsService {
|
||||
this.prepareRoom(roomData);
|
||||
});
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
openRoom(roomId) {
|
||||
|
||||
if(this.currentRoom) {
|
||||
if(this.getDmRoom(this.currentRoom)) {
|
||||
this.getDmRoom(this.currentRoom).roomLeave()
|
||||
} else if(this.getGroupRoom(this.currentRoom)) {
|
||||
this.getGroupRoom(this.currentRoom).roomLeave()
|
||||
}
|
||||
this.currentRoom.roomLeave()
|
||||
}
|
||||
|
||||
this.currentRoom = roomId
|
||||
|
||||
if(this.currentRoom) {
|
||||
if(this.getDmRoom(this.currentRoom)) {
|
||||
this.getDmRoom(this.currentRoom).open()
|
||||
} else if(this.getGroupRoom(this.currentRoom)) {
|
||||
this.getGroupRoom(this.currentRoom).open()
|
||||
}
|
||||
if(this.getDmRoom(roomId)) {
|
||||
this.currentRoom = this.getDmRoom(roomId)
|
||||
} else if(this.getGroupRoom(roomId)) {
|
||||
this.currentRoom = this.getGroupRoom(roomId)
|
||||
}
|
||||
|
||||
this.currentRoom.open()
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user