signal-desktop/ts/util/incrementMessageCounter.ts
2021-08-17 16:15:45 -07:00

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);