mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
fix ios notifications
This commit is contained in:
+23
-25
@@ -164,8 +164,6 @@ export class HomePage implements OnInit {
|
||||
|
||||
this.logDeviceInfo();
|
||||
|
||||
this.notificationsService.onReciveForeground();
|
||||
this.notificationsService.onReciveBackground();
|
||||
|
||||
window.addEventListener('online', () => {
|
||||
this.backgroundservice.online()
|
||||
@@ -238,20 +236,20 @@ export class HomePage implements OnInit {
|
||||
}, 1000)
|
||||
|
||||
|
||||
/* if (!this.platform.is('desktop')) {
|
||||
App.addListener('appStateChange', ({ isActive }) => {
|
||||
if (isActive) {
|
||||
// The app is in the foreground.
|
||||
console.log('App is in the foreground');
|
||||
this.RochetChatConnectorService.connect()
|
||||
this.reloadComponent(true)
|
||||
} else {
|
||||
// The app is in the background.
|
||||
console.log('App is in the background');
|
||||
// You can perform actions specific to the background state here.
|
||||
}
|
||||
});
|
||||
} */
|
||||
/* if (!this.platform.is('desktop')) {
|
||||
App.addListener('appStateChange', ({ isActive }) => {
|
||||
if (isActive) {
|
||||
// The app is in the foreground.
|
||||
console.log('App is in the foreground');
|
||||
this.RochetChatConnectorService.connect()
|
||||
this.reloadComponent(true)
|
||||
} else {
|
||||
// The app is in the background.
|
||||
console.log('App is in the background');
|
||||
// You can perform actions specific to the background state here.
|
||||
}
|
||||
});
|
||||
} */
|
||||
|
||||
}
|
||||
|
||||
@@ -344,15 +342,15 @@ export class HomePage implements OnInit {
|
||||
}
|
||||
|
||||
|
||||
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.router.navigateByUrl('/',{skipLocationChange:true}).then(()=>{
|
||||
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.router.navigateByUrl('/', { skipLocationChange: true }).then(() => {
|
||||
this.router.navigate([`/${url}`]).then(() => {
|
||||
console.log(`After navigation I am on:${this.router.url}`)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ export class InactivityPage implements OnInit {
|
||||
public alertController: AlertController,
|
||||
public ThemeService: ThemeService,
|
||||
public p: PermissionService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
loop = false
|
||||
|
||||
ngOnInit() {}
|
||||
ngOnInit() { }
|
||||
|
||||
runloop() {
|
||||
|
||||
@@ -71,7 +71,7 @@ export class InactivityPage implements OnInit {
|
||||
async Login() {
|
||||
|
||||
if (this.validateUsername()) {
|
||||
if(this.validatePassword()) {
|
||||
if (this.validatePassword()) {
|
||||
|
||||
this.userattempt = {
|
||||
username: this.username,
|
||||
@@ -79,7 +79,7 @@ export class InactivityPage implements OnInit {
|
||||
domainName: environment.domain,
|
||||
BasicAuthKey: ""
|
||||
}
|
||||
let attempt = await this.authService.login(this.userattempt, {saveSession: false})
|
||||
let attempt = await this.authService.login(this.userattempt, { saveSession: false })
|
||||
|
||||
if (attempt) {
|
||||
|
||||
@@ -88,7 +88,7 @@ export class InactivityPage implements OnInit {
|
||||
if (attempt.UserId == SessionStore.user.UserId) {
|
||||
await this.authService.SetSession(attempt, this.userattempt);
|
||||
|
||||
if(this.p.userPermission(this.p.permissionList.Chat.access)){
|
||||
if (this.p.userPermission(this.p.permissionList.Chat.access)) {
|
||||
// this.authService.loginChat();
|
||||
}
|
||||
|
||||
@@ -119,18 +119,18 @@ export class InactivityPage implements OnInit {
|
||||
getToken() {
|
||||
this.notificatinsservice.requestPermissions();
|
||||
this.notificatinsservice.registrationError();
|
||||
this.notificatinsservice.getAndpostToken(this.username);
|
||||
// this.notificatinsservice.getAndpostToken(this.username);
|
||||
}
|
||||
|
||||
setCode(code: string) {
|
||||
|
||||
if(this.code.length < 4) {
|
||||
if (this.code.length < 4) {
|
||||
this.code.push(code)
|
||||
}
|
||||
|
||||
if(this.code.length == 4) {
|
||||
if (this.code.length == 4) {
|
||||
|
||||
if(!SessionStore.hasPin) {
|
||||
if (!SessionStore.hasPin) {
|
||||
//
|
||||
this.storePin()
|
||||
this.pinLogin()
|
||||
@@ -141,14 +141,14 @@ export class InactivityPage implements OnInit {
|
||||
}
|
||||
|
||||
clearCode() {
|
||||
this.code =[]
|
||||
this.code = []
|
||||
}
|
||||
|
||||
pinLogin() {
|
||||
|
||||
const code = this.code.join('')
|
||||
|
||||
if( SessionStore.validatePin(code)) {
|
||||
if (SessionStore.validatePin(code)) {
|
||||
|
||||
SessionStore.setInativity(true)
|
||||
this.goback()
|
||||
@@ -166,26 +166,26 @@ export class InactivityPage implements OnInit {
|
||||
|
||||
goback() {
|
||||
const pathName = this.SessionStore.user.UrlBeforeInactivity
|
||||
if(pathName) {
|
||||
this.router.navigate([pathName],{replaceUrl: true});
|
||||
if (pathName) {
|
||||
this.router.navigate([pathName], { replaceUrl: true });
|
||||
} else {
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
if(this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)){
|
||||
if (this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)) {
|
||||
//When user has got access to Agenda but does not have their own calendar, goes to Agenda
|
||||
if(this.p.userPermission(this.p.permissionList.Agenda.access) && SessionStore.user.OwnerCalendars.length == 0){
|
||||
if (this.p.userPermission(this.p.permissionList.Agenda.access) && SessionStore.user.OwnerCalendars.length == 0) {
|
||||
this.router.navigate(['/home/agenda']);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
this.router.navigate(['/home/events']);
|
||||
}
|
||||
}
|
||||
//If user has access permission to both Chat and Action, goes to Chat by default.
|
||||
else if((this.p.userPermission(this.p.permissionList.Chat.access) && this.p.userPermission(this.p.permissionList.Actions.access)) || this.p.userPermission(this.p.permissionList.Chat.access)){
|
||||
else if ((this.p.userPermission(this.p.permissionList.Chat.access) && this.p.userPermission(this.p.permissionList.Actions.access)) || this.p.userPermission(this.p.permissionList.Chat.access)) {
|
||||
this.router.navigate(['/home/chat']);
|
||||
}
|
||||
else if(this.p.userPermission(this.p.permissionList.Actions.access)){
|
||||
else if (this.p.userPermission(this.p.permissionList.Actions.access)) {
|
||||
this.router.navigate(['/home/publications']);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ export class LoginPage implements OnInit {
|
||||
userattempt: UserForm;
|
||||
code = []
|
||||
|
||||
hasPin: boolean
|
||||
hasPin: boolean
|
||||
loginPreference: string
|
||||
|
||||
sessionStore = SessionStore;
|
||||
@@ -56,16 +56,16 @@ export class LoginPage implements OnInit {
|
||||
private ChatService: ChatService,
|
||||
private platform: Platform,
|
||||
private FirstEnterService: FirstEnterService,
|
||||
private storage:Storage,
|
||||
private storage: Storage,
|
||||
private storageService: StorageService,
|
||||
) {}
|
||||
) { }
|
||||
|
||||
ngOnInit() {}
|
||||
ngOnInit() { }
|
||||
|
||||
togglePassword() {
|
||||
this.showPassword = !this.showPassword;
|
||||
|
||||
if(this.passwordIcon == "eye") {
|
||||
if (this.passwordIcon == "eye") {
|
||||
this.passwordIcon = "eye-off";
|
||||
} else {
|
||||
this.passwordIcon = "eye";
|
||||
@@ -101,14 +101,14 @@ export class LoginPage implements OnInit {
|
||||
getToken() {
|
||||
this.notificatinsservice.requestPermissions();
|
||||
this.notificatinsservice.registrationError();
|
||||
this.notificatinsservice.getAndpostToken(this.username);
|
||||
// this.notificatinsservice.getAndpostToken(this.username);
|
||||
}
|
||||
|
||||
async Login() {
|
||||
|
||||
|
||||
if (this.validateUsername()) {
|
||||
if(this.validatePassword()) {
|
||||
if (this.validatePassword()) {
|
||||
|
||||
this.userattempt = {
|
||||
username: this.username.trim(),
|
||||
@@ -119,8 +119,8 @@ export class LoginPage implements OnInit {
|
||||
|
||||
const loader = this.toastService.loading()
|
||||
|
||||
let attempt = await this.authService.login(this.userattempt, {saveSession: false})
|
||||
const data = await this.authService.loginContenteProduction(this.userattempt, {saveSession: true})
|
||||
let attempt = await this.authService.login(this.userattempt, { saveSession: false })
|
||||
const data = await this.authService.loginContenteProduction(this.userattempt, { saveSession: true })
|
||||
|
||||
|
||||
loader.remove()
|
||||
@@ -132,7 +132,7 @@ export class LoginPage implements OnInit {
|
||||
CPSession.save(data)
|
||||
this.changeProfileService.run();
|
||||
|
||||
if(attempt.ChatData) {
|
||||
if (attempt.ChatData) {
|
||||
|
||||
await this.authService.loginToChatWs();
|
||||
this.ChatService.setheader()
|
||||
@@ -167,16 +167,16 @@ export class LoginPage implements OnInit {
|
||||
|
||||
|
||||
|
||||
if(attempt.ChatData) {
|
||||
if (attempt.ChatData) {
|
||||
await this.authService.loginToChatWs();
|
||||
this.ChatService.setheader();
|
||||
this.ChatSystemService.loadChat();
|
||||
}
|
||||
this.storageService.remove("Notifications")
|
||||
this.getToken();
|
||||
this.getToken();
|
||||
|
||||
if(!this.platform.is('desktop') && !this.platform.is('mobileweb')) {
|
||||
if(this.sessionStore.hasPin) {
|
||||
if (!this.platform.is('desktop') && !this.platform.is('mobileweb')) {
|
||||
if (this.sessionStore.hasPin) {
|
||||
this.router.navigateByUrl('/home/events');
|
||||
} else {
|
||||
this.router.navigateByUrl('/pin', { replaceUrl: true });
|
||||
@@ -207,23 +207,23 @@ export class LoginPage implements OnInit {
|
||||
|
||||
goback() {
|
||||
const pathName = SessionStore.user.UrlBeforeInactivity
|
||||
if(pathName) {
|
||||
if (pathName) {
|
||||
this.router.navigate([pathName]);
|
||||
} else {
|
||||
if(this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)){
|
||||
if (this.p.userPermission(this.p.permissionList.Agenda.access) || this.p.userPermission(this.p.permissionList.Gabinete.access)) {
|
||||
//When user has got access to Agenda but does not have their own calendar, goes to Agenda
|
||||
if(this.p.userPermission(this.p.permissionList.Agenda.access) && SessionStore.user.OwnerCalendars.length == 0){
|
||||
if (this.p.userPermission(this.p.permissionList.Agenda.access) && SessionStore.user.OwnerCalendars.length == 0) {
|
||||
this.router.navigate(['/home/agenda']);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
this.router.navigate(['/home/events']);
|
||||
}
|
||||
}
|
||||
//If user has access permission to both Chat and Action, goes to Chat by default.
|
||||
else if((this.p.userPermission(this.p.permissionList.Chat.access) && this.p.userPermission(this.p.permissionList.Actions.access)) || this.p.userPermission(this.p.permissionList.Chat.access)){
|
||||
else if ((this.p.userPermission(this.p.permissionList.Chat.access) && this.p.userPermission(this.p.permissionList.Actions.access)) || this.p.userPermission(this.p.permissionList.Chat.access)) {
|
||||
this.router.navigate(['/home/chat']);
|
||||
}
|
||||
else if(this.p.userPermission(this.p.permissionList.Actions.access)){
|
||||
else if (this.p.userPermission(this.p.permissionList.Actions.access)) {
|
||||
this.router.navigate(['/home/publications']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ import { Capacitor } from '@capacitor/core';
|
||||
import { AngularFireMessaging } from '@angular/fire/messaging';
|
||||
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
|
||||
|
||||
import { FCM } from '@capacitor-community/fcm';
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -51,6 +53,9 @@ export class NotificationsService {
|
||||
private afMessaging: AngularFireMessaging,
|
||||
public NotificationHolderService: NotificationHolderService) {
|
||||
|
||||
this.onReciveForeground();
|
||||
this.onReciveBackground();
|
||||
|
||||
}
|
||||
|
||||
getTokenByUserIdAndId(user, userID) {
|
||||
@@ -65,10 +70,11 @@ export class NotificationsService {
|
||||
if (!this.isPushNotificationsAvailable) {
|
||||
return false
|
||||
}
|
||||
PushNotifications.requestPermissions().then(result => {
|
||||
PushNotifications.requestPermissions().then(async (result) => {
|
||||
if (result.receive === 'granted') {
|
||||
// Register with Apple / Google to receive push via APNS/FCM
|
||||
PushNotifications.register();
|
||||
this.getAndpostToken("")
|
||||
} else {
|
||||
// Show some error
|
||||
}
|
||||
@@ -77,19 +83,31 @@ export class NotificationsService {
|
||||
}
|
||||
}
|
||||
|
||||
getAndpostToken(username) {
|
||||
private getAndpostToken(username) {
|
||||
const geturl = environment.apiURL + 'notifications/token';
|
||||
|
||||
if (this.platform.is('mobile')) {
|
||||
if (!this.isPushNotificationsAvailable) {
|
||||
return false
|
||||
}
|
||||
if (this.platform.is('ios')) {
|
||||
FCM.getToken()
|
||||
.then(r => {
|
||||
this.postToken(r.token, geturl)
|
||||
this.token = r.token
|
||||
// alert(this.token)
|
||||
})
|
||||
.catch(err => console.log(err));
|
||||
} else {
|
||||
|
||||
PushNotifications.addListener('registration',
|
||||
(token: Token) => {
|
||||
this.postToken(token.value, geturl)
|
||||
this.token = token.value
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
PushNotifications.addListener('registration',
|
||||
(token: Token) => {
|
||||
this.postToken(token.value, geturl)
|
||||
this.token = token.value
|
||||
}
|
||||
);
|
||||
} else {
|
||||
this.afMessaging.requestToken.subscribe(
|
||||
(token) => {
|
||||
@@ -103,7 +121,6 @@ export class NotificationsService {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -148,14 +165,18 @@ export class NotificationsService {
|
||||
|
||||
PushNotifications.addListener('registrationError',
|
||||
(error: any) => {
|
||||
this.active = false
|
||||
this.active = false;
|
||||
|
||||
(() => {
|
||||
throw ("error" + error.error)
|
||||
})();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
onReciveForeground() {
|
||||
|
||||
if(this.platform.is('mobile')) {
|
||||
if (this.platform.is('mobile')) {
|
||||
|
||||
if (!this.isPushNotificationsAvailable) {
|
||||
return false
|
||||
@@ -174,9 +195,9 @@ export class NotificationsService {
|
||||
this.afMessaging.messages.subscribe((notification) => {
|
||||
this.storenotification(notification)
|
||||
this.notificationReceived.emit();
|
||||
this.eventtrigger.publishSomeData({
|
||||
notification: "recive"
|
||||
})
|
||||
this.eventtrigger.publishSomeData({
|
||||
notification: "recive"
|
||||
})
|
||||
// Handle the received message, e.g., show a notification
|
||||
});
|
||||
}
|
||||
@@ -190,7 +211,7 @@ export class NotificationsService {
|
||||
|
||||
onReciveBackground() {
|
||||
|
||||
if(this.platform.is('mobile')) {
|
||||
if (this.platform.is('mobile')) {
|
||||
if (!this.isPushNotificationsAvailable) {
|
||||
return false
|
||||
}
|
||||
@@ -285,7 +306,7 @@ export class NotificationsService {
|
||||
|
||||
notificatinsRoutes = (notification) => {
|
||||
|
||||
console.log('BACK BACK',notification)
|
||||
console.log('BACK BACK', notification)
|
||||
|
||||
if (notification.notification.data.Service === "agenda" && notification.notification.data.IdObject.length > 10) {
|
||||
|
||||
@@ -336,8 +357,14 @@ export class NotificationsService {
|
||||
else if (notification.notification.data.Service === "gabinete-digital" && notification.notification.data.Object === "expedientes-pr") {
|
||||
this.zone.run(() => this.router.navigate(['/home/gabinete-digital/expedientes-pr', notification.notification.data.IdObject, 'gabinete-digital']));
|
||||
} else if (notification.notification.data.Service === "chat") {
|
||||
|
||||
let navigationExtras: NavigationExtras = { queryParams: { "roomId": notification.notification.data.IdObject, } };
|
||||
this.zone.run(() => this.router.navigate(['/home/chat'], navigationExtras));
|
||||
|
||||
this.zone.run(() => this.router.navigate(['/home/chat']));
|
||||
|
||||
setTimeout(() => {
|
||||
this.zone.run(() => this.router.navigate(['/home/chat'], navigationExtras));
|
||||
}, 200);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user