From 584662ca65e87c3c9fb997fc1c68a8e4d0eccab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 8 Feb 2022 10:21:50 +0100 Subject: [PATCH 1/7] bug addimage chat --- src/app/pages/chat/messages/messages.page.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index cc7d24b79..e49730994 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -653,7 +653,9 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { const roomId = this.roomId const file: any = await this.fileService.getFileFromDevice(types); + console.log('ADDFILECHAT', file) const imageData = await this.fileToBase64Service.convert(file) + console.log('ADDFILECHAT', imageData) const formData = new FormData(); formData.append("blobFile", file); From e86b7749c5cc4e5e85f4d356b5d18c446ef9bcec Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Tue, 8 Feb 2022 14:22:32 +0100 Subject: [PATCH 2/7] auto login chat --- src/app/guards/auth.guard.ts | 5 ++- .../set-room-owner/set-room-owner.page.ts | 1 - .../book-meeting-modal.page.ts | 1 - src/app/pages/login/login.page.ts | 1 - src/app/services/auth.service.ts | 45 +++++++++---------- src/app/services/functions/file.service.ts | 4 +- .../shared/chat/new-group/new-group.page.ts | 1 - src/app/store/session.service.ts | 6 +-- 8 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/app/guards/auth.guard.ts b/src/app/guards/auth.guard.ts index 74a8e799d..b0724113e 100644 --- a/src/app/guards/auth.guard.ts +++ b/src/app/guards/auth.guard.ts @@ -1,6 +1,7 @@ import { Injectable } from '@angular/core'; import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router'; import { Observable } from 'rxjs'; +import { AuthService } from '../services/auth.service'; import { LocalstoreService } from '../store/localstore.service'; import { SessionStore } from '../store/session.service'; @@ -10,7 +11,8 @@ import { SessionStore } from '../store/session.service'; export class AuthGuard implements CanActivate { constructor( private router:Router, - private localstoreService: LocalstoreService + private localstoreService: LocalstoreService, + private authService: AuthService, ){} canActivate( @@ -25,6 +27,7 @@ export class AuthGuard implements CanActivate { this.router.navigate(['/']); return false } else { + this.authService.loginChat(SessionStore.user) return true } } diff --git a/src/app/modals/set-room-owner/set-room-owner.page.ts b/src/app/modals/set-room-owner/set-room-owner.page.ts index ac9939bf2..89d728161 100644 --- a/src/app/modals/set-room-owner/set-room-owner.page.ts +++ b/src/app/modals/set-room-owner/set-room-owner.page.ts @@ -84,7 +84,6 @@ export class SetRoomOwnerPage implements OnInit { } this.chatService.addGroupOwner(body).subscribe((res)=>{ - alert('here'); console.log(res); this.close(); this.toastService._successMessage('Operação realizada com sucesso'); diff --git a/src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.ts b/src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.ts index 87b8de6dd..08d599ff8 100644 --- a/src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.ts +++ b/src/app/pages/gabinete-digital/expediente/book-meeting-modal/book-meeting-modal.page.ts @@ -261,7 +261,6 @@ export class BookMeetingModalPage implements OnInit { } if(this.task.FsId == '8') { - alert('Chegou') const loader = this.toastService.loading() try { switch (this.loggeduser.Profile) { diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 7373f3c72..46be42992 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -100,7 +100,6 @@ export class LoginPage implements OnInit { // login to API successfully if (attempt) { - if (attempt.UserId == SessionStore.user.UserId) { await this.authService.SetSession(attempt, this.userattempt); await this.authService.loginChat(this.userattempt); diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index f26ca9f5e..5a04f1b6d 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -103,44 +103,41 @@ export class AuthService { } } - //Login to rocketChat server - async loginChat(user: UserForm) { - const expireDate = new Date(new Date().getTime() + 60*1000); + //Login to rocketChat server2 + //user: UserForm + async loginChat(user: any) { + + const expirationMinutes = 60; + let date = new Date().getTime(); + let expirationDate = new Date(new Date().getTime() + expirationMinutes*60*1000); + let postData = { - "user": user.username, - "password": user.password, + "user": user.RochetChatUser, + "password": user.Password, } let responseChat = await this.httpService.post('login', postData).toPromise(); if(responseChat) { - - 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) - }) - }, 1) - - console.log('Login to Rocket chat OK'); + console.log('Login to Rocket chat OK', responseChat); this.ValidatedUserChat = responseChat; localStorage.setItem('userChat', JSON.stringify(responseChat)); this.storageService.store(AuthConnstants.AUTH, responseChat); - - this.autologout(10000); - - return true; - + //return true; } else{ console.log('Network error'); this.presentAlert('Network error'); - return false; + //return false; } + + this.autoLoginChat(expirationDate.getTime() - date, user); + } + + async autoLoginChat(expirationDate:number, user:any){ + setTimeout(()=>{ + this.loginChat(user); + }, expirationDate) } autologout(expirationDate:number){ diff --git a/src/app/services/functions/file.service.ts b/src/app/services/functions/file.service.ts index f864b398f..d696224de 100644 --- a/src/app/services/functions/file.service.ts +++ b/src/app/services/functions/file.service.ts @@ -336,7 +336,7 @@ export class FileService { quality: 50, // allowEditing: true, resultType: CameraResultType.Uri, - source: CameraSource.Camera + source: CameraSource.Photos }); @@ -378,6 +378,8 @@ export class FileService { //loader.remove(); }); */ } + + addPictureToChat(roomId) { console.log('add picture to chat') diff --git a/src/app/shared/chat/new-group/new-group.page.ts b/src/app/shared/chat/new-group/new-group.page.ts index 9bcc2eddc..75b4f7d37 100644 --- a/src/app/shared/chat/new-group/new-group.page.ts +++ b/src/app/shared/chat/new-group/new-group.page.ts @@ -67,7 +67,6 @@ export class NewGroupPage implements OnInit{ } /* ngOnDestroy(){ - alert('Destroy') this.dataService.set("newGroup", false); this.dataService.set("task", null); this.dataService.set("newGroupName", ''); diff --git a/src/app/store/session.service.ts b/src/app/store/session.service.ts index 3e480e7bc..e1f510138 100644 --- a/src/app/store/session.service.ts +++ b/src/app/store/session.service.ts @@ -12,7 +12,7 @@ class SessionService { // main data private _user = new UserSession() // local storage keyName - private keyName: string; + private keyName: string; constructor() { @@ -73,7 +73,7 @@ class SessionService { return false } return this._user.PIN.length >= 2 - + } reset(user) { @@ -98,4 +98,4 @@ class SessionService { } -export const SessionStore = new SessionService() \ No newline at end of file +export const SessionStore = new SessionService() From eea38ad05bd953ff83b91953239e349998cfb264 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Tue, 8 Feb 2022 15:41:40 +0100 Subject: [PATCH 3/7] save --- src/app/services/chat/ws-chat-methods.service.ts | 4 ++-- src/app/services/chat/ws-chat.service.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 6ea061412..9d3a6268f 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -187,12 +187,12 @@ export class WsChatMethodsService { */ private defaultSubtribe(id: any) { this.WsChatService.streamRoomMessages(id).then((subscription)=>{ - console.log('streamRoomMessages', subscription) + //console.log('streamRoomMessages', subscription) }) this.WsChatService.subStreamNotifyRoom(id, 'typing', false) this.WsChatService.streamNotifyRoomDeleteMessage(id).then((subscription)=>{ - console.log('streamNotifyRoomDeleteMessage', subscription); + //console.log('streamNotifyRoomDeleteMessage', subscription); }) } diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 593b79276..d4904bf0c 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -657,11 +657,11 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { for (const [key, item] of Object.entries(this.wsMsgQueue)) { if(item.loginRequired == true && this.isLogin == true) { - console.log('run msgQueue ', key) + //console.log('run msgQueue ', key) this.ws.send(item); delete this.wsMsgQueue[key] } else if(item.loginRequired == false) { - console.log('run msgQueue ', key) + //console.log('run msgQueue ', key) this.ws.send(item); delete this.wsMsgQueue[key] } From 4602615716e709a22fc5a0712779a5b2b1b791ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 8 Feb 2022 15:45:09 +0100 Subject: [PATCH 4/7] add image to chat bug --- src/app/pages/chat/messages/messages.page.ts | 43 +++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 9fe3739e2..1d8ddfbea 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -38,6 +38,7 @@ import { FileType } from 'src/app/models/fileType'; import { SearchPage } from 'src/app/pages/search/search.page'; import { Storage } from '@ionic/storage'; import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service'; +import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; const IMAGE_DIR = 'stored-images'; @@ -552,6 +553,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { }) } + + async addImageMobile() { + this.addFileToChatMobile(['image/apng', 'image/jpeg', 'image/png']) + } async addImage() { this.addFileToChat(['image/apng', 'image/jpeg', 'image/png']) @@ -605,6 +610,42 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { }); } + async addFileToChatMobile(types: typeof FileType[] ) { + const roomId = this.roomId + + const file = await Camera.getPhoto({ + quality: 90, + // allowEditing: true, + resultType: CameraResultType.Base64, + source: CameraSource.Photos + }); + console.log('ADDFILECHAT', file) + //const imageData = await this.fileToBase64Service.convert(file) + //console.log('ADDFILECHAT', imageData) + + const response = await fetch(file.base64String!); + const blob = await response.blob(); + + const formData = new FormData(); + formData.append("blobFile", blob); + + this.wsChatMethodsService.getDmRoom(roomId).send({ + file: { + "type": "application/img", + "guid": '', + "image_url": 'data:image/jpeg;base64,' +file.base64String + }, + temporaryData: formData, + attachments: [{ + "title": file.path , + "image_url": 'data:image/jpeg;base64,' +file.base64String, + "text": "description", + "title_link_download": false, + }] + }) + + } + async addFileToChat(types: typeof FileType[] ) { @@ -660,7 +701,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { this.takePicture() } else if (res['data'] == 'add-picture') { - this.addImage() + this.addImageMobile() } else if (res['data'] == 'add-document') { this.addFile() From 0c01cb1ebc1bf3a3953b031542f24655c8714560 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Tue, 8 Feb 2022 16:23:30 +0100 Subject: [PATCH 5/7] save --- src/app/services/auth.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index be564c886..fbf7b762b 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -116,8 +116,8 @@ export class AuthService { let expirationDate = new Date(new Date().getTime() + expirationMinutes*60*1000); let postData = { - "user": user.RochetChatUser, - "password": user.Password, + "user": SessionStore.user.RochetChatUser, + "password": SessionStore.user.Password, } let responseChat = await this.httpService.post('login', postData).toPromise(); From b169ff5687d66d4e4fef1b015e4ccafc20614105 Mon Sep 17 00:00:00 2001 From: "tiago.kayaya" Date: Tue, 8 Feb 2022 16:37:32 +0100 Subject: [PATCH 6/7] save --- src/app/guards/auth.guard.ts | 4 ++-- src/app/pages/inactivity/inactivity.page.ts | 20 ++++++++++---------- src/app/pages/login/login.page.ts | 4 ++-- src/app/services/auth.service.ts | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/app/guards/auth.guard.ts b/src/app/guards/auth.guard.ts index f6ed7fa9b..17b45ac9f 100644 --- a/src/app/guards/auth.guard.ts +++ b/src/app/guards/auth.guard.ts @@ -29,8 +29,8 @@ export class AuthGuard implements CanActivate { this.router.navigate(['/']); return false } else { - this.authService.loginChat(SessionStore.user) - return true + this.authService.loginChat(); + return true; } } diff --git a/src/app/pages/inactivity/inactivity.page.ts b/src/app/pages/inactivity/inactivity.page.ts index 7b52d83da..4a60452d7 100644 --- a/src/app/pages/inactivity/inactivity.page.ts +++ b/src/app/pages/inactivity/inactivity.page.ts @@ -36,11 +36,11 @@ export class InactivityPage implements OnInit { loop = false ngOnInit() { - + // window.addEventListener('resize', (event) => { // if(this.router.url != '/login') return false - + // if(this.loop == false) { // this.loop = true // this.runloop() @@ -54,7 +54,7 @@ export class InactivityPage implements OnInit { // const containerHeight = 651 // let circleHeight = document.querySelector('.circle')['offsetHeight'] - // let circleWidth = document.querySelector('.circle')['offsetWidth'] + // let circleWidth = document.querySelector('.circle')['offsetWidth'] // console.log(window.innerHeight, ' < ', containerHeight) // console.log(circleHeight) @@ -64,7 +64,7 @@ export class InactivityPage implements OnInit { // e['style']['width'] = (circleWidth -1 )+'px' // }) - + // if( window.innerHeight< containerHeight) { // setTimeout(()=>{ // this.runloop() @@ -114,14 +114,14 @@ export class InactivityPage implements OnInit { let attempt = await this.authService.login(this.userattempt, {saveSession: false}) if (attempt) { - + // if current attemp is equal to the current user if (attempt.UserId == SessionStore.user.UserId) { await this.authService.SetSession(attempt, this.userattempt); - this.authService.loginChat(this.userattempt); + this.authService.loginChat(); this.getToken(); SessionStore.setInativity(true) - + this.goback() } else { SessionStore.delete() @@ -174,10 +174,10 @@ export class InactivityPage implements OnInit { const code = this.code.join('') if( SessionStore.validatePin(code)) { - + SessionStore.setInativity(true) this.goback() - + setTimeout(()=>{ this.clearCode() }, 1000) @@ -196,7 +196,7 @@ export class InactivityPage implements OnInit { } else { this.router.navigate(['/home/events'], {replaceUrl: true}); } - + } storePin() { diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 46be42992..de8e9d8f8 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -102,7 +102,7 @@ export class LoginPage implements OnInit { if (attempt) { if (attempt.UserId == SessionStore.user.UserId) { await this.authService.SetSession(attempt, this.userattempt); - await this.authService.loginChat(this.userattempt); + await this.authService.loginChat(); this.getToken(); SessionStore.setInativity(true); @@ -116,7 +116,7 @@ export class LoginPage implements OnInit { await this.authService.SetSession(attempt, this.userattempt); this.changeProfileService.run() - await this.authService.loginChat(this.userattempt); + await this.authService.loginChat(); this.getToken(); this.router.navigateByUrl('/pin', { replaceUrl: true }); } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index fbf7b762b..5698453cd 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -109,7 +109,7 @@ export class AuthService { //Login to rocketChat server2 //user: UserForm - async loginChat(user: any) { + async loginChat() { const expirationMinutes = 60; let date = new Date().getTime(); @@ -136,12 +136,12 @@ export class AuthService { this.presentAlert('Network error'); } - this.autoLoginChat(expirationDate.getTime() - date, user); + this.autoLoginChat(expirationDate.getTime() - date); } - async autoLoginChat(expirationDate:number, user:any){ + async autoLoginChat(expirationDate:number){ setTimeout(()=>{ - this.loginChat(user); + this.loginChat(); }, expirationDate) } From 813e9518564e4e77a0d9c9b0e5de8588e4894cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eudes=20In=C3=A1cio?= Date: Tue, 8 Feb 2022 17:14:14 +0100 Subject: [PATCH 7/7] add image to chat done! --- src/app/pages/chat/messages/messages.page.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 1d8ddfbea..8f400df01 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -623,7 +623,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { //const imageData = await this.fileToBase64Service.convert(file) //console.log('ADDFILECHAT', imageData) - const response = await fetch(file.base64String!); + const response = await fetch('data:image/jpeg;base64,'+ file.base64String!); const blob = await response.blob(); const formData = new FormData();