mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
improvements
This commit is contained in:
@@ -47,37 +47,28 @@ export class AuthService {
|
||||
|
||||
//Login to rocketChat server
|
||||
loginChat(postData: any):Observable<any> {
|
||||
const res = this.httpService.post('login', postData);
|
||||
const res2 = res.subscribe(res=>{
|
||||
this.storageService.store(res);
|
||||
});
|
||||
return res;
|
||||
return this.httpService.post('login', postData);
|
||||
}
|
||||
|
||||
//Get user data from RocketChat
|
||||
//Get user data from RocketChat | global object
|
||||
getUserData(){
|
||||
const res = this.storageService.get('user');
|
||||
console.log(res);
|
||||
|
||||
|
||||
/* this.storageService.get(AuthConnstants.AUTH).then(res=>{
|
||||
this.storageService.get(AuthConnstants.AUTH).then(res=>{
|
||||
this.userData$.next(res);
|
||||
}) */
|
||||
});
|
||||
}
|
||||
|
||||
/* getProfile(){
|
||||
getProfile(){
|
||||
this.storageService.get(AuthConnstants.PROFILE).then(res=>{
|
||||
return res;
|
||||
});
|
||||
} */
|
||||
}
|
||||
|
||||
logoutChat(){
|
||||
//this.storageService.clear();
|
||||
/* this.storageService.removeStorageItem(AuthConnstants.AUTH).then(res =>{
|
||||
this.storageService.removeStorageItem(AuthConnstants.AUTH).then(res =>{
|
||||
this.userData$.next('');
|
||||
this.router.navigate(['']);
|
||||
}) */
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { HttpHeaders } from '@angular/common/http';
|
||||
import { HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from "rxjs"
|
||||
import { AuthService } from './auth.service';
|
||||
@@ -14,6 +14,7 @@ import { Storage } from '@ionic/storage';
|
||||
export class ChatService {
|
||||
headers: HttpHeaders;
|
||||
options:any;
|
||||
options1:any;
|
||||
X_User_Id:any;
|
||||
X_Auth_Token:any;
|
||||
|
||||
@@ -25,48 +26,113 @@ export class ChatService {
|
||||
private storage: Storage,
|
||||
private storageService:StorageService,) {
|
||||
this.headers = new HttpHeaders();
|
||||
|
||||
this.storage.get('user').then((val) => {
|
||||
console.log(JSON.parse(unescape(atob(val))).data.userId);
|
||||
let user = JSON.parse(unescape(atob(val))).data;
|
||||
this.headers = this.headers.set('X-User-Id', user.userId);
|
||||
console.log(user.userId);
|
||||
this.X_User_Id = user.userId;
|
||||
this.headers = this.headers.set('X-Auth-Token', user.authToken);
|
||||
console.log(user.authToken);
|
||||
this.X_Auth_Token = user.authToken;
|
||||
this.options = {
|
||||
headers: {
|
||||
'X-User-Id': this.X_User_Id,
|
||||
'X-Auth-Token': this.X_Auth_Token
|
||||
},
|
||||
};
|
||||
this.getAllConnectedUsers(this.options);
|
||||
|
||||
});
|
||||
|
||||
/* this.authService.userData$.subscribe((res:any)=>{
|
||||
/* this.headers = this.headers.set('X-User-Id', 'GqjNWiLrGEHRna7Zn');
|
||||
this.headers = this.headers.set('X-Auth-Token', 'dAM0ZOTAy8jzQA_vS25z2IrnSc6sYLfi5rmaa35YNUz'); */
|
||||
-
|
||||
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);
|
||||
}); */
|
||||
});
|
||||
this.options = {
|
||||
headers: {
|
||||
'X-User-Id': this.X_User_Id,
|
||||
'X-Auth-Token': this.X_Auth_Token
|
||||
},
|
||||
headers: this.headers,
|
||||
};
|
||||
}
|
||||
|
||||
getAllUsers(){
|
||||
console.log(this.headers);
|
||||
/* return this.http.get(environment.apiChatUrl+'users.list', this.options); */
|
||||
/* getUser(){
|
||||
this.storage.get('user').then((val) => {
|
||||
let user = JSON.parse(unescape(atob(val))).data;
|
||||
|
||||
this.headers = this.headers.set('X-User-Id', user.userId);
|
||||
this.headers = this.headers.set('X-Auth-Token', user.authToken);
|
||||
|
||||
this.options1 = {
|
||||
headers: this.headers,
|
||||
};
|
||||
console.log(this.options1);
|
||||
|
||||
this.http.get(environment.apiChatUrl+'users.presence', this.options1).subscribe(res => {
|
||||
console.log(res);
|
||||
});
|
||||
|
||||
});
|
||||
} */
|
||||
getAllDirectMessages(){
|
||||
return this.http.get(environment.apiChatUrl+'im.list', this.options);
|
||||
}
|
||||
getAllConnectedUsers(opts){
|
||||
console.log(opts);
|
||||
|
||||
return this.http.get(environment.apiChatUrl+'users.presence', opts);
|
||||
getAllChannels(){
|
||||
return this.http.get(environment.apiChatUrl+'channels.list', this.options);
|
||||
}
|
||||
getAllUserChannels(){
|
||||
return this.http.get(environment.apiChatUrl+'channels.list.joined', this.options);
|
||||
}
|
||||
|
||||
getAllRooms(){
|
||||
return this.http.get(environment.apiChatUrl+'rooms.get', this.options);
|
||||
}
|
||||
getAllPrivateGroups(){
|
||||
/* return this.http.get(environment.apiChatUrl+'groups.list', this.options); */
|
||||
return this.http.get(environment.apiChatUrl+'groups.list', this.options);
|
||||
}
|
||||
|
||||
getAllUsers(){
|
||||
return this.http.get(environment.apiChatUrl+'users.list', this.options);
|
||||
}
|
||||
getAllConnectedUsers(){
|
||||
return this.http.get(environment.apiChatUrl+'users.presence', this.options);
|
||||
}
|
||||
//Check whether user is online or offline
|
||||
getUserPresence(id:any){
|
||||
|
||||
let params = new HttpParams();
|
||||
params = params.set("userId", id);
|
||||
|
||||
let opts = {
|
||||
headers: this.headers,
|
||||
params: params
|
||||
}
|
||||
return this.http.get(environment.apiChatUrl+'users.getPresence', opts);
|
||||
}
|
||||
|
||||
//Load messages from roomId
|
||||
loadJoinedRooms(){
|
||||
return this.http.get(environment.apiChatUrl+'im.list', this.options);
|
||||
}
|
||||
|
||||
//Load messages from roomId
|
||||
getRoomMessages(roomId:any){
|
||||
|
||||
let params = new HttpParams();
|
||||
params = params.set("roomId", roomId);
|
||||
|
||||
let opts = {
|
||||
headers: this.headers,
|
||||
params: params
|
||||
}
|
||||
return this.http.get(environment.apiChatUrl+'im.history', opts);
|
||||
}
|
||||
|
||||
sendMessage(body:any){
|
||||
let opts = {
|
||||
headers: this.headers,
|
||||
}
|
||||
return this.http.post(environment.apiChatUrl+'chat.sendMessage', body, opts);
|
||||
}
|
||||
//Load members from a chat
|
||||
getMembers(roomId:any){
|
||||
|
||||
let params = new HttpParams();
|
||||
params = params.set("roomId", roomId);
|
||||
|
||||
let opts = {
|
||||
headers: this.headers,
|
||||
params: params
|
||||
}
|
||||
return this.http.get(environment.apiChatUrl+'im.members', opts);
|
||||
}
|
||||
removeChatRoom(body:any){
|
||||
let opts = {
|
||||
headers: this.headers,
|
||||
}
|
||||
return this.http.post(environment.apiChatUrl+'im.close', body, opts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,37 +1,33 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Storage } from '@ionic/storage';
|
||||
import { AuthConnstants } from '../config/auth-constants';
|
||||
import { Plugins } from '@capacitor/core';
|
||||
const { Storage } = Plugins;
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class StorageService {
|
||||
user: any = "Max";
|
||||
storageKey = "user";
|
||||
constructor(private storage: Storage) {}
|
||||
constructor() {}
|
||||
|
||||
// set a key/value2
|
||||
store(user:any){
|
||||
const encryptedValue = btoa(escape(JSON.stringify(user)));
|
||||
this.storage.set(AuthConnstants.AUTH, encryptedValue);
|
||||
// Store the value
|
||||
async store(storageKey: string, value: any) {
|
||||
const encryptedValue = btoa(escape(JSON.stringify(value)));
|
||||
await Storage.set({
|
||||
key: storageKey,
|
||||
value: encryptedValue
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Or to get a key/value pair
|
||||
get(key:any){
|
||||
let user = this.storage.get(key).then((val) => {
|
||||
console.log(JSON.parse(unescape(atob(val))).data);
|
||||
return JSON.parse(unescape(atob(val))).data;
|
||||
});
|
||||
return user;
|
||||
// Get the value
|
||||
async get(storageKey: string) {
|
||||
const ret = await Storage.get({ key: storageKey });
|
||||
return JSON.parse(unescape(atob(ret.value)));
|
||||
}
|
||||
|
||||
|
||||
/* async removeStorageItem(storageKey: string) {
|
||||
await this.storage.remove({ key: storageKey });
|
||||
} */
|
||||
async removeStorageItem(storageKey: string) {
|
||||
await Storage.remove({ key: storageKey });
|
||||
}
|
||||
|
||||
// Clear storage
|
||||
async clear() {
|
||||
await this.storage.clear();
|
||||
await Storage.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user