From acacb58d0d27b87dac8d16e5e3f2d5739abf3d45 Mon Sep 17 00:00:00 2001 From: Peter Maquiran Date: Sat, 29 Jan 2022 20:16:39 +0100 Subject: [PATCH] fix rocket chat session --- src/app/services/auth.service.ts | 9 ++++++--- src/app/services/chat.service.ts | 9 ++++++--- src/app/services/chat/room.service.ts | 5 +++++ src/app/services/chat/ws-chat-methods.service.ts | 15 ++++++++++++++- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 4e87e26ed..219eb2900 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 { ChatService } from './chat.service'; @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 ChatService: ChatService) { this.headers = new HttpHeaders(); @@ -116,8 +118,9 @@ export class AuthService { if(responseChat) { + + setTimeout(()=>{ - console.log('login', SessionStore.user.RochetChatUser, SessionStore.user.Password) this.WsChatService.connect(); this.WsChatService.login().then((message) => { @@ -133,8 +136,8 @@ export class AuthService { this.ValidatedUserChat = responseChat; localStorage.setItem('userChat', JSON.stringify(responseChat)); - this.storageService.store(AuthConnstants.AUTH, responseChat); + this.ChatService.setHeader() return true; } diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts index 78a481246..9d786fe02 100644 --- a/src/app/services/chat.service.ts +++ b/src/app/services/chat.service.ts @@ -27,19 +27,22 @@ export class ChatService { constructor( private http:HttpClient, private httpService: HttpService, - private authService: AuthService, + public authService: AuthService, private storage: Storage, private storageService:StorageService, ) { - this.loggedUserChat = authService.ValidatedUserChat; + this.setHeader() + } + + setHeader() { + this.loggedUserChat = this.authService.ValidatedUserChat; this.headers = new HttpHeaders(); this.headers = this.headers.set('X-User-Id', this.loggedUserChat['data'].userId); this.headers = this.headers.set('X-Auth-Token', this.loggedUserChat['data'].authToken); this.options = { headers: this.headers, }; - } getDocumentDetails(url:string){ diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 4e85074ae..a785e5b12 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -42,6 +42,11 @@ export class RoomService { mgsArray = []; scrollDown = () => { } + + /** + * @description get user list from ws-chat-methods.service + * @returns chatUser[] + */ getAllUsers = (): chatUser[] => { return [] } diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 6914bde47..fa9b44579 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -136,7 +136,11 @@ export class WsChatMethodsService { })) } - + /** + * @description when a new room is create, needs to subtribe in order to receive updates + * @param id + * @param roomData + */ subscribeToRoomUpdate(id, roomData) { this.defaultSubtribe(id) @@ -164,6 +168,10 @@ export class WsChatMethodsService { } + /** + * @description create a representation of an room in these instance this.dm, this.group ... + * @param roomData + */ prepareRoom(roomData) { let room:RoomService; @@ -232,6 +240,11 @@ export class WsChatMethodsService { return this.users.find((user)=> user.username == username) } + /** + * @description convert rocketchat statues num to readable string + * @param text + * @returns + */ statusNumberToText(text) { if(text == '0') { return "offline"