mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
Merge branch 'developer' of https://bitbucket.org/equilibriumito/gabinete-digital into feature/autologinchat
This commit is contained in:
@@ -12,6 +12,12 @@ import { AESEncrypt } from '../services/aesencrypt.service';
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
import { WsChatService } from 'src/app/services/chat/ws-chat.service';
|
||||
import { Router } from '@angular/router';
|
||||
import { NfService } from 'src/app/services/chat/nf.service'
|
||||
import { MessageService } from 'src/app/services/chat/message.service';
|
||||
import { ProcessesService } from 'src/app/services/processes.service';
|
||||
import { AttachmentsService } from 'src/app/services/attachments.service';
|
||||
import { RoomService } from './chat/room.service';
|
||||
import { Storage } from '@ionic/storage';
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
@@ -33,7 +39,11 @@ export class AuthService {
|
||||
private aesencrypt: AESEncrypt,
|
||||
private cookieService: CookieService,
|
||||
private WsChatService: WsChatService,
|
||||
private router: Router,) {
|
||||
private router: Router,
|
||||
private NfService:NfService,
|
||||
private processesService: ProcessesService,
|
||||
private AttachmentsService: AttachmentsService,
|
||||
private storage: Storage ) {
|
||||
|
||||
this.headers = new HttpHeaders();
|
||||
|
||||
@@ -41,13 +51,7 @@ export class AuthService {
|
||||
this.ValidatedUser = SessionStore.user
|
||||
|
||||
console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password)
|
||||
this.WsChatService.connect();
|
||||
this.WsChatService.login().then((message) => {
|
||||
console.log('rocket chat login successfully', message)
|
||||
this.WsChatService.setStatus('busy')
|
||||
}).catch((message)=>{
|
||||
console.log('rocket chat login failed', message)
|
||||
})
|
||||
this.loginToChatWs()
|
||||
|
||||
}
|
||||
|
||||
@@ -119,16 +123,17 @@ export class AuthService {
|
||||
let responseChat = await this.httpService.post('login', postData).toPromise();
|
||||
|
||||
if(responseChat) {
|
||||
console.log('Login to Rocket chat OK', responseChat);
|
||||
|
||||
this.loginToChatWs()
|
||||
|
||||
console.log('Login to Rocket chat OK');
|
||||
this.ValidatedUserChat = responseChat;
|
||||
localStorage.setItem('userChat', JSON.stringify(responseChat));
|
||||
this.storageService.store(AuthConnstants.AUTH, responseChat);
|
||||
//return true;
|
||||
}
|
||||
else{
|
||||
console.log('Network error');
|
||||
this.presentAlert('Network error');
|
||||
//return false;
|
||||
}
|
||||
|
||||
this.autoLoginChat(expirationDate.getTime() - date, user);
|
||||
@@ -140,6 +145,58 @@ export class AuthService {
|
||||
}, expirationDate)
|
||||
}
|
||||
|
||||
private loginToChatWs() {
|
||||
setTimeout(()=>{
|
||||
|
||||
this.WsChatService.connect();
|
||||
this.WsChatService.login().then((message) => {
|
||||
console.log('rocket chat login successfully', message)
|
||||
this.WsChatService.setStatus('online')
|
||||
}).catch((message)=>{
|
||||
console.log('rocket chat login failed', message)
|
||||
})
|
||||
|
||||
|
||||
this.NfService.beforeSendAttachment = async (message: MessageService, room?: RoomService) => {
|
||||
|
||||
if(message.hasFile) {
|
||||
if(message.file.type != 'application/webtrix') {
|
||||
const formData = message.temporaryData
|
||||
|
||||
try {
|
||||
let guid: any = await this.AttachmentsService.uploadFile(formData).toPromise()
|
||||
message.file.guid = guid.path
|
||||
await this.storage.set(guid.path, message.file.image_url).then(() => {
|
||||
console.log('add picture to chat IMAGE SAVED')
|
||||
message.getFileFromDb()
|
||||
});
|
||||
|
||||
return true
|
||||
} catch(e) {
|
||||
return false
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
const res = message.temporaryData
|
||||
let url = await this.processesService.GetDocumentUrl(res.data.selected.Id, res.data.selected.ApplicationType).toPromise();
|
||||
let url_no_options: string = url.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
|
||||
message.attachments[0].title_link = url_no_options
|
||||
message.attachments[0].message_link = url_no_options
|
||||
return true
|
||||
|
||||
} catch(e) {
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}, 1)
|
||||
}
|
||||
|
||||
autologout(expirationDate:number){
|
||||
setTimeout(()=>{
|
||||
this.logout();
|
||||
|
||||
Reference in New Issue
Block a user