Files
doneit-web/src/app/services/chat.service.ts
T

58 lines
2.2 KiB
TypeScript
Raw Normal View History

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;
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('Access-Control-Allow-Origin', 'http://localhost:8100');
this.headers = this.headers.set('Access-Control-Allow-Credentials', 'true');
this.headers = this.headers.set('Access-Control-Allow-Headers', 'Access-Control-Allow-Origin, Access-Control-Allow-Credentials, Access-Control-Allow-Headers, x-requested-with, Content-Type, X-Auth-Token, X-User-Id, origin, authorization, accept, client-security-token');
this.headers = this.headers.set('X-User-Id', user.userId);
this.headers = this.headers.set('X-Auth-Token', user.authToken);
});
/* 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 = {
headers: this.headers,
};
2020-11-03 11:52:21 +01:00
}
getAllUsers(){
2020-12-21 16:37:44 +01:00
console.log(this.headers);
2020-10-30 15:22:35 +01:00
return this.http.get(environment.apiChatUrl+'users.list', this.options);
}
2020-11-03 11:52:21 +01:00
getAllConnectedUsers(){
return this.http.get(environment.apiChatUrl+'users.presence', this.options);
}
getAllPrivateGroups(){
return this.http.get(environment.apiChatUrl+'groups.list', this.options);
2020-10-30 15:22:35 +01:00
}
}