diff --git a/src/app/pages/chat/chat.page.html b/src/app/pages/chat/chat.page.html index 27c49e4f1..c08544c4c 100644 --- a/src/app/pages/chat/chat.page.html +++ b/src/app/pages/chat/chat.page.html @@ -37,6 +37,7 @@ +
diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 636c72896..9aa2f37b2 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -125,6 +125,8 @@ export class ChatPage implements OnInit { this.showLoader = true; + this.segment = 'Contactos' + } ngOnInit() { diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index 74519ab76..d79528541 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -13,7 +13,10 @@ import { ThemeService } from 'src/app/services/theme.service'; import { StorageService } from 'src/app/services/storage.service'; import { PermissionService } from 'src/app/services/permission.service'; import { PermissionList } from 'src/app/models/permission/permissionList'; -import { MessageModel, DeleteMessageModel } from '../../models/beast-orm' +import { MessageModel, DeleteMessageModel } from '../../models/beast-orm'; +import { WsChatService } from 'src/app/services/chat/ws-chat.service'; +import { Storage } from '@ionic/storage'; +import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'; @Component({ selector: 'app-login', templateUrl: './login.page.html', @@ -46,6 +49,9 @@ export class LoginPage implements OnInit { public ThemeService: ThemeService, private storageservice: StorageService, public p: PermissionService, + private WsChatService: WsChatService, + private storage: Storage, + public WsChatMethodsService: WsChatMethodsService, ) {} ngOnInit() { @@ -134,7 +140,9 @@ export class LoginPage implements OnInit { } else { + this.WsChatService.logout(); this.clearStoreService.clear(); + this.WsChatMethodsService.clearChat(); SessionStore.delete(); window.localStorage.clear(); await MessageModel.deleteAll() diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index c55f09766..908324f5c 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -20,7 +20,7 @@ import { RoomService } from './chat/room.service'; import { Storage } from '@ionic/storage'; import { InitialsService } from './functions/initials.service'; import { PermissionService } from './permission.service'; - +import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'; @Injectable({ providedIn: 'root' }) @@ -48,7 +48,8 @@ export class AuthService { private AttachmentsService: AttachmentsService, private storage: Storage, private initialsService: InitialsService, - public p: PermissionService, ) { + public p: PermissionService, + public WsChatMethodsService: WsChatMethodsService, ) { this.headers = new HttpHeaders(); @@ -201,6 +202,11 @@ export class AuthService { this.WsChatService.setStatus('online') + + setTimeout(() => { + this.WsChatMethodsService.getAllRooms(); + }, 200); + // alert('wsLogin') }).catch((message) => { diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts index e21c11ab5..6d402df58 100644 --- a/src/app/services/chat.service.ts +++ b/src/app/services/chat.service.ts @@ -1,14 +1,13 @@ import { HttpHeaders, HttpParams } from '@angular/common/http'; import { Injectable } from '@angular/core'; -import { AuthService } from './auth.service'; import { HttpService } from './http.service'; import { StorageService } from './storage.service'; -import { HttpClient, HttpHeaderResponse } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import { environment } from 'src/environments/environment'; import { Storage } from '@ionic/storage'; import { PermissionService } from './permission.service'; import { SessionStore } from '../store/session.service'; - +import { ChangeProfileService } from 'src/app/services/change-profile.service'; @Injectable({ providedIn: 'root' }) @@ -24,19 +23,21 @@ export class ChatService { constructor( private http: HttpClient, private httpService: HttpService, - private authService: AuthService, private storage: Storage, private storageService: StorageService, - public p: PermissionService) { + public p: PermissionService, + private changeProfileService: ChangeProfileService,) { - this.setheader() + this.changeProfileService.registerCallback(() => { + this.setheader(); + }) } getDocumentDetails(url: string) { let headersc = new HttpHeaders(); - headersc = headersc.set('X-User-Id', this.loggedUserChat['data'].userId); - headersc = headersc.set('X-Auth-Token', this.loggedUserChat['data'].authToken); + headersc = headersc.set('X-User-Id', SessionStore.user.ChatData.data.userId); + headersc = headersc.set('X-Auth-Token', SessionStore.user.ChatData.data.authToken); headersc = headersc.set('Sec-Fetch-Dest', 'attachment'); headersc = headersc.set('Sec-Fetch-Mode', 'navigate'); headersc = headersc.set('Cookie', 'rc_uid=fsMwcNdufWvdnChj7'); @@ -342,7 +343,6 @@ export class ChatService { setheader() { try { if (this.p.userPermission(this.p.permissionList.Chat.access)) { - this.loggedUserChat = this.authService.ValidatedUserChat; this.headers = new HttpHeaders(); if (this.p.userPermission(this.p.permissionList.Chat.access)) { diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 90fd2413f..2104ed689 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -469,7 +469,7 @@ export class RoomService { deleteAll() { - this.messages.forEach((message)=>{ + this.messages.forEach((message) => { if(message?._id) { this.sendDeleteRequest(message._id) } @@ -478,7 +478,7 @@ export class RoomService { async delateMessageToSendToOthers(userId) { - const deleteMessage = await DeleteMessageModel.all() + const deleteMessage = await DeleteMessageModel.all(); const toSend = deleteMessage.filter((DeleteMessage:string[])=> ! DeleteMessage.includes(userId)) diff --git a/src/app/services/chat/ws-chat-methods.service.ts b/src/app/services/chat/ws-chat-methods.service.ts index 87976f395..d12c22731 100644 --- a/src/app/services/chat/ws-chat-methods.service.ts +++ b/src/app/services/chat/ws-chat-methods.service.ts @@ -14,7 +14,6 @@ import { SortService } from '../functions/sort.service'; import { chatUser } from 'src/app/models/chatMethod'; import { NfService } from 'src/app/services/chat/nf.service' import { ChangeProfileService } from '../change-profile.service'; -import { AuthService } from '../auth.service'; import { ChatStorageService } from './chat-storage.service'; import { ChatMethodsService } from './chat-methods.service'; import { AESEncrypt } from '../aesencrypt.service' @@ -41,7 +40,7 @@ export class WsChatMethodsService { users: chatUser[] = [] sessionStore = SessionStore - loggedUser: any; + delete = [] @@ -56,7 +55,6 @@ export class WsChatMethodsService { private NfService: NfService, private changeProfileService: ChangeProfileService, private chatService: ChatService, - private authService: AuthService, private ChatStorageService: ChatStorageService, private ChatMethodsService:ChatMethodsService, private AESEncrypt: AESEncrypt, @@ -64,7 +62,7 @@ export class WsChatMethodsService { private NetworkServiceService: NetworkServiceService, ) { - this.loggedUser = authService.ValidatedUserChat['data']; + this.loadChat() @@ -93,13 +91,6 @@ export class WsChatMethodsService { }) - // on change profile remove a rooms - this.changeProfileService.registerCallback(() => { - this.clearChat() - this.ReLoadChat() - this.storage.remove('Rooms'); - }) - } private loadChat() { @@ -173,8 +164,10 @@ export class WsChatMethodsService { async getAllRooms () { this.loadingWholeList = true const rooms = await this.WsChatService.getRooms(); + try { + await this.storage.remove('Rooms'); + } catch(e) {} - await this.storage.remove('Rooms'); await rooms.result.update.forEach( async (roomData: room, index) => { const roomId = this.getRoomId(roomData); diff --git a/src/app/services/chat/ws-chat.service.ts b/src/app/services/chat/ws-chat.service.ts index 173a9f167..2bc758e80 100644 --- a/src/app/services/chat/ws-chat.service.ts +++ b/src/app/services/chat/ws-chat.service.ts @@ -78,7 +78,6 @@ export class WsChatService { // if(message.result) { if(message.result.token) { - this.isLogin = true this.loginResponse = message @@ -106,6 +105,7 @@ export class WsChatService { getRooms(roomOlder = 1480377601) { + //const requestId = uuidv4() const requestId = uuidv4() const message = { @@ -121,7 +121,6 @@ export class WsChatService { this.ws.registerCallback({type:'Onmessage', funx:(message)=>{ if(message.id == requestId) { // same request send resolve(message) - // return true } }}) @@ -186,6 +185,7 @@ export class WsChatService { logout() { this.isLogin = false this.ws.connected = false + this.ws.disconnect() } // send message to room @@ -749,6 +749,7 @@ export class WsChatService { const data = JSON.parse(event.data) // + // console.log(data) for (const [key, value] of Object.entries(this.wsCallbacks)) { if(value.type== 'Onmessage') { @@ -777,6 +778,15 @@ export class WsChatService { onerror: (event: any) => { + }, + disconnect:() => { + if(this.socket) { + this.socket.onopen = (event: any) => {} + this.socket.onmessage = (event: any) => {} + this.socket.onclose = (event: any) => {} + this.socket.onerror = (event: any) => {} + this.socket.close() + } } }} diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 66482dde6..58b1211e1 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -49,6 +49,7 @@
{{msg.u.name}} {{msg.duration}} + {{msg._id}}
diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 2a91751fb..f5fd8e696 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -49,8 +49,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy @ViewChild('scrollMe') private myScrollContainer: ElementRef; @ViewChild('message-item') messageContainer: ElementRef; - loggedUser: any; - messages: any; dm: any; userPresence = ''; @@ -126,7 +124,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy private platform: Platform, private fileOpener: FileOpener, ) { - this.loggedUser = authService.ValidatedUserChat['data']; this.checkAudioPermission() }