fix chat open modal

This commit is contained in:
Lorito Tiago
2023-10-19 15:03:12 +01:00
parent 2a4796bb3d
commit 26b894ed1c
11 changed files with 976 additions and 831 deletions
+67 -169
View File
@@ -114,7 +114,10 @@ export class ChatSystemService {
document.addEventListener('resume', () => {
this.RochetChatConnectorService.setStatus('online')
if (this._dm?.length == 0 && this._group?.length == 0) {
this.getAllRooms();
if (SessionStore.user?.ChatData?.data) {
this.getAllRooms();
}
}
});
@@ -124,11 +127,15 @@ export class ChatSystemService {
// The app is in the foreground.
console.log('App is in the foreground');
this.currentRoom?.loadHistory({ forceUpdate: true })
if (SessionStore.user?.ChatData?.data) {
this.currentRoom?.loadHistory({ forceUpdate: true })
}
setTimeout(() => {
this.subscribeToRoom()
this.RochetChatConnectorService.setStatus('online')
if (SessionStore.user?.ChatData?.data) {
this.subscribeToRoom()
this.RochetChatConnectorService.setStatus('online')
}
}, 1000);
/* this.reloadComponent(true) */
@@ -150,15 +157,16 @@ export class ChatSystemService {
private async ReLoadChat() {
this.getUserStatus();
await this.chatService.refreshtoken();
this.restoreUsers();
await this.getUser();
await this.restoreRooms();
await this.getAllRooms();
this.subscribeToRoom();
if (SessionStore.user?.ChatData?.data) {
this.getUserStatus();
await this.chatService.refreshtoken();
this.restoreUsers();
await this.getUser();
await this.restoreRooms();
await this.getAllRooms();
this.subscribeToRoom();
}
//
}
@@ -263,90 +271,23 @@ export class ChatSystemService {
for (let roomData of this.sortArrayISODate(_rooms)) {
const roomId = this.getRoomId(roomData);
if (roomData.t == 'd') {
let error = false
let res;
try {
res = await this.chatService.getMembers(roomId).toPromise();
} catch (e) {
await this.chatService.refreshtoken();
error = true
}
if (error) {
res = await this.chatService.getMembers(roomId).toPromise();
}
const members = res['members'];
const users = members.filter(data => data.username != this.sessionStore.user.UserName);
_rooms[index]['members'] = members
_rooms[index]['membersExcludeMe'] = users
await this.prepareRoom(roomData);
} else {
if (roomData.t === 'p') {
let error = false
let res;
try {
res = await this.chatService.getGroupMembers(roomId).toPromise()
} catch (e) {
await this.chatService.refreshtoken();
error = true
}
if (error) {
res = await this.chatService.getGroupMembers(roomId).toPromise()
}
const members = res['members'];
const users = members.filter(data => data.username != this.sessionStore.user.UserName);
_rooms[index]['members'] = members
_rooms[index]['membersExcludeMe'] = users
await this.prepareRoom(roomData);
}
else {
let error = false
let res;
try {
res = await this.chatService.getChannelMembers(roomId).toPromise()
} catch (e) {
await this.chatService.refreshtoken();
error = true
}
if (error) {
res = await this.chatService.getChannelMembers(roomId).toPromise()
}
const members = res['members'];
const users = members.filter(data => data.username != this.sessionStore.user.UserName);
_rooms[index]['members'] = members
_rooms[index]['membersExcludeMe'] = users
await this.prepareRoom(roomData);
}
}
if (roomId == roomIdCallback) {
callback()
}
index++;
}
}
@@ -362,7 +303,6 @@ export class ChatSystemService {
async getRoom(_rooms: any) {
this.loadingWholeList = true
let index = 0
if (_rooms) {
@@ -374,80 +314,17 @@ export class ChatSystemService {
for (let roomData of this.sortArrayISODate(_rooms)) {
const roomId = this.getRoomId(roomData);
if (roomData.t == 'd') {
let error = false
let res;
try {
res = await this.chatService.getMembers(roomId).toPromise();
} catch (e) {
await this.chatService.refreshtoken();
error = true
}
if (error) {
res = await this.chatService.getMembers(roomId).toPromise();
}
const members = res['members'];
const users = members.filter(data => data.username != this.sessionStore.user.UserName);
_rooms[index]['members'] = members
_rooms[index]['membersExcludeMe'] = users
await this.prepareRoom(roomData);
} else {
if (roomData.t === 'p') {
let error = false
let res;
try {
res = await this.chatService.getGroupMembers(roomId).toPromise()
} catch (e) {
await this.chatService.refreshtoken();
error = true
}
if (error) {
res = await this.chatService.getGroupMembers(roomId).toPromise()
}
const members = res['members'];
const users = members.filter(data => data.username != this.sessionStore.user.UserName);
_rooms[index]['members'] = members
_rooms[index]['membersExcludeMe'] = users
await this.prepareRoom(roomData);
}
else {
let error = false
let res;
try {
res = await this.chatService.getChannelMembers(roomId).toPromise()
} catch (e) {
await this.chatService.refreshtoken();
error = true
}
if (error) {
res = await this.chatService.getChannelMembers(roomId).toPromise()
}
const members = res['members'];
const users = members.filter(data => data.username != this.sessionStore.user.UserName);
_rooms[index]['members'] = members
_rooms[index]['membersExcludeMe'] = users
await this.prepareRoom(roomData);
}
@@ -477,17 +354,26 @@ export class ChatSystemService {
*/
subscribeToRoom() {
for (const id in this.dm) {
this.defaultSubtribe(id)
if (SessionStore.user?.ChatData?.data) {
for (const id in this.dm) {
this.defaultSubtribe(id)
}
for (const id in this.group) {
this.defaultSubtribe(id)
}
this.RochetChatConnectorService.streamNotifyLogged().then((subscription => { }))
this.RochetChatConnectorService.subStreamMessageUser().then((subscription => { }))
} else {
setTimeout(() => {
throw ('No chat data');
}, 1000)
}
for (const id in this.group) {
this.defaultSubtribe(id)
}
this.RochetChatConnectorService.streamNotifyLogged().then((subscription => { }))
this.RochetChatConnectorService.subStreamMessageUser().then((subscription => { }))
}
/**
@@ -576,13 +462,20 @@ export class ChatSystemService {
lastMessage: this.getRoomLastMessage(roomData),
_updatedAt: new Date(roomData._updatedAt || roomData._updatedAt['$date']),
u: roomData.u || {},
members: roomData.members,
membersExcludeMe: roomData.membersExcludeMe
members: [],
membersExcludeMe: []
}
let roomId = this.getRoomId(roomData);
if (setData.name != 'Rocket Cat' && setData.name != 'general') {
let chat = false
if (roomData?.usernames) {
if (roomData?.usernames?.includes("chat.admin")) {
chat = true
}
}
if (setData.name != 'Rocket Cat' && setData.name != 'general' && chat == false) {
// create room
if (!this.roomExist(roomId)) {
let room: RoomService = new RoomService(this.RochetChatConnectorService, new MessageService(this.NfService, this.RochetChatConnectorService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this, this.notificationService), this.storage, this.platform, this.sqlservice, this.NativeNotificationService, this.sortService, this.ChatService, this.NfService, this.ChatMethodsService, this.AESEncrypt, this.AttachmentsService, this.NetworkServiceService, this, this.ViewedMessageService, this.notificationService)
@@ -755,26 +648,33 @@ export class ChatSystemService {
getRoomName(roomData: room): string {
if (this.isIndividual(roomData)) {
const names: String[] = roomData.usernames
const roomName = names.filter((name, index) => {
return name != SessionStore.user.UserName
})[0]
if (roomName) {
if (roomData.t == 'd') {
const username = roomData.usernames.find(e => e != SessionStore.user.UserName)
try {
const firstName = capitalizeTxt(roomName.split('.')[0])
const lastName = capitalizeTxt(roomName.split('.')[1])
const firstName = capitalizeTxt(username.split('.')[0])
const lastName = capitalizeTxt(username.split('.')[1])
return firstName + ' ' + lastName
} catch (e) {
return roomData['membersExcludeMe'][0].name
} catch (error) {
const username = roomData.usernames.find(e => e != SessionStore.user.UserName)
const firstName = capitalizeTxt(username.split('.')[0])
return firstName
}
} else if (roomData.name) {
return roomData.name
} else {
return 'Sem nome'
if (roomData.t === 'p') {
return 'Loading'
}
else {
return 'Loading'
}
}
} else {
return roomData.fname
}
@@ -849,12 +749,10 @@ export class ChatSystemService {
async createGroup(name) {
const res: any = await this.createPrivateRoom(name, SessionStore.user.UserName, {});
console.log('room is created', res)
if (res?.result?.rid) {
try {
await this.getAllRooms();
} catch (e) { }
console.log('room is loaded')
return res
} else {
return res