Profile picture, notifications, chat romms

This commit is contained in:
Eudes Inácio
2023-09-18 05:41:33 +01:00
parent 540750e0e9
commit 527cc0f2a6
10 changed files with 236 additions and 124 deletions
+96 -52
View File
@@ -72,6 +72,7 @@ export class ChatPage implements OnInit {
componentRef: any;
roomId: any;
task: any;
groupRoomId: any;
showEmptyComponent = true;
showMessages = false;
@@ -106,6 +107,8 @@ export class ChatPage implements OnInit {
eventSelectedDate: Date = new Date();
contacts: EventPerson[];
showEventEditOrOpen: "edit" | "add" | "" | "eventoToApprove" = ""
socket: WebSocket;
receivedData: any;
constructor(
private chatService: ChatService,
@@ -137,18 +140,17 @@ export class ChatPage implements OnInit {
this.segment = 'Contactos'
this.eventTriger.getObservable().subscribe((event) => {
if(event.notification == "recive") {
/* this.eventTriger.getObservable().subscribe((event) => {
if (event.notification == "recive") {
this.onSegmentChange()
}
// console.log(event)
});
}); */
}
ngOnInit() {
console.log("Loading TestComponent")
this.segment = "Contactos";
this.authService.userData$.subscribe((res: any) => {
@@ -160,8 +162,8 @@ export class ChatPage implements OnInit {
this.router.events.forEach((event) => {
if (event instanceof NavigationEnd && event.url == '/home/chat' ||
event instanceof NavigationEnd && event.url == "/home/chat?gbCreateGroup=true") {
if (event instanceof NavigationEnd && event.url == '/home/chat' ||
event instanceof NavigationEnd && event.url == "/home/chat?gbCreateGroup=true") {
this.checkCreateGroup();
}
});
@@ -180,8 +182,43 @@ export class ChatPage implements OnInit {
if (isActive) {
// The app is in the foreground.
console.log('App is in the foreground');
this.RochetChatConnectorService.connect()
this.reloadComponent(true)
setTimeout(() => {
this.ChatSystemService.subscribeToRoom()
},1000);
/* const webSocketURL = environment.apiWsChatUrl;
const ws = new WebSocket(webSocketURL);
ws.addEventListener('open', () => {
console.log('WebSocket connection opened');
});
ws.addEventListener('message', (event) => {
const data = JSON.parse(event.data);
// Handle incoming messages from the Rocket.Chat server.
console.log('Received message:', data);
});
ws.addEventListener('close', (event) => {
console.log('WebSocket connection closed', event);
// Optionally, attempt to reopen the connection when it's closed.
// You can implement a reconnect strategy here.
setTimeout(() => {
this.reopenWebSocketConnection();
}, 5000); // Reopen the connection after 5 seconds (adjust as needed).
});
this.RochetChatConnectorService.sendStreamNotifyRoom("26XgGhKghKN8fN6v8KvDfW9jrjhKhoAWhM", SessionStore.user.UserName, 'typing', true).catch((error) => console.error(error));
ws.addEventListener('error', (error) => {
console.error('WebSocket error:', error);
// Handle WebSocket errors here.
});
*/
/* this.reloadComponent(true) */
} else {
// The app is in the background.
console.log('App is in the background');
@@ -191,15 +228,22 @@ export class ChatPage implements OnInit {
}
}
reopenWebSocketConnection() {
// Implement your reconnection logic here.
const newWebSocket = new WebSocket(environment.apiWsChatUrl);
// Add event listeners to the newWebSocket.
// Retry connecting or other reconnection logic can be added here.
}
routeCheck() {
const urlParams = new URLSearchParams(window.location.search);
const roomId = urlParams.get('roomId');
if(roomId) {
if (roomId) {
const room = this.ChatSystemService.getRoomById(roomId);
if(room.isGroup) {
if (room.isGroup) {
this.segment = 'Grupos'
this.openGroupMessagesPage(roomId)
} else {
@@ -219,7 +263,7 @@ export class ChatPage implements OnInit {
this.closeAllDesktopComponents();
this.showEmptyComponent = true;
}
}
numSequence(n: number): Array<number> {
@@ -228,7 +272,7 @@ export class ChatPage implements OnInit {
ngOnDestroy() {
this.setStatus('offline');
}
setStatus(status: string) {
@@ -237,7 +281,7 @@ export class ChatPage implements OnInit {
status: status,
}
this.chatService.setUserStatus(body).subscribe(res => {
})
}
@@ -248,7 +292,7 @@ export class ChatPage implements OnInit {
this.hideRefreshBtn = false;
this.closeAllDesktopComponents()
this.ChatSystemService.getRoomById(this.roomId)?.roomLeave()
this.ChatSystemService.getRoomById(this.roomId)?.roomLeave()
}
else {
this.hideRefreshBtn = true;
@@ -273,7 +317,7 @@ export class ChatPage implements OnInit {
this.showGroupContacts = false;
this.showNewEvent = false;
this.showAttendees = false;
}
showEmptyContainer() {
@@ -353,14 +397,14 @@ export class ChatPage implements OnInit {
this.closeAllDesktopComponents();
this.showEmptyComponent = false;
this.showGroupMessages = true;
}
}
openNewEventPage(data?) {
if(data) {
if (data) {
this.taskParticipants = data.members.map((val) => {
return {
Name: val.name,
@@ -370,10 +414,10 @@ export class ChatPage implements OnInit {
});
this.groupRoomId = data.roomId;
}
this.closeAllDesktopComponents();
if (window.innerWidth < 701) {
}
else {
this.showNewEvent = true;
@@ -413,19 +457,19 @@ export class ChatPage implements OnInit {
this.idSelected = "";
}
async closeNewEventComponentAndOpenChat({roomId}) {
async closeNewEventComponentAndOpenChat({ roomId }) {
this.closeAllDesktopComponents();
this.ChatSystemService._group.forEach((room)=>{
if(room.id == roomId) {
this.ChatSystemService._group.forEach((room) => {
if (room.id == roomId) {
this.openGroupMessagesPage(roomId)
}
})
this.ChatSystemService._dm.forEach((room)=>{
if(room.id == roomId) {
this.ChatSystemService._dm.forEach((room) => {
if (room.id == roomId) {
this.openMessagesPage(roomId)
}
})
@@ -440,8 +484,8 @@ export class ChatPage implements OnInit {
doRefresh(event) {
setTimeout(() => {
try {
event?.target?.complete();
} catch(error) {}
event?.target?.complete();
} catch (error) { }
}, 1000);
}
@@ -506,7 +550,7 @@ export class ChatPage implements OnInit {
// // //
// // let chatusersArray = [];
// // userslist.forEach(element => {
// // let userListDB = {
// // _id: element.Id,
// // name: element.Name,
@@ -571,7 +615,7 @@ export class ChatPage implements OnInit {
usersArray.push(chatusers);
});
await this.storageservice.remove('chatusers');
await this.storageservice.store('chatusers',usersArray);
await this.storageservice.store('chatusers', usersArray);
} else {
users.forEach(element => {
//
@@ -605,7 +649,7 @@ export class ChatPage implements OnInit {
getGroupsDB() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {
this.storageservice.get("grouprooms").then((rooms) =>{
this.storageservice.get("grouprooms").then((rooms) => {
let k = rooms.sort((a, b) => {
var dateA = new Date(a._updatedAt).getTime();
@@ -613,7 +657,7 @@ export class ChatPage implements OnInit {
return dateB - dateA;
});
this.allGroups = rooms.sort((a, b) => {
@@ -625,13 +669,13 @@ export class ChatPage implements OnInit {
//
}).catch((error) => {
console.error('storage getGrup Romm db: ',error)
console.error('storage getGrup Romm db: ', error)
})
this.storageservice.get('chatusers').then((users) => {
this.dmUsers = users.filter(data => data.username != SessionStore.user.UserName);
}).catch((error) => {
console.error('storage getgrupDb: ',error)
console.error('storage getgrupDb: ', error)
})
} else {
// this.sqlservice.getAllChatRoom().then((rooms: any) => {
@@ -713,14 +757,14 @@ export class ChatPage implements OnInit {
async getGroups(event?) {
this.result = this.chatService.getAllPrivateGroups().subscribe(async (res: any) => {
//
this.showLoader = false;
this.showLoader = false;
if (res.groups != 200) {
this.transformGroups(res.groups);
this.getGroupsDB();
this.privateGroups = res.groups;
if (this.route.url != "/home/chat") {
//
@@ -728,7 +772,7 @@ export class ChatPage implements OnInit {
else {
//Check if modal is opened
if (this.segment == "Grupos" && this.showGroupMessages != true) {
await new Promise(resolve => setTimeout(resolve, 1000)).catch ((error) => {
await new Promise(resolve => setTimeout(resolve, 1000)).catch((error) => {
console.error(error);
});
//await this.getGroups();
@@ -758,7 +802,7 @@ export class ChatPage implements OnInit {
modal.onDidDismiss().then((Data) => {
// console.log(Data,'daatatatat');
// let data = Data.data
// let roomId = data.roomId
// this.openMessagesPage(roomId);
@@ -788,7 +832,7 @@ export class ChatPage implements OnInit {
});
modal.onDidDismiss().then((res) => {
this.modalController.dismiss(res.data);
});
@@ -812,18 +856,18 @@ export class ChatPage implements OnInit {
}
backToChat({roomId}) {
backToChat({ roomId }) {
const room = this.ChatSystemService.getRoomById(roomId);
if(room.isGroup) {
if (room.isGroup) {
this.segment = "Grupos"
this.openGroupMessagesPage(room.id);
} else {
this.segment = "Contactos"
this.openMessagesPage(room.id);
}
}
async openChatDebuggingPageModal(roomId?: any) {
@@ -850,24 +894,24 @@ export class ChatPage implements OnInit {
},
});
modal.onDidDismiss().then(() =>{
modal.onDidDismiss().then(() => {
this.ChatSystemService.currentRoom.roomLeave()
});
await modal.present();
}
reloadComponent(self:boolean,urlToNavigateTo ?:string){
reloadComponent(self: boolean, urlToNavigateTo?: string) {
//skipLocationChange:true means dont update the url to / when navigating
console.log("Current route I am on:",this.router.url);
const url=self ? this.router.url :urlToNavigateTo;
this.zone.run(() =>this.router.navigateByUrl('/',{skipLocationChange:true}).then(()=>{
this.zone.run(() => this.router.navigate([`/${url}`]).then(()=>{
console.log(`After navigation I am on:${this.router.url}`)
}))
}))
}
console.log("Current route I am on:", this.router.url);
const url = self ? this.router.url : urlToNavigateTo;
this.zone.run(() => this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
this.zone.run(() => this.router.navigate([`/${url}`]).then(() => {
console.log(`After navigation I am on:${this.router.url}`)
}))
}))
}
}