2020-10-30 15:22:35 +01:00
|
|
|
import { HttpHeaders } from '@angular/common/http';
|
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { Observable } from "rxjs"
|
|
|
|
|
import { AuthService } from './auth.service';
|
|
|
|
|
import { HttpService } from './http.service';
|
|
|
|
|
import { StorageService } from './storage.service';
|
|
|
|
|
import { HttpClient, HttpHeaderResponse } from '@angular/common/http';
|
|
|
|
|
import { environment } from 'src/environments/environment';
|
2020-12-21 16:37:44 +01:00
|
|
|
import { Storage } from '@ionic/storage';
|
2020-10-30 15:22:35 +01:00
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
|
providedIn: 'root'
|
|
|
|
|
})
|
|
|
|
|
export class ChatService {
|
|
|
|
|
headers: HttpHeaders;
|
|
|
|
|
options:any;
|
2021-01-07 09:39:36 +01:00
|
|
|
X_User_Id:any;
|
|
|
|
|
X_Auth_Token:any;
|
2020-10-30 15:22:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private http:HttpClient,
|
|
|
|
|
private httpService: HttpService,
|
|
|
|
|
private authService: AuthService,
|
2020-12-21 16:37:44 +01:00
|
|
|
private storage: Storage,
|
2020-10-30 15:22:35 +01:00
|
|
|
private storageService:StorageService,) {
|
|
|
|
|
this.headers = new HttpHeaders();
|
2020-12-21 16:37:44 +01:00
|
|
|
|
|
|
|
|
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);
|
2021-01-07 09:39:36 +01:00
|
|
|
console.log(user.userId);
|
|
|
|
|
this.X_User_Id = user.userId;
|
2020-12-21 16:37:44 +01:00
|
|
|
this.headers = this.headers.set('X-Auth-Token', user.authToken);
|
2021-01-07 09:39:36 +01:00
|
|
|
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);
|
|
|
|
|
|
2020-12-21 16:37:44 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/* this.authService.userData$.subscribe((res:any)=>{
|
2020-10-30 15:22:35 +01:00
|
|
|
this.headers = this.headers.set('X-User-Id', res.userId);
|
|
|
|
|
this.headers = this.headers.set('X-Auth-Token', res.authToken);
|
2020-12-21 16:37:44 +01:00
|
|
|
}); */
|
2020-10-30 15:22:35 +01:00
|
|
|
this.options = {
|
2021-01-07 09:39:36 +01:00
|
|
|
headers: {
|
|
|
|
|
'X-User-Id': this.X_User_Id,
|
|
|
|
|
'X-Auth-Token': this.X_Auth_Token
|
|
|
|
|
},
|
2020-10-30 15:22:35 +01:00
|
|
|
};
|
2020-11-03 11:52:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getAllUsers(){
|
2020-12-21 16:37:44 +01:00
|
|
|
console.log(this.headers);
|
2021-01-07 09:39:36 +01:00
|
|
|
/* return this.http.get(environment.apiChatUrl+'users.list', this.options); */
|
2020-10-30 15:22:35 +01:00
|
|
|
}
|
2021-01-07 09:39:36 +01:00
|
|
|
getAllConnectedUsers(opts){
|
|
|
|
|
console.log(opts);
|
|
|
|
|
|
|
|
|
|
return this.http.get(environment.apiChatUrl+'users.presence', opts);
|
2020-11-03 11:52:21 +01:00
|
|
|
}
|
|
|
|
|
getAllPrivateGroups(){
|
2021-01-07 09:39:36 +01:00
|
|
|
/* return this.http.get(environment.apiChatUrl+'groups.list', this.options); */
|
2020-10-30 15:22:35 +01:00
|
|
|
}
|
|
|
|
|
}
|