diff --git a/src/app/modals/chat-options-features/chat-options-features.page.ts b/src/app/modals/chat-options-features/chat-options-features.page.ts index f22b859c0..a4a5a91cb 100644 --- a/src/app/modals/chat-options-features/chat-options-features.page.ts +++ b/src/app/modals/chat-options-features/chat-options-features.page.ts @@ -10,6 +10,7 @@ import { FileLoaderService } from 'src/app/services/file/file-loader.service'; import { FileToBase64Service } from 'src/app/services/file/file-to-base64.service'; import { environment } from 'src/environments/environment'; import { ThemeService } from 'src/app/services/theme.service' +import { HttpErrorResponse } from '@angular/common/http'; @Component({ selector: 'app-chat-options-features', @@ -117,8 +118,12 @@ export class ChatOptionsFeaturesPage implements OnInit { this.chatService.sendMessage(body).subscribe(res=> { // - },(error) => { - + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.chatService.sendMessage(body); + } + }); // }; @@ -144,8 +149,12 @@ export class ChatOptionsFeaturesPage implements OnInit { this.chatService.sendMessage(body).subscribe(res=> { - },(error) => { - + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.chatService.sendMessage(body); + } + }); } diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 959fd66c4..f6916ddf7 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -1,4 +1,4 @@ -import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; +import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http'; import { Component, OnInit, @@ -507,6 +507,12 @@ export class ChatPage implements OnInit { // }*/ + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.getChatMembers(); + } + }); } diff --git a/src/app/pages/chat/edit-group/edit-group.page.ts b/src/app/pages/chat/edit-group/edit-group.page.ts index 434bfc007..0a8c3235d 100644 --- a/src/app/pages/chat/edit-group/edit-group.page.ts +++ b/src/app/pages/chat/edit-group/edit-group.page.ts @@ -1,3 +1,4 @@ +import { HttpErrorResponse } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { ModalController, NavParams, PickerController } from '@ionic/angular'; import { ChatService } from 'src/app/services/chat.service'; @@ -36,6 +37,11 @@ export class EditGroupPage implements OnInit { this.room = room['room']; this.groupName = this.room.name.split('-').join(' '); + },(error: HttpErrorResponse) => { + if(error.status === 401) { + this.chatService.refreshtoken(); + this.getRoomInfo() + } }); } diff --git a/src/app/pages/chat/group-messages/group-contacts/group-contacts.page.ts b/src/app/pages/chat/group-messages/group-contacts/group-contacts.page.ts index aa1c439ba..ca0ff798f 100644 --- a/src/app/pages/chat/group-messages/group-contacts/group-contacts.page.ts +++ b/src/app/pages/chat/group-messages/group-contacts/group-contacts.page.ts @@ -1,4 +1,4 @@ -import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { ModalController, NavParams } from '@ionic/angular'; import * as _ from 'lodash'; @@ -85,6 +85,12 @@ export class GroupContactsPage implements OnInit { this.showLoader = false; + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.loadUsers(); + } + }); } diff --git a/src/app/pages/chat/group-messages/group-messages.page.ts b/src/app/pages/chat/group-messages/group-messages.page.ts index bd869ddab..212b2f835 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -31,6 +31,7 @@ import { MessageService } from 'src/app/services/chat/message.service'; import { File } from '@awesome-cordova-plugins/file/ngx'; import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx'; import { SessionStore } from 'src/app/store/session.service'; +import { HttpErrorResponse } from '@angular/common/http'; @Component({ selector: 'app-group-messages', @@ -380,6 +381,12 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { this.allUsers = res['users'].filter(data => data.username != SessionStore.user.UserName); + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.getChatMembers(); + } + }); } diff --git a/src/app/pages/chat/messages/contacts/contacts.page.ts b/src/app/pages/chat/messages/contacts/contacts.page.ts index b369d5dd3..40dd5ac8b 100644 --- a/src/app/pages/chat/messages/contacts/contacts.page.ts +++ b/src/app/pages/chat/messages/contacts/contacts.page.ts @@ -1,4 +1,4 @@ -import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { ModalController } from '@ionic/angular'; import { AuthService } from 'src/app/services/auth.service'; @@ -67,6 +67,12 @@ export class ContactsPage implements OnInit { return 0; }); this.showLoader = false; + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.loadUsers(); + } + }); } diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 0f8c1a5df..2a26d3274 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -36,6 +36,7 @@ import { FileToBase64Service } from 'src/app/services/file/file-to-base64.servic import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; import { DomSanitizer } from '@angular/platform-browser'; import { SessionStore } from 'src/app/store/session.service'; +import { HttpErrorResponse } from '@angular/common/http'; const IMAGE_DIR = 'stored-images'; @@ -519,6 +520,12 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { this.members = res['members']; this.dmUsers = res['members'].filter(data => data.username != this.sessionStore.user.UserName) this.showLoader = false; + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.getChatMembers(); + } + }); } diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts index cc51df1e1..01e1801a5 100644 --- a/src/app/services/chat.service.ts +++ b/src/app/services/chat.service.ts @@ -350,4 +350,22 @@ export class ChatService { } + refreshtoken(){ + this.headers = this.headers.set('Authorization', SessionStore.user.BasicAuthKey); + let options = { + headers: this.headers + }; + return this.http.get(environment.apiURL+'UserAuthentication/RegenereChatToken',options).subscribe(async res => { + let data = { + status: res['status'], + data: { + userId: res['data'].userId, + authToken: res['data'].authToken } + } + SessionStore.user.ChatData = data + console.log(res) + console.log(SessionStore.user.ChatData) + }); + } + } diff --git a/src/app/shared/chat/edit-group/edit-group.page.ts b/src/app/shared/chat/edit-group/edit-group.page.ts index 6921d9ba9..ac40055f0 100644 --- a/src/app/shared/chat/edit-group/edit-group.page.ts +++ b/src/app/shared/chat/edit-group/edit-group.page.ts @@ -1,3 +1,4 @@ +import { HttpErrorResponse } from '@angular/common/http'; import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { ModalController, PickerController } from '@ionic/angular'; import { AuthService } from 'src/app/services/auth.service'; @@ -41,6 +42,12 @@ export class EditGroupPage implements OnInit { this.room = room['room']; this.groupName = this.room.name.split('-').join(' '); + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.getRoomInfo(); + } + }); } diff --git a/src/app/shared/chat/group-messages/group-contacts/group-contacts.page.ts b/src/app/shared/chat/group-messages/group-contacts/group-contacts.page.ts index c3afa32f0..9ff9610f7 100644 --- a/src/app/shared/chat/group-messages/group-contacts/group-contacts.page.ts +++ b/src/app/shared/chat/group-messages/group-contacts/group-contacts.page.ts @@ -1,4 +1,4 @@ -import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http'; import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { ModalController, NavParams } from '@ionic/angular'; import * as _ from 'lodash'; @@ -203,6 +203,12 @@ export class GroupContactsPage implements OnInit { this.showLoader = false; + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.loadUsers(); + } + }); } diff --git a/src/app/shared/chat/group-messages/group-messages.page.ts b/src/app/shared/chat/group-messages/group-messages.page.ts index 5403fe7e0..da3fa4db9 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -34,6 +34,7 @@ import { AlertController } from '@ionic/angular'; import { File } from '@awesome-cordova-plugins/file/ngx'; import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx'; import { SessionStore } from 'src/app/store/session.service'; +import { HttpErrorResponse } from '@angular/common/http'; /* @@ -366,6 +367,12 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe this.allUsers = res['users'].filter(data => data.username != SessionStore.user.UserName); // + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.getChatMembers(); + } + }); } diff --git a/src/app/shared/chat/messages/contacts/contacts.page.ts b/src/app/shared/chat/messages/contacts/contacts.page.ts index 7e775e3e3..a0680ce79 100644 --- a/src/app/shared/chat/messages/contacts/contacts.page.ts +++ b/src/app/shared/chat/messages/contacts/contacts.page.ts @@ -1,4 +1,4 @@ -import { HttpHeaders } from '@angular/common/http'; +import { HttpErrorResponse, HttpHeaders } from '@angular/common/http'; import { Component, EventEmitter, OnInit, Output } from '@angular/core'; import { ModalController } from '@ionic/angular'; import { AuthService } from 'src/app/services/auth.service'; @@ -83,6 +83,12 @@ export class ContactsPage implements OnInit { return 0; }); this.showLoader = false; + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.loadUsers(); + } + }); } diff --git a/src/app/shared/chat/messages/messages.page.ts b/src/app/shared/chat/messages/messages.page.ts index 623155e2e..10fa2fc1f 100644 --- a/src/app/shared/chat/messages/messages.page.ts +++ b/src/app/shared/chat/messages/messages.page.ts @@ -31,6 +31,7 @@ import { AlertController, Platform } from '@ionic/angular'; import { File } from '@awesome-cordova-plugins/file/ngx'; import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx'; import { SessionStore } from 'src/app/store/session.service'; +import { HttpErrorResponse } from '@angular/common/http'; const IMAGE_DIR = 'stored-images'; @@ -524,6 +525,12 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy this.members = res['members']; this.dmUsers = res['members'].filter(data => data.username != this.sessionStore.user.UserName) this.showLoader = false; + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.getChatMembers(); + } + }); } diff --git a/src/app/shared/popover/chat-popover/chat-popover.page.ts b/src/app/shared/popover/chat-popover/chat-popover.page.ts index 4670a1537..cd63e74b9 100644 --- a/src/app/shared/popover/chat-popover/chat-popover.page.ts +++ b/src/app/shared/popover/chat-popover/chat-popover.page.ts @@ -5,6 +5,7 @@ import { ToastService } from 'src/app/services/toast.service'; import { ThemeService } from 'src/app/services/theme.service' import { SetRoomOwnerPage } from 'src/app/modals/set-room-owner/set-room-owner.page'; import { WsChatMethodsService } from 'src/app/services/chat/ws-chat-methods.service'; +import { HttpErrorResponse } from '@angular/common/http'; @Component({ @@ -168,6 +169,12 @@ export class ChatPopoverPage implements OnInit { }); } + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.deleteGroup(); + } + }); this.popoverController.dismiss('delete'); this.modalController.dismiss('delete'); diff --git a/src/app/shared/popover/messages-options/messages-options.page.ts b/src/app/shared/popover/messages-options/messages-options.page.ts index ba6589fa9..744631dd4 100644 --- a/src/app/shared/popover/messages-options/messages-options.page.ts +++ b/src/app/shared/popover/messages-options/messages-options.page.ts @@ -1,3 +1,4 @@ +import { HttpErrorResponse } from '@angular/common/http'; import { Component, OnInit } from '@angular/core'; import { ModalController, NavParams, PopoverController } from '@ionic/angular'; import { ChatService } from 'src/app/services/chat.service'; @@ -41,6 +42,12 @@ export class MessagesOptionsPage implements OnInit { let body = { "roomId": this.roomId } this.chatService.removeChatRoom(body).subscribe(res=>{ + },(error: HttpErrorResponse) => { + if(error.status === 401){ + this.chatService.refreshtoken() + this.closeChatRoom(); + } + }); this.close(); }