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
@@ -39,8 +39,8 @@ export class EditProfilePage implements OnInit {
) { }
ngOnInit() {
this.getProfilpictureFromStorage();
this.getProfilpictureFromStorage();
}
getProfilpictureFromStorage() {
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
@@ -50,27 +50,27 @@ export class EditProfilePage implements OnInit {
this.profilePicture = "";
})
}
/* getProfilpicture(guid) {
console.log('Get picture ', guid.path)
this.attachmentService.getUserProfilePhoto().subscribe(async (picture: any) => {
console.log('Get picture ', picture)
this.storageService.store(this.SessionStore.user.RoleID.toString() + "guid", guid.path)
this.storageService.store(this.SessionStore.user.RoleID.toString(), picture).then((value) => {
this.profilePicture = picture
this.SessionStore.user.UserPhoto = picture;
console.log('picture saved')
}).catch((error) => {
console.log('picture not saved')
});
}, ((error) => {
console.log('Error get profile picture: ', error)
}))
} */
/* getProfilpicture(guid) {
console.log('Get picture ', guid.path)
this.attachmentService.getUserProfilePhoto().subscribe(async (picture: any) => {
console.log('Get picture ', picture)
this.storageService.store(this.SessionStore.user.RoleID.toString() + "guid", guid.path)
this.storageService.store(this.SessionStore.user.RoleID.toString(), picture).then((value) => {
this.profilePicture = picture
this.SessionStore.user.UserPhoto = picture;
console.log('picture saved')
}).catch((error) => {
console.log('picture not saved')
});
}, ((error) => {
console.log('Error get profile picture: ', error)
}))
} */
close() {
this.modalController.dismiss();
@@ -188,14 +188,23 @@ export class EditProfilePage implements OnInit {
this.attachmentService.addUserProfilePhoto(object).subscribe((guid) => {
console.log('GUID ', guid)
console.log(this.SessionStore.user.RoleID.toString())
this.storageService.store(this.SessionStore.user.RoleID.toString(), this.capturedImage).then((value) => {
this.profilePicture = 'data:image/jpeg;base64,' +this.capturedImage;
//get user profile picture base64
this.attachmentService.getUserProfilePhoto(guid).subscribe((base) => {
console.log('before picture saved',base)
this.storageService.store(this.SessionStore.user.RoleID.toString(), 'data:image/jpeg;base64,'+base).then((value) => {
this.profilePicture = 'data:image/jpeg;base64,' + base;
console.log('picture saved')
}).catch((error) => {
console.log('picture not saved')
});
console.log('picture saved',value)
}).catch((error) => {
console.log('picture not saved')
});
},(error) => {
console.log('profile picture erro: ', error)
})
/* this.getProfilpicture(guid); */
}, ((error) => {
console.log('Erro Upload profile picture ', error)
+1 -1
View File
@@ -94,7 +94,7 @@ export class ProfilePage implements OnInit {
getProfilpicture() {
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
console.log(picture)
this.profilePicture = 'data:image/jpeg;base64,' +picture
this.profilePicture = picture
}).catch((error ) => {
this.profilePicture = "";
})
+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}`)
}))
}))
}
}
@@ -723,6 +723,8 @@ export class ExpedienteDetailPage implements OnInit {
this.dataService.set("newGroupName", this.task.Folio);
this.dataService.set("documents", this.fulltask.Documents);
this.dataService.set("link", window.location.pathname);
console.log('First ,', this.task)
setTimeout(() => {
this.router.navigate(['/home/chat']);
}, 100)
+6 -2
View File
@@ -190,11 +190,15 @@ export class AttachmentsService {
return this.http.post(`${geturl}`, formData, options);
}
getUserProfilePhoto() {
getUserProfilePhoto(guid) {
const geturl = environment.apiURL + 'UserAuthentication/GetPhoto';
let params = new HttpParams();
params = params.set("UserPhoto", guid);
let options = {
headers: this.headers
headers: this.headers,
params: params
};
return this.http.get(`${geturl}`, options);
@@ -19,15 +19,12 @@ export class RochetChatConnectorService {
}
reConnect() {
console.log('Connect1 ',this.ws.connected)
if(!this.ws.connected) {
this.ws.connect()
console.log('Connect2 ',this.ws.connected)
}
}
connect() {
console.log('Check conetion 11')
console.log(this.ws.connected)
// dont connect if is already connected
if(this.ws.connected == true) {
console.log('Check conetion 22')
@@ -744,7 +741,7 @@ export class RochetChatConnectorService {
private n = 0
private ws = {
ws = {
connected: false,
registerCallback:(params: wsCallbacksParams) => {
+1
View File
@@ -4,6 +4,7 @@ import { Injectable } from '@angular/core';
providedIn: 'root'
})
export class DataService {
public task: any;
data = {}
+33 -19
View File
@@ -137,9 +137,7 @@ export class NotificationsService {
this.active = true
console.log('NOtification Listener', notification)
this.storenotification(notification)
this.eventtrigger.publishSomeData({
notification: "recive"
})
}
);
@@ -156,6 +154,7 @@ export class NotificationsService {
}
}
storenotification(notification) {
console.log('Store Notification ',notification)
this.storageService.get("Notifications").then((store) => {
@@ -163,22 +162,39 @@ export class NotificationsService {
store.push(notification)
console.log('Store Notification ',store)
const result = store.reduce((accumulator, current) => {
let exists = accumulator.find(item => {
return item.id === current.id;
});
if(!exists) {
accumulator = accumulator.concat(current);
}
return accumulator;
}, []);
console.log(result);
if(this.platform.is('mobile')) {
const result = store.reduce((accumulator, current) => {
let exists = accumulator.find(item => {
return item.id === current.id;
});
if(!exists) {
accumulator = accumulator.concat(current);
}
return accumulator;
}, []);
console.log('Notification Result',result);
this.storageService.store("Notifications", result).then(() => {
this.eventtrigger.publishSomeData({
notification: "recive"
})
})
} else {
this.storageService.store("Notifications", store).then(() => {
this.eventtrigger.publishSomeData({
notification: "recive"
})
})
}
this.storageService.store("Notifications", result)
}).catch((error) => {
if (!error) {
this.storageService.store("Notifications", [notification])
@@ -214,11 +230,9 @@ export class NotificationsService {
notification: event.data
}
this.notificatinsRoutes(object)
// Implemente a lógica para lidar com a mensagem recebida do Service Worker
if (event.data.notificationClicked) {
console.log('Notificação push do Firebase clicada em segundo plano!');
// Implemente ações adicionais conforme necessário
this.notificatinsRoutes(object)
}
};
}
@@ -1,4 +1,4 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Component, EventEmitter, Input, OnInit, Output,ViewContainerRef } from '@angular/core';
import { ModalController, PickerController, PopoverController } from '@ionic/angular';
import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
import { DataService } from 'src/app/services/data.service';
@@ -49,6 +49,7 @@ export class NewGroupPage implements OnInit{
private toastService: ToastService,
public ThemeService: ThemeService,
private RouteService: RouteService,
private viewContainerRef: ViewContainerRef
)
{
this.loggedUserChat = SessionStore.user.ChatData['data'];
@@ -56,9 +57,16 @@ export class NewGroupPage implements OnInit{
}
ngOnInit() {
console.log(this.dataService.get("task"))
this.task = this.dataService.get("task");
this.event = this.dataService.get("event");
console.log(this.task)
this
if(this.task) {
this.link = this.dataService.get("link");
this.groupName = this.task.Folio;
@@ -93,12 +101,15 @@ export class NewGroupPage implements OnInit{
close() {
if(this.link) {
this.viewContainerRef.clear();
this.RouteService.goBack();
this.dataService.set("link", false);
} else {
if(this.roomId) {
this.backToChat.emit({roomId: this.roomId});
this.viewContainerRef.clear();
} else {
this.viewContainerRef.clear();
this.closeAllDesktopComponents.emit();
}
+44 -14
View File
@@ -1,4 +1,4 @@
import { Component, OnInit, ChangeDetectorRef } from '@angular/core';
import { Component, OnInit, ChangeDetectorRef, NgZone } from '@angular/core';
import { AnimationController, ModalController, Platform } from '@ionic/angular';
import { SearchPage } from 'src/app/pages/search/search.page';
import { Router } from '@angular/router';
@@ -14,6 +14,7 @@ import { PermissionService } from 'src/app/services/permission.service';
import { EventTrigger } from 'src/app/services/eventTrigger.service'
import { ActiveTabService } from 'src/app/services/active-tab.service';
import { NotificationsService } from 'src/app/services/notifications.service';
import { AttachmentsService } from 'src/app/services/attachments.service';
@Component({
selector: 'app-header',
@@ -55,6 +56,8 @@ export class HeaderPage implements OnInit {
private notificationService: NotificationsService,
private cdRef: ChangeDetectorRef,
private storageService: StorageService,
private zone: NgZone,
private attachmentService: AttachmentsService
) {
this.loggeduser = SessionStore.user;
router.events.subscribe((val) => {
@@ -65,7 +68,7 @@ export class HeaderPage implements OnInit {
});
this.updateReciveNotification();
this.updateDeleteNotification();
this.updateDeleteNotification();
/* this.notificationService.notificationReceived.subscribe(() => {
console.log('header', 'event.notification')
@@ -75,23 +78,49 @@ export class HeaderPage implements OnInit {
}
ngOnInit() {
ngOnInit() {
this.hideSearch();
this.getProfilpicture();
console.log('Profile picture guid ', this.SessionStore.user.UserPhoto)
this.getProfilpicture();
}
ng
reloadComponent(self: boolean, urlToNavigateTo?: string) {
//skipLocationChange:true means dont update the url to / when navigating
console.log("Current route I am on header:", 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 header:${this.router.url}`)
}))
}))
}
getProfilpicture() {
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
console.log(picture)
this.profilePicture = 'data:image/jpeg;base64,' +picture
}).catch((error ) => {
this.profilePicture = "";
this.attachmentService.getUserProfilePhoto(this.SessionStore.user.UserPhoto).subscribe((base) => {
this.storageService.store(this.SessionStore.user.RoleID.toString(), 'data:image/jpeg;base64,' + base).then((value) => {
this.profilePicture = 'data:image/jpeg;base64,' + base;
console.log('picture saved', value)
}).catch((error) => {
console.log('picture not saved')
});
}, (error) => {
console.log('profile picture errro: ', error)
this.storageService.get(this.SessionStore.user.RoleID.toString()).then((picture) => {
console.log(picture)
this.profilePicture = picture
}).catch((error) => {
this.profilePicture = "";
})
})
}
updateReciveNotification() {
@@ -118,10 +147,11 @@ export class HeaderPage implements OnInit {
console.log('Call notification data')
await this.storageservice.get("Notifications").then((value) => {
console.log('Get notification data', )
console.log('Get notification data',)
this.notificationLength = value.length;
console.log('Call notification data',this.notificationLength)
console.log('Call notification data', this.notificationLength)
}).catch((error) => {
if (!error) {