next-ucap-messenger/projects/ucap-webmessenger-app/src/app/services/native.service.ts

78 lines
2.5 KiB
TypeScript
Raw Normal View History

2019-12-23 07:37:44 +00:00
import { Injectable, Inject, NgZone } from '@angular/core';
2019-12-12 08:15:09 +00:00
import { DOCUMENT } from '@angular/common';
import {
UCAP_NATIVE_SERVICE,
NativeService,
UpdateCheckConfig
} from '@ucap-webmessenger/native';
2019-11-19 07:44:50 +00:00
import { Store } from '@ngrx/store';
import { NGXLogger } from 'ngx-logger';
import * as AuthenticationStore from '@app/store/account/authentication';
2019-11-21 01:29:19 +00:00
import * as SettingsStore from '@app/store/messenger/settings';
2019-12-12 08:15:09 +00:00
import * as UpdateStore from '@app/store/setting/update';
import { PublicApiService } from '@ucap-webmessenger/api-public';
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
import {
LoginInfo,
KEY_LOGIN_INFO,
EnvironmentsInfo,
KEY_ENVIRONMENTS_INFO
} from '@app/types';
import { environment } from '../../environments/environment';
2019-11-19 07:44:50 +00:00
@Injectable({
providedIn: 'root'
})
export class AppNativeService {
constructor(
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService,
2019-12-12 08:15:09 +00:00
private publicApiService: PublicApiService,
private sessionStorageService: SessionStorageService,
@Inject(DOCUMENT) private document: Document,
2019-12-23 07:37:44 +00:00
private ngZone: NgZone,
2019-11-19 07:44:50 +00:00
private store: Store<any>,
private logger: NGXLogger
) {}
subscribe(): void {
this.nativeService.logout().subscribe(() => {
this.store.dispatch(AuthenticationStore.logoutConfirmation());
2019-11-19 07:44:50 +00:00
});
this.nativeService.changeStatus().subscribe(statusCode => {});
2019-11-21 01:29:19 +00:00
this.nativeService.showSetting().subscribe(() => {
2019-12-23 07:37:44 +00:00
this.ngZone.run(() => {
this.store.dispatch(SettingsStore.showDialog());
});
2019-11-21 01:29:19 +00:00
});
2019-11-19 07:44:50 +00:00
}
2019-12-12 08:15:09 +00:00
subscribeAfterLogin(): void {
const loginInfo = this.sessionStorageService.get<LoginInfo>(KEY_LOGIN_INFO);
const environmentsInfo = this.sessionStorageService.get<EnvironmentsInfo>(
KEY_ENVIRONMENTS_INFO
);
const els = this.document.getElementsByTagName('app-root');
const currentVersion = els.item(0).getAttribute('app-version');
const updateCheckConfig: UpdateCheckConfig = {
feed: this.publicApiService.urlForVersionInfo2({
deviceType: environment.productConfig.updateCheckConfig.deviceType,
companyGroupType: loginInfo.companyGroupType,
companyCode: loginInfo.companyCode,
loginId: loginInfo.loginId
}),
currentVersion,
intervalHour: environment.productConfig.updateCheckConfig.intervalHour
};
this.nativeService
.checkForInstantUpdates(updateCheckConfig)
.subscribe(updateInfo => {
this.store.dispatch(UpdateStore.existInstantUpdate({ updateInfo }));
});
}
2019-11-19 07:44:50 +00:00
}