mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
chat retry
This commit is contained in:
@@ -59,6 +59,7 @@ export class MessageService {
|
||||
downloadAttachments = false;
|
||||
downloadAttachmentsTemp = 0;
|
||||
UploadAttachmentsTemp = 0;
|
||||
manualRetry = false
|
||||
|
||||
constructor(
|
||||
private NfService: NfService,
|
||||
@@ -215,6 +216,9 @@ export class MessageService {
|
||||
|
||||
}
|
||||
|
||||
|
||||
functionTimer = null;
|
||||
|
||||
async sendRequest(params) {
|
||||
|
||||
if(params?.attachments) {
|
||||
@@ -228,16 +232,41 @@ export class MessageService {
|
||||
this.RochetChatConnectorService.send(params).then(
|
||||
(ChatMessage: any) => {
|
||||
ChatMessage = ChatMessage.message.result
|
||||
clearTimeout(this.functionTimer);
|
||||
|
||||
this.messageSend = true
|
||||
this.redefinedMessage(ChatMessage)
|
||||
|
||||
}
|
||||
).catch((error) => {
|
||||
clearTimeout(this.functionTimer);
|
||||
console.error(error)
|
||||
})
|
||||
|
||||
this.functionTimer = setTimeout(() => {
|
||||
|
||||
this.RochetChatConnectorService.registerCallback({
|
||||
type:'Onmessage',
|
||||
key:'ping-pong-message',
|
||||
funx:(message: any) => {
|
||||
if(message.msg == "ping") {
|
||||
if(this.sendAttempt >= 3) {
|
||||
this.manualRetry = true
|
||||
} else {
|
||||
this.send()
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
this.save()
|
||||
}
|
||||
})
|
||||
|
||||
this.RochetChatConnectorService.wsSend({message:{msg:"pong"}, loginRequired: false})
|
||||
|
||||
}, 8000)
|
||||
|
||||
} else {
|
||||
// console.log("reconnect")
|
||||
this.RochetChatConnectorService.registerCallback({
|
||||
type: 'reConnect',
|
||||
funx: async ()=> {
|
||||
@@ -335,6 +364,7 @@ export class MessageService {
|
||||
channels: this.channels,
|
||||
mentions: this.mentions,
|
||||
//msg: this.AESEncrypt.encrypt(this.msg, SessionStore.user.UserName),
|
||||
sendAttempt: this.sendAttempt,
|
||||
msg:this.msg,
|
||||
rid: this.rid,
|
||||
ts: this.ts,
|
||||
|
||||
@@ -46,6 +46,10 @@ export class RochetChatConnectorService {
|
||||
|
||||
}
|
||||
|
||||
wsSend({message, requestId = uuidv4(), loginRequired = true}:send) {
|
||||
this.ws.send({message:{msg:"pong"}, loginRequired: false})
|
||||
}
|
||||
|
||||
login() {
|
||||
// dont login if is already login
|
||||
if(this.isLogin == true) {
|
||||
@@ -739,7 +743,7 @@ export class RochetChatConnectorService {
|
||||
} else {
|
||||
let messageStr = JSON.stringify(message)
|
||||
//
|
||||
// console.log(messageStr)
|
||||
console.log(messageStr)
|
||||
this.socket.send(messageStr)
|
||||
}
|
||||
return requestId
|
||||
@@ -747,6 +751,8 @@ export class RochetChatConnectorService {
|
||||
|
||||
onmessage: async (event: any)=> {
|
||||
const data = JSON.parse(event.data)
|
||||
|
||||
console.log('data', data)
|
||||
|
||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||
if(value.type== 'Onmessage') {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { FirstEnterService } from './first-enter.service';
|
||||
|
||||
describe('FirstEnterService', () => {
|
||||
let service: FirstEnterService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(FirstEnterService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,51 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
|
||||
|
||||
import { AlertController, Platform } from '@ionic/angular';
|
||||
import { PermissionService } from '../services/permission.service';
|
||||
import { SessionStore } from '../store/session.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class FirstEnterService {
|
||||
|
||||
constructor(private router:Router,
|
||||
private platform: Platform,
|
||||
public p: PermissionService,
|
||||
private alertController: AlertController) { }
|
||||
|
||||
|
||||
enter( ) {
|
||||
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){
|
||||
this.router.navigate(['/home/agenda']);
|
||||
}
|
||||
else{
|
||||
this.router.navigate(['/home/events']);
|
||||
}
|
||||
}
|
||||
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)) {
|
||||
this.router.navigate(['/home/publications']);
|
||||
} else {
|
||||
|
||||
this.alertController.create({
|
||||
cssClass: 'my-custom-class',
|
||||
header: 'Utilizador sem acesso a aplicação',
|
||||
buttons: [{
|
||||
text: 'Ok',
|
||||
handler: () => {
|
||||
|
||||
}
|
||||
}]
|
||||
}).then( async (alertPopup) => {
|
||||
await alertPopup.present();
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user