mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
improve chat
This commit is contained in:
@@ -387,9 +387,7 @@ export class ChatService {
|
||||
} catch (error) {
|
||||
|
||||
this.resetTimer();
|
||||
setTimeout(async () => {
|
||||
await this.refreshtoken();
|
||||
}, 3000)
|
||||
await this.refreshtoken();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user