This commit is contained in:
Peter Maquiran
2022-02-10 14:07:16 +01:00
parent a6823d9bae
commit 26a209502e
5 changed files with 122 additions and 128 deletions
@@ -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()
}