mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 13:02:56 +00:00
merge with Peter branch
This commit is contained in:
@@ -59,6 +59,7 @@ export class MessageService {
|
||||
downloadAttachments = false;
|
||||
downloadAttachmentsTemp = 0;
|
||||
UploadAttachmentsTemp = 0;
|
||||
manualRetry = false
|
||||
|
||||
constructor(
|
||||
private NfService: NfService,
|
||||
@@ -70,7 +71,7 @@ export class MessageService {
|
||||
private ChatSystemService: ChatSystemService) {
|
||||
}
|
||||
|
||||
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, from }:Message) {
|
||||
setData({customFields = {}, channels, mentions, msg ,rid ,ts, u, t, _id, id, _updatedAt, file, attachments, temporaryData, localReference , viewed = [], received = [], delate = false, delateRequest =false, from, sendAttempt = 0 }:Message) {
|
||||
|
||||
this.channels = channels || []
|
||||
this.mentions = mentions || []
|
||||
@@ -87,6 +88,7 @@ export class MessageService {
|
||||
this.id = id
|
||||
this.delate = delate
|
||||
this.delateRequest = delateRequest
|
||||
this.sendAttempt = 0
|
||||
|
||||
if(this.attachments?.length >= 1 && attachments?.length >= 1) {
|
||||
this.attachments[0] = Object.assign(this.attachments[0], attachments[0])
|
||||
@@ -148,6 +150,7 @@ export class MessageService {
|
||||
async send(): Promise<any> {
|
||||
|
||||
this.sendAttempt++;
|
||||
this.manualRetry = false
|
||||
|
||||
if(!this.hasFile) {
|
||||
|
||||
@@ -215,8 +218,10 @@ export class MessageService {
|
||||
|
||||
}
|
||||
|
||||
async sendRequest(params) {
|
||||
|
||||
functionTimer = null;
|
||||
|
||||
async sendRequest(params) {
|
||||
if(params?.attachments) {
|
||||
if(params?.attachments[0]?.image_url) {
|
||||
delete params?.attachments[0]?.image_url
|
||||
@@ -225,19 +230,64 @@ export class MessageService {
|
||||
|
||||
if(this.NetworkServiceService.getCurrentNetworkStatus() == ConnectionStatus.Online) {
|
||||
// console.log('online send')
|
||||
this.RochetChatConnectorService.send(params).then(
|
||||
(ChatMessage: any) => {
|
||||
ChatMessage = ChatMessage.message.result
|
||||
|
||||
this.messageSend = true
|
||||
this.redefinedMessage(ChatMessage)
|
||||
if(this.msg == '<script></script>') {
|
||||
if(this.sendAttempt >= 4) {
|
||||
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)
|
||||
})
|
||||
}
|
||||
).catch((error) => {
|
||||
console.error(error)
|
||||
})
|
||||
|
||||
} else {
|
||||
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})
|
||||
|
||||
}, 3000)
|
||||
|
||||
} else {
|
||||
// console.log("reconnect")
|
||||
this.RochetChatConnectorService.registerCallback({
|
||||
type: 'reConnect',
|
||||
funx: async ()=> {
|
||||
@@ -257,6 +307,8 @@ export class MessageService {
|
||||
|
||||
const message = this.getChatObj()
|
||||
|
||||
this.manualRetry = false
|
||||
|
||||
ChatMessage = Object.assign(message, ChatMessage)
|
||||
this.setData(ChatMessage)
|
||||
|
||||
@@ -335,6 +387,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) {
|
||||
@@ -570,7 +574,7 @@ export class RochetChatConnectorService {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message) => {
|
||||
|
||||
// console.log();
|
||||
|
||||
if(message.id == requestId || message?.subs?.[0] == requestId) { // same request send
|
||||
resolve(message)
|
||||
return true
|
||||
@@ -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