1 |
55995
|
argiro.kok
|
import {Injectable} from '@angular/core';
|
2 |
|
|
import {HttpClient} from '@angular/common/http';
|
3 |
58570
|
konstantin
|
import {map, tap} from "rxjs/operators";
|
4 |
55964
|
argiro.kok
|
import {CustomOptions} from "../../services/servicesUtils/customOptions.class";
|
5 |
55995
|
argiro.kok
|
import {EnvProperties} from "../properties/env-properties";
|
6 |
58459
|
konstantin
|
import {COOKIE} from "../../login/utils/helper.class";
|
7 |
58570
|
konstantin
|
import {BehaviorSubject, Observable} from "rxjs";
|
8 |
51050
|
argiro.kok
|
|
9 |
|
|
@Injectable()
|
10 |
|
|
export class SubscribeService {
|
11 |
58570
|
konstantin
|
private isSubscribedSubject: BehaviorSubject<boolean> = new BehaviorSubject(false);
|
12 |
51050
|
argiro.kok
|
|
13 |
58594
|
konstantin
|
constructor(private http: HttpClient) {}
|
14 |
51050
|
argiro.kok
|
|
15 |
58570
|
konstantin
|
public initIsSubscribedToCommunity(properties: EnvProperties, pid: string) {
|
16 |
|
|
let url = properties.adminToolsAPIURL + "/community/" + pid + "/is-subscriber/";
|
17 |
|
|
this.http.get<boolean>(url, CustomOptions.getAuthOptionsWithBody()).subscribe((isSubscribed) => {
|
18 |
|
|
this.isSubscribedSubject.next(isSubscribed);
|
19 |
|
|
});
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
public get isSubscribed(): Observable<boolean> {
|
23 |
|
|
return this.isSubscribedSubject.asObservable();
|
24 |
|
|
}
|
25 |
|
|
|
26 |
57547
|
k.triantaf
|
getCommunitySubscribers(properties: EnvProperties, pid: string) {
|
27 |
|
|
let url = properties.adminToolsAPIURL + "/community/" + pid + "/subscribers";
|
28 |
|
|
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
|
29 |
|
|
}
|
30 |
51050
|
argiro.kok
|
|
31 |
58459
|
konstantin
|
getNumberOfCommunitySubscribers(properties: EnvProperties, pid: string) {
|
32 |
|
|
let url = properties.adminToolsAPIURL + "/community/" + pid + "/subscribers/count";
|
33 |
|
|
return this.http.get<any>((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url);
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
isSubscribedToCommunity(properties: EnvProperties, pid: string) {
|
37 |
|
|
let url = properties.adminToolsAPIURL + "/community/" + pid + "/is-subscriber/";
|
38 |
58461
|
konstantin
|
return this.http.get<boolean>(url, CustomOptions.getAuthOptionsWithBody())
|
39 |
57547
|
k.triantaf
|
.pipe(map(res => {
|
40 |
58459
|
konstantin
|
// if (res['status'] && res['status'] != 200) {
|
41 |
|
|
// return null;
|
42 |
|
|
// }
|
43 |
|
|
// if (res['subscribers'] && res['subscribers'] != null) {
|
44 |
|
|
//
|
45 |
|
|
// for (var i = 0; i < res['subscribers'].length; i++) {
|
46 |
|
|
// if (res['subscribers'][i] != null && res['subscribers'][i].email == email) {
|
47 |
|
|
// return true;
|
48 |
|
|
// }
|
49 |
|
|
// }
|
50 |
|
|
// }
|
51 |
|
|
// return false;
|
52 |
|
|
return res;
|
53 |
|
|
}));
|
54 |
|
|
}
|
55 |
51050
|
argiro.kok
|
|
56 |
58459
|
konstantin
|
subscribeToCommunity(properties: EnvProperties, pid: string) {
|
57 |
58570
|
konstantin
|
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscriber", {}, CustomOptions.getAuthOptionsWithBody())
|
58 |
|
|
.pipe(tap(isSubscribed => {
|
59 |
|
|
this.isSubscribedSubject.next(isSubscribed);}));
|
60 |
58459
|
konstantin
|
}
|
61 |
57547
|
k.triantaf
|
|
62 |
58459
|
konstantin
|
unSubscribeToCommunity(properties: EnvProperties, pid: string) {
|
63 |
58570
|
konstantin
|
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscriber/delete", {}, CustomOptions.getAuthOptionsWithBody())
|
64 |
|
|
.pipe(tap(unSubscribed => {
|
65 |
|
|
this.isSubscribedSubject.next(!unSubscribed);}));
|
66 |
57547
|
k.triantaf
|
}
|
67 |
|
|
|
68 |
58459
|
konstantin
|
subscribeToCommunityByEmail(properties: EnvProperties, pid: string, email: string) {
|
69 |
57547
|
k.triantaf
|
let subscriber = {"email": email};
|
70 |
58420
|
konstantin
|
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscribers", JSON.stringify(subscriber), CustomOptions.getAuthOptionsWithBody());
|
71 |
57547
|
k.triantaf
|
}
|
72 |
|
|
|
73 |
58459
|
konstantin
|
unSubscribeToCommunityByEmail(properties: EnvProperties, pid: string, email: string) {
|
74 |
58420
|
konstantin
|
return this.http.post<any>(properties.adminToolsAPIURL + "/community/" + pid + "/subscribers/delete", JSON.stringify([email]), CustomOptions.getAuthOptionsWithBody());
|
75 |
57547
|
k.triantaf
|
}
|
76 |
|
|
|
77 |
58461
|
konstantin
|
getCommunitiesSubscribedTo(properties: EnvProperties/*, email: string*/) {
|
78 |
|
|
let url = properties.adminToolsAPIURL + "/subscriber/communities";//?email=" + email;
|
79 |
|
|
return this.http.get<any>(url, CustomOptions.getAuthOptionsWithBody());
|
80 |
57547
|
k.triantaf
|
}
|
81 |
51050
|
argiro.kok
|
}
|