src/app/guards/auth.guard.ts

This commit is contained in:
Peter Maquiran
2023-01-03 22:04:33 +01:00
parent fcc8bc6b74
commit 0e5b739df5
4 changed files with 60 additions and 42 deletions
-3
View File
@@ -6,7 +6,6 @@ import { PermissionService } from '../services/permission.service';
import { LocalstoreService } from '../store/localstore.service';
import { SessionStore } from '../store/session.service';
import { RouteService } from 'src/app/services/route.service'
import { InformationPage } from 'src/app/modals/information/information.page'
import { FirstEnterService } from 'src/app/services/first-enter.service'
// import { ModalController } from '@ionic/angular';
import { AlertController, Platform } from '@ionic/angular';
@@ -20,9 +19,7 @@ export class AuthGuard implements CanActivate {
public p: PermissionService,
private RouteService: RouteService,
private FirstEnterService: FirstEnterService,
private InformationPage: InformationPage,
private alertController: AlertController,
// private modalController: ModalController,
){}
canActivate(
+50 -29
View File
@@ -12,6 +12,8 @@ import { HttpEventType } from '@angular/common/http';
import { AttachmentsService } from 'src/app/services/attachments.service';
import { NetworkServiceService , ConnectionStatus} from 'src/app/services/network-service.service';
import { ChatSystemService } from './chat-system.service';
import { resolve } from 'dns';
import { async } from '@angular/core/testing';
@Injectable({
providedIn: 'root'
})
@@ -149,6 +151,12 @@ export class MessageService {
async send(): Promise<any> {
if(this.messageSend) {
return new Promise((resolve, reject) => {
resolve('solve')
})
}
this.sendAttempt++;
this.manualRetry = false
@@ -164,26 +172,10 @@ export class MessageService {
} else {
this.uploadingFile = true
let uploadSuccessfully = false
if(this.hasSendAttachment == false) {
try {
uploadSuccessfully = await this.NfService.beforeSendAttachment(this)
} catch (error) {
console.error('beforeSendAttachment uploadSuccessfully',error)
}
this.UploadAttachmentsTemp++
}
this.uploadingFile = false
let uploadSuccessfully = await this.sendRequestAttachment()
if(uploadSuccessfully) {
this.hasSendAttachment = true
this.errorUploadingAttachment = false
this.temporaryData = {}
const params = {roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file, localReference: this.localReference}
await this.sendRequest(params)
@@ -199,19 +191,23 @@ export class MessageService {
}
})
} else if(uploadSuccessfully == false && this.UploadAttachmentsTemp == 1) {
this.send().catch((error) =>{
console.error(error)
} else if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Offline) {
this.RochetChatConnectorService.registerCallback({
type: 'reConnect',
funx: async ()=> {
await this.send().catch((error) => {
console.error(error)
})
return true
}
})
}
else if(uploadSuccessfully == false) {
this.errorUploadingAttachment = true
return new Promise((resolve, reject) => {
reject(false)
})
} else if (this.UploadAttachmentsTemp <= 3) {
setTimeout(async () => {
return await this.send()
}, 3000)
} else if (this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) {
this.manualRetry = true
}
}
@@ -221,6 +217,31 @@ export class MessageService {
functionTimer = null;
async sendRequestAttachment() {
this.uploadingFile = true
let uploadSuccessfully = false
if(this.hasSendAttachment == false) {
try {
uploadSuccessfully = await this.NfService.beforeSendAttachment(this)
this.UploadAttachmentsTemp++
this.uploadingFile = false
this.manualRetry = false
this.errorUploadingAttachment = false
this.hasSendAttachment = true
this.temporaryData = {}
} catch (error) {
this.uploadingFile = false
this.errorUploadingAttachment = true
console.error('beforeSendAttachment error:', error)
}
}
return uploadSuccessfully
}
async sendRequest(params) {
if(params?.attachments) {
if(params?.attachments[0]?.image_url) {