add show total users in rocket chat server

This commit is contained in:
Tiago Kayaya
2020-10-30 15:22:35 +01:00
parent 4a7df21759
commit 21eb3d3cf1
63 changed files with 970 additions and 139 deletions
+39 -7
View File
@@ -1,19 +1,23 @@
import { Injectable } from '@angular/core';
import { StorageService } from './storage.service';
import { Router } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { User } from '../models/user.model';
import { environment } from 'src/environments/environment';
import { HttpService } from './http.service';
import { BehaviorSubject, Observable } from 'rxjs';
import { AuthConnstants } from '../config/auth-constants';
@Injectable({
providedIn: 'root'
})
export class AuthService {
userData$ = new BehaviorSubject<any>('');
constructor(
private http: HttpClient
private http: HttpClient,
private httpService: HttpService,
private storageService:StorageService,
private router:Router
) { }
public ValidatedUser:User;
@@ -31,12 +35,40 @@ export class AuthService {
if (result)
{
this.ValidatedUser = user;
}
}
return result;
}
logout(){
this.ValidatedUser = null;
}
loginChat(){
const body = {"user": "admin","password": "tabteste@006"};
const url = "http://192.168.100.111:3000/api/v1/login";
return this.http.post(url, body);
}
//Login to rocketChat server
loginChat2(postData: any):Observable<any> {
return this.httpService.post('login', postData);
}
//Get user data from RocketChat
getUserData(){
this.storageService.get(AuthConnstants.AUTH).then(res=>{
this.userData$.next(res);
})
}
logoutChat(){
//this.storageService.clear();
this.storageService.removeStorageItem(AuthConnstants.AUTH).then(res =>{
this.userData$.next('');
this.router.navigate(['']);
})
}
}
+16
View File
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ChatService } from './chat.service';
describe('ChatService', () => {
let service: ChatService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ChatService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
+41
View File
@@ -0,0 +1,41 @@
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';
@Injectable({
providedIn: 'root'
})
export class ChatService {
headers: HttpHeaders;
options:any;
constructor(
private http:HttpClient,
private httpService: HttpService,
private authService: AuthService,
private storageService:StorageService,) {
this.headers = new HttpHeaders();
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);
});
}
getAllUsers(){
this.options = {
headers: this.headers,
};
console.log(this.headers);
return this.http.get(environment.apiChatUrl+'users.list', this.options);
}
getPrivateGroups(){
this.http.get(environment.apiChatUrl+'groups.list', this.options);
}
}
+16
View File
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { FcmService } from './fcm.service';
describe('FcmService', () => {
let service: FcmService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(FcmService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
+64
View File
@@ -0,0 +1,64 @@
import { Injectable } from '@angular/core';
import {
Plugins,
PushNotification,
PushNotificationToken,
PushNotificationActionPerformed,
Capacitor
} from '@capacitor/core';
import { Router } from '@angular/router';
const { PushNotifications } = Plugins;
@Injectable({
providedIn: 'root'
})
export class FcmService {
constructor(private router: Router) { }
initPush() {
if (Capacitor.platform !== 'web') {
this.registerPush();
}
}
private registerPush() {
PushNotifications.requestPermission().then((permission) => {
if (permission.granted) {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// No permission for push granted
}
});
PushNotifications.addListener(
'registration',
(token: PushNotificationToken) => {
console.log('My token: ' + JSON.stringify(token));
}
);
PushNotifications.addListener('registrationError', (error: any) => {
console.log('Error: ' + JSON.stringify(error));
});
PushNotifications.addListener(
'pushNotificationReceived',
async (notification: PushNotification) => {
console.log('Push received: ' + JSON.stringify(notification));
}
);
PushNotifications.addListener(
'pushNotificationActionPerformed',
async (notification: PushNotificationActionPerformed) => {
const data = notification.notification.data;
console.log('Action performed: ' + JSON.stringify(notification.notification));
if (data.detailsId) {
this.router.navigateByUrl(`/home/notifications/notification-detail${data.detaisId}`);
}
}
);
}
}
+16
View File
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { HttpService } from './http.service';
describe('HttpService', () => {
let service: HttpService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(HttpService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
+26
View File
@@ -0,0 +1,26 @@
import { HttpClient, HttpHeaderResponse, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class HttpService {
constructor(private http:HttpClient) { }
post(serviceName:string, data:any){
const headers = new HttpHeaders();
const options = {header: headers, withCredentials: false};
const url = environment.apiChatUrl+serviceName;
const body = {"user": "admin","password": "tabteste@006"};
return this.http.post(url, /* JSON.stringify( */data/* ), options */)
}
get(serviceName:string, options:any){
const url = environment.apiChatUrl+serviceName;
return this.http.get(url, options);
}
}