Hide "become a sustainer" button if you're already a sustainer
This commit is contained in:
parent
7edf3763a8
commit
67b17ec317
22 changed files with 318 additions and 26 deletions
36
ts/services/areWeASubscriber.ts
Normal file
36
ts/services/areWeASubscriber.ts
Normal 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();
|
Loading…
Add table
Add a link
Reference in a new issue