|
@@ -38,6 +38,7 @@ import {PushService} from './push';
|
|
|
import {QrCodeService} from './qrcode';
|
|
|
import {ReceiverService} from './receiver';
|
|
|
import {StateService} from './state';
|
|
|
+import {TimeoutService} from './timeout';
|
|
|
import {TitleService} from './title';
|
|
|
import {VersionService} from './version';
|
|
|
|
|
@@ -172,6 +173,7 @@ export class WebClientService {
|
|
|
private pushService: PushService;
|
|
|
private qrCodeService: QrCodeService;
|
|
|
private receiverService: ReceiverService;
|
|
|
+ private timeoutService: TimeoutService;
|
|
|
private titleService: TitleService;
|
|
|
private versionService: VersionService;
|
|
|
|
|
@@ -213,6 +215,9 @@ export class WebClientService {
|
|
|
private pushToken: string = null;
|
|
|
private pushTokenType: threema.PushTokenType = null;
|
|
|
|
|
|
+ // Timeouts
|
|
|
+ private batteryStatusTimeout: ng.IPromise<void> = null;
|
|
|
+
|
|
|
// Other
|
|
|
private config: threema.Config;
|
|
|
private container: threema.Container.Factory;
|
|
@@ -222,7 +227,6 @@ export class WebClientService {
|
|
|
private trustedKeyStore: TrustedKeyStoreService;
|
|
|
public clientInfo: threema.ClientInfo = null;
|
|
|
public version = null;
|
|
|
- private batteryStatusTimeout: ng.IPromise<void> = null;
|
|
|
|
|
|
private blobCache = new Map<string, threema.BlobInfo>();
|
|
|
private loadingMessages = new Map<string, boolean>();
|
|
@@ -245,7 +249,7 @@ export class WebClientService {
|
|
|
'Container', 'TrustedKeyStore',
|
|
|
'StateService', 'NotificationService', 'MessageService', 'PushService', 'BrowserService',
|
|
|
'TitleService', 'QrCodeService', 'MimeService', 'ReceiverService',
|
|
|
- 'VersionService', 'BatteryStatusService',
|
|
|
+ 'VersionService', 'BatteryStatusService', 'TimeoutService',
|
|
|
'CONFIG',
|
|
|
];
|
|
|
constructor($log: ng.ILogService,
|
|
@@ -270,6 +274,7 @@ export class WebClientService {
|
|
|
receiverService: ReceiverService,
|
|
|
versionService: VersionService,
|
|
|
batteryStatusService: BatteryStatusService,
|
|
|
+ timeoutService: TimeoutService,
|
|
|
CONFIG: threema.Config) {
|
|
|
|
|
|
// Angular services
|
|
@@ -292,6 +297,7 @@ export class WebClientService {
|
|
|
this.pushService = pushService;
|
|
|
this.qrCodeService = qrCodeService;
|
|
|
this.receiverService = receiverService;
|
|
|
+ this.timeoutService = timeoutService;
|
|
|
this.titleService = titleService;
|
|
|
this.versionService = versionService;
|
|
|
|
|
@@ -396,11 +402,12 @@ export class WebClientService {
|
|
|
this.$log.info(`Initializing (keyStore=${keyStore !== undefined ? 'yes' : 'no'}, peerTrustedKey=` +
|
|
|
`${flags.peerTrustedKey !== undefined ? 'yes' : 'no'}, resume=${resumeSession})`);
|
|
|
|
|
|
- // Reset fields, blob cache & pending requests in case the session
|
|
|
+ // Reset fields, blob cache, pending requests and pending timeouts in case the session
|
|
|
// should explicitly not be resumed
|
|
|
if (!resumeSession) {
|
|
|
this.clearCache();
|
|
|
this.wireMessageFutures.clear();
|
|
|
+ this.timeoutService.cancelAll();
|
|
|
}
|
|
|
|
|
|
// Only move the previous connection's instances if the previous
|
|
@@ -870,10 +877,11 @@ export class WebClientService {
|
|
|
this.discardSession({ resetMessageSequenceNumber: false });
|
|
|
this.$log.debug(this.logTag, 'Session discarded');
|
|
|
|
|
|
- // Reset fields, blob cache & pending requests in case the session
|
|
|
+ // Reset fields, blob cache, pending requests and pending timeouts in case the session
|
|
|
// cannot be resumed
|
|
|
this.clearCache();
|
|
|
this.wireMessageFutures.clear();
|
|
|
+ this.timeoutService.cancelAll();
|
|
|
|
|
|
// Set required initialisation steps
|
|
|
requiredInitializationSteps.push(
|
|
@@ -923,7 +931,7 @@ export class WebClientService {
|
|
|
// Fetch current version
|
|
|
// Delay it to prevent the dialog from being closed by the messenger constructor,
|
|
|
// which closes all open dialogs.
|
|
|
- this.$timeout(() => this.versionService.checkForUpdate(), 7000);
|
|
|
+ this.timeoutService.register(() => this.versionService.checkForUpdate(), 7000, true, 'checkForUpdate');
|
|
|
|
|
|
// Notify state service about data loading
|
|
|
this.stateService.updateConnectionBuildupState('loading');
|
|
@@ -1147,6 +1155,9 @@ export class WebClientService {
|
|
|
// Remove all pending promises
|
|
|
this.wireMessageFutures.clear();
|
|
|
|
|
|
+ // Cancel pending timeouts
|
|
|
+ this.timeoutService.cancelAll();
|
|
|
+
|
|
|
// Reset the push service
|
|
|
this.pushService.reset();
|
|
|
|
|
@@ -4021,15 +4032,17 @@ export class WebClientService {
|
|
|
const isOk = stateChange.state === threema.GlobalConnectionState.Ok;
|
|
|
const wasOk = stateChange.prevState === threema.GlobalConnectionState.Ok;
|
|
|
if (!isOk && wasOk && this.batteryStatusService.dataAvailable) {
|
|
|
- this.batteryStatusTimeout = this.$timeout(
|
|
|
+ this.batteryStatusTimeout = this.timeoutService.register(
|
|
|
() => {
|
|
|
this.batteryStatusService.clearStatus();
|
|
|
this.batteryStatusTimeout = null;
|
|
|
},
|
|
|
60000,
|
|
|
+ true,
|
|
|
+ 'batteryStatusHide',
|
|
|
);
|
|
|
} else if (isOk && this.batteryStatusTimeout !== null) {
|
|
|
- this.$timeout.cancel(this.batteryStatusTimeout);
|
|
|
+ this.timeoutService.cancel(this.batteryStatusTimeout);
|
|
|
this.batteryStatusTimeout = null;
|
|
|
}
|
|
|
}
|