Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(app): keep the age block to the instance it was set on (#3739)

Hampus5290c7f4d1f0
diff --git a/fluxer_app/src/features/auth/state/AccountEntryStorage.ts b/fluxer_app/src/features/auth/state/AccountEntryStorage.ts
index 73d4a6c5e..02209a3a9 100644
--- a/fluxer_app/src/features/auth/state/AccountEntryStorage.ts
+++ b/fluxer_app/src/features/auth/state/AccountEntryStorage.ts
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {runtimeInstanceKey} from '@app/features/app/state/InstanceSnapshotStore';
+import RuntimeConfig from '@app/features/app/state/RuntimeConfig';
import {getProtectedLocalStorage} from '@app/features/platform/state/ProtectedWebStorage';
import {Logger} from '@app/features/platform/utils/AppLogger';
import {MS_PER_DAY} from '@fluxer/date_utils/src/DateConstants';
@@ -7,7 +9,7 @@ import {MS_PER_DAY} from '@fluxer/date_utils/src/DateConstants';
const logger = new Logger('AccountEntryStorage');
const DEVICE_PROOF_KEY_PREFIX = 'fluxer.device_proof.';
-const AGE_BLOCK_KEY = 'fluxer.age_block_until';
+const AGE_BLOCK_KEY_PREFIX = 'fluxer.age_block_until.';
function readItem(key: string): string | null {
try {
@@ -37,17 +39,28 @@ export function storeDeviceProof(userId: string, deviceProof: string | undefined
writeItem(`${DEVICE_PROOF_KEY_PREFIX}${userId}`, deviceProof);
}
+function ageBlockKey(): string | null {
+ const snapshot = RuntimeConfig.getSnapshotOrNull();
+ const instanceKey = snapshot === null ? null : runtimeInstanceKey(snapshot);
+ return instanceKey === null ? null : `${AGE_BLOCK_KEY_PREFIX}${instanceKey}`;
+}
+
export function isAgeBlocked(): boolean {
- const now = Date.now();
- const until = Number(readItem(AGE_BLOCK_KEY));
- return Number.isFinite(until) && until > now;
+ const key = ageBlockKey();
+ if (key === null) {
+ return false;
+ }
+ const until = Number(readItem(key));
+ return Number.isFinite(until) && until > Date.now();
}
let ageBlockedAccountRemoved = false;
export function markAgeBlocked(options: {accountRemoved?: boolean} = {}): void {
- const now = Date.now();
- writeItem(AGE_BLOCK_KEY, String(now + MS_PER_DAY));
+ const key = ageBlockKey();
+ if (key !== null) {
+ writeItem(key, String(Date.now() + MS_PER_DAY));
+ }
ageBlockedAccountRemoved = options.accountRemoved === true;
}