Hide "become a sustainer" button if you're already a sustainer

This commit is contained in:
Evan Hahn 2021-11-30 10:29:57 -06:00 committed by GitHub
parent 7edf3763a8
commit 67b17ec317
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 318 additions and 26 deletions

View file

@ -0,0 +1,36 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { StorageInterface } from '../types/Storage.d';
import type { WebAPIType } from '../textsecure/WebAPI';
import { LatestQueue } from '../util/LatestQueue';
import { waitForOnline } from '../util/waitForOnline';
// This is only exported for testing.
export class AreWeASubscriberService {
private readonly queue = new LatestQueue();
update(
storage: Pick<StorageInterface, 'get' | 'put' | 'onready'>,
server: Pick<WebAPIType, 'getHasSubscription'>
): void {
this.queue.add(async () => {
await new Promise<void>(resolve => storage.onready(resolve));
const subscriberId = storage.get('subscriberId');
if (!subscriberId || !subscriberId.byteLength) {
storage.put('areWeASubscriber', false);
return;
}
await waitForOnline(navigator, window);
storage.put(
'areWeASubscriber',
await server.getHasSubscription(subscriberId)
);
});
}
}
export const areWeASubscriberService = new AreWeASubscriberService();