This commit is contained in:
tiago.kayaya
2021-01-07 09:39:36 +01:00
parent 3f449abc3e
commit 6596941cdd
3 changed files with 33 additions and 16 deletions
+24 -9
View File
@@ -14,6 +14,8 @@ import { Storage } from '@ionic/storage';
export class ChatService {
headers: HttpHeaders;
options:any;
X_User_Id:any;
X_Auth_Token:any;
constructor(
@@ -27,12 +29,20 @@ export class ChatService {
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);
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)=>{
@@ -40,18 +50,23 @@ export class ChatService {
this.headers = this.headers.set('X-Auth-Token', res.authToken);
}); */
this.options = {
headers: this.headers,
headers: {
'X-User-Id': this.X_User_Id,
'X-Auth-Token': this.X_Auth_Token
},
};
}
getAllUsers(){
console.log(this.headers);
return this.http.get(environment.apiChatUrl+'users.list', this.options);
/* return this.http.get(environment.apiChatUrl+'users.list', this.options); */
}
getAllConnectedUsers(){
return this.http.get(environment.apiChatUrl+'users.presence', this.options);
getAllConnectedUsers(opts){
console.log(opts);
return this.http.get(environment.apiChatUrl+'users.presence', opts);
}
getAllPrivateGroups(){
return this.http.get(environment.apiChatUrl+'groups.list', this.options);
/* return this.http.get(environment.apiChatUrl+'groups.list', this.options); */
}
}