improve chat

This commit is contained in:
Peter Maquiran
2022-10-04 11:33:46 +01:00
parent b3dfb396f3
commit e738bf08f3
14 changed files with 74 additions and 144 deletions
+45 -16
View File
@@ -39,6 +39,7 @@ export class ChatSystemService {
users: chatUser[] = []
sessionStore = SessionStore
delete = []
loadingUsers = false
constructor(
private RochetChatConnectorService: RochetChatConnectorService,
@@ -57,18 +58,20 @@ export class ChatSystemService {
private NetworkServiceService: NetworkServiceService,
) {
this.loadChat()
this.RochetChatConnectorService.registerCallback({
type: 'reConnect',
funx: () => {
funx: async () => {
/**
* @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()
await this.chatService.refreshtoken();
await this.getUser();
await this.getAllRooms();
this.subscribeToRoom();
//
this.getUserStatus();
if(this.currentRoom) {
this.currentRoom.loadHistory({forceUpdate: true})
@@ -85,22 +88,25 @@ export class ChatSystemService {
}
})
if(this.sessionStore.user.Inactivity) {
this.loadChat();
}
}
private loadChat() {
loadChat() {
this.ReLoadChat()
}
async ReLoadChat() {
await this.chatService.refreshtoken();
await this.getUser();
await this.restoreRooms();
await this.getAllRooms();
this.subscribeToRoom();
//
await this.getUser();
this.getUserStatus();
}
@@ -590,11 +596,37 @@ export class ChatSystemService {
async getUser() {
let _res = await this.ChatService.getAllUsers().toPromise()
this.loadingUsers = true
let _res
let users = _res['users'].filter(data => data.username != SessionStore.user.UserName);
console.log('getuser')
users = users.sort((a,b) => {
try {
_res = await this.ChatService.getAllUsers().toPromise();
} catch (error) {
await this.chatService.refreshtoken();
_res = await this.ChatService.getAllUsers().toPromise();
}
let users: chatUser[] = _res['users'].filter(data => data.username != SessionStore.user.UserName);
const userIds = this.users.map((user) => user._id)
for(let UserUpdate of users) {
if(userIds.includes(UserUpdate._id)) {
console.log("found")
for (var index = 0; index < this.users.length; index++) {
if(UserUpdate._id == this.users[index]._id) {
this.users[index] = UserUpdate
}
}
} else {
this.users.push(UserUpdate)
console.log("push ")
}
}
this.users = this.users.sort((a,b) => {
if(a.name < b.name) {
return -1;
}
@@ -604,11 +636,8 @@ export class ChatSystemService {
return 0;
});
users.forEach((user, index) => {
// user[index].status = this.statusNumberToText(user[index].status)
})
this.loadingUsers = false
this.users = users
}
getUserOfRoom(roomId){
+13
View File
@@ -202,6 +202,19 @@ export class RoomService {
}
get online() {
if(!this.isGroup) {
for(let user of this.ChatSystemService.users) {
if(this.membersExcludeMe[0]._id == user._id) {
return user.status
}
}
}
return 'offline'
}
countDownDate(date) {
let difference = new Date(date).getTime() - new Date().getTime();
let c_day = Math.floor(difference/(1000*60*60*24));