diff --git a/package.json b/package.json index d9347c770..4686c8149 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,8 @@ "cordova-plugin-inappbrowser": {}, "cordova-plugin-camera": { "ANDROID_SUPPORT_V4_VERSION": "27.+" - } + }, + "cordova-sqlite-storage": {} }, "platforms": [ "ios", diff --git a/src/app/home/home.page.html b/src/app/home/home.page.html index dc266711b..1fa8391bd 100644 --- a/src/app/home/home.page.html +++ b/src/app/home/home.page.html @@ -26,10 +26,10 @@ Pesquisa --> - + diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 2b3ecc684..498037a09 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -52,7 +52,7 @@ export class ChatPage implements OnInit { }); } - async starConversation(selectedUser) { + async startConversation(selectedUser) { const modal = await this.modalController.create({ component: ConversationPage, cssClass: 'conversation', diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index a2cd3d0af..6253e3263 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -57,6 +57,7 @@ export class LoginPage implements OnInit { loginRocketChat(){ this.authService.loginChat(this.postData).subscribe((res: any) =>{ + this.storageService.store(res); console.log('Login to Rocket chat OK'); },(error:any) =>{ console.log('Network error'); diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index 03ada687f..9182db2aa 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -50,11 +50,11 @@ export class AuthService { } //Get user data from RocketChat - /* getUserData(){ + getUserData(){ this.storageService.get(AuthConnstants.AUTH).then(res=>{ this.userData$.next(res); }) - } */ + } /* getProfile(){ this.storageService.get(AuthConnstants.PROFILE).then(res=>{ diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts index fcec14651..a26d1f61d 100644 --- a/src/app/services/chat.service.ts +++ b/src/app/services/chat.service.ts @@ -21,6 +21,7 @@ export class ChatService { private authService: AuthService, private storageService:StorageService,) { this.headers = new HttpHeaders(); + this.storageService.get() this.authService.userData$.subscribe((res:any)=>{ this.headers = this.headers.set('X-User-Id', res.userId); this.headers = this.headers.set('X-Auth-Token', res.authToken); diff --git a/src/app/services/storage.service.ts b/src/app/services/storage.service.ts index e65b0037a..5997af8a6 100644 --- a/src/app/services/storage.service.ts +++ b/src/app/services/storage.service.ts @@ -1,33 +1,31 @@ import { Injectable } from '@angular/core'; -/* import { Plugins } from '@capacitor/core'; -const { Storage } = Plugins; */ +import { Storage } from '@ionic/storage'; @Injectable({ providedIn: 'root' }) export class StorageService { - constructor() {} + constructor(private storage: Storage) {} - /* // Store the value - async store(storageKey: string, value: any) { + // Store the value + async store(value: any) { const encryptedValue = btoa(escape(JSON.stringify(value))); - await Storage.set({ - key: storageKey, - value: encryptedValue - }); + await this.storage.set('user', encryptedValue);; } // Get the value - async get(storageKey: string) { - const ret = await Storage.get({ key: storageKey }); - return JSON.parse(unescape(atob(ret.value))); + async get(user: any) { + const ret = await this.storage.get('user').then(res=>{ + return JSON.parse(unescape(atob(ret.value))); + }); + } - async removeStorageItem(storageKey: string) { - await Storage.remove({ key: storageKey }); - } + /* async removeStorageItem(storageKey: string) { + await this.storage.remove({ key: storageKey }); + } */ // Clear storage async clear() { - await Storage.clear(); - } */ + await this.storage.clear(); + } }