2018-04-23 19:03:47 +02:00
|
|
|
import { Utils } from "../misc/utils";
|
2018-01-09 22:19:55 +01:00
|
|
|
|
2018-04-04 14:22:18 +02:00
|
|
|
import { AppIdService as AppIdServiceAbstraction } from "../abstractions/appId.service";
|
2018-02-19 19:07:19 +01:00
|
|
|
import { StorageService } from "../abstractions/storage.service";
|
2018-01-09 22:19:55 +01:00
|
|
|
|
2018-04-04 14:22:18 +02:00
|
|
|
export class AppIdService implements AppIdServiceAbstraction {
|
2018-01-09 22:19:55 +01:00
|
|
|
constructor(private storageService: StorageService) {}
|
|
|
|
|
|
|
|
getAppId(): Promise<string> {
|
|
|
|
return this.makeAndGetAppId("appId");
|
|
|
|
}
|
|
|
|
|
|
|
|
getAnonymousAppId(): Promise<string> {
|
|
|
|
return this.makeAndGetAppId("anonymousAppId");
|
|
|
|
}
|
|
|
|
|
|
|
|
private async makeAndGetAppId(key: string) {
|
|
|
|
const existingId = await this.storageService.get<string>(key);
|
|
|
|
if (existingId != null) {
|
|
|
|
return existingId;
|
|
|
|
}
|
2021-12-16 13:36:21 +01:00
|
|
|
|
2018-04-23 19:03:47 +02:00
|
|
|
const guid = Utils.newGuid();
|
2018-01-09 22:19:55 +01:00
|
|
|
await this.storageService.save(key, guid);
|
|
|
|
return guid;
|
2021-12-16 13:36:21 +01:00
|
|
|
}
|
2018-01-09 22:19:55 +01:00
|
|
|
}
|