diff --git a/src/app/modals/profile/profile.page.ts b/src/app/modals/profile/profile.page.ts index 926fe61f9..aee2e76e3 100644 --- a/src/app/modals/profile/profile.page.ts +++ b/src/app/modals/profile/profile.page.ts @@ -214,11 +214,13 @@ export class ProfilePage implements OnInit { } logout() { - SessionStore.setInativity(false) + this.authService.logout() + + /* SessionStore.setInativity(false) SessionStore.setUrlBeforeInactivity(this.router.url) setTimeout(() => { this.router.navigateByUrl('/', { replaceUrl: true }); - }, 100) + }, 100) */ } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index a508f72d2..f26ca9f5e 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -11,6 +11,7 @@ import { SessionStore } from '../store/session.service'; 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'; @Injectable({ providedIn: 'root' }) @@ -31,7 +32,8 @@ export class AuthService { public alertController: AlertController, private aesencrypt: AESEncrypt, private cookieService: CookieService, - private WsChatService: WsChatService) { + private WsChatService: WsChatService, + private router: Router,) { this.headers = new HttpHeaders(); @@ -101,12 +103,9 @@ export class AuthService { } } - logout() { - this.ValidatedUser = null; - } - //Login to rocketChat server async loginChat(user: UserForm) { + const expireDate = new Date(new Date().getTime() + 60*1000); let postData = { "user": user.username, "password": user.password, @@ -128,13 +127,14 @@ export class AuthService { }, 1) console.log('Login to Rocket chat OK'); - this.ValidatedUserChat = responseChat; - localStorage.setItem('userChat', JSON.stringify(responseChat)); this.storageService.store(AuthConnstants.AUTH, responseChat); - + + this.autologout(10000); + return true; + } else{ console.log('Network error'); @@ -143,6 +143,25 @@ export class AuthService { } } + autologout(expirationDate:number){ + setTimeout(()=>{ + this.logout(); + }, expirationDate) + } + + logout() { + + this.ValidatedUser = null; + localStorage.removeItem('userChat'); + + SessionStore.setInativity(false) + SessionStore.setUrlBeforeInactivity(this.router.url) + setTimeout(() => { + this.router.navigateByUrl('/', { replaceUrl: true }); + }, 100) + + } + //Get user data from RocketChat | global object getUserData(){ this.storageService.get(AuthConnstants.AUTH).then(res=>{ diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index f0d7af0d4..7e458ed1f 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -361,5 +361,9 @@ export class WsChatMethodsService { this.users = user } + getUserOfRoom(roomId){ + return this.WsChatService.getUserOfRoom(roomId); + } + } diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 3abc1ae4e..61cf2096f 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -119,6 +119,35 @@ export class WsChatService { }); } + getUserOfRoom(roomId) { + + const requestId = uuidv4() + + const message = { + "msg": "method", + "method": "getUsersOfRoom", + "id": requestId, + "params": [ + roomId, + false, + { + "limit": 100, + "skip": 0 + } ] + } + + this.ws.send({message, requestId}) + + return new Promise((resolve, reject) => { + this.ws.registerCallback({type:'Onmessage', funx:(message)=>{ + if(message.id == requestId) { // same request send + resolve(message) + return true + } + }}) + }); + } + logout() { this.isLogin = false this.ws.connected = false @@ -360,7 +389,7 @@ export class WsChatService { } }) } - + loadHistory(roomId, limit: number = 50) { @@ -593,7 +622,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { }, onopen:()=> { this.ws.connected = true - + console.log('================== welcome to socket server =====================') this.ws.wsMsgQueue() @@ -602,13 +631,13 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) { for (const [key, value] of Object.entries(this.wsCallbacks)) { if(value.type== 'reConnect') { const dontRepeat = value.funx() - + if(dontRepeat) { delete this.wsCallbacks[key] } - + } - + } }