22 lines
580 B
TypeScript
22 lines
580 B
TypeScript
// Copyright 2021 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
import { debounce } from 'lodash';
|
|
|
|
let receivedAtCounter: number | undefined;
|
|
|
|
export function incrementMessageCounter(): number {
|
|
if (!receivedAtCounter) {
|
|
receivedAtCounter =
|
|
Number(localStorage.getItem('lastReceivedAtCounter')) || Date.now();
|
|
}
|
|
|
|
receivedAtCounter += 1;
|
|
debouncedUpdateLastReceivedAt();
|
|
|
|
return receivedAtCounter;
|
|
}
|
|
|
|
const debouncedUpdateLastReceivedAt = debounce(() => {
|
|
localStorage.setItem('lastReceivedAtCounter', String(receivedAtCounter));
|
|
}, 500);
|