Skip to content

Commit

Permalink
Do not initialize receivedAtCounter in connect
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny-signal committed Aug 17, 2021
1 parent d222376 commit 6343e7c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
3 changes: 0 additions & 3 deletions ts/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2173,9 +2173,6 @@ export async function startApp(): Promise<void> {
let connectCount = 0;
let connecting = false;
async function connect(firstRun?: boolean) {
window.receivedAtCounter =
window.storage.get('lastReceivedAtCounter') || Date.now();

if (connecting) {
window.log.warn('connect already running', { connectCount });
return;
Expand Down
15 changes: 7 additions & 8 deletions ts/util/incrementMessageCounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@

import { debounce } from 'lodash';

let receivedAtCounter: number | undefined;

export function incrementMessageCounter(): number {
if (!window.receivedAtCounter) {
window.receivedAtCounter =
if (!receivedAtCounter) {
receivedAtCounter =
Number(localStorage.getItem('lastReceivedAtCounter')) || Date.now();
}

window.receivedAtCounter += 1;
receivedAtCounter += 1;
debouncedUpdateLastReceivedAt();

return window.receivedAtCounter;
return receivedAtCounter;
}

const debouncedUpdateLastReceivedAt = debounce(() => {
localStorage.setItem(
'lastReceivedAtCounter',
String(window.receivedAtCounter)
);
localStorage.setItem('lastReceivedAtCounter', String(receivedAtCounter));
}, 500);
1 change: 0 additions & 1 deletion ts/window.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ declare global {
baseAttachmentsPath: string;
baseStickersPath: string;
baseTempPath: string;
receivedAtCounter: number;
enterKeyboardMode: () => void;
enterMouseMode: () => void;
getAccountManager: () => AccountManager;
Expand Down

0 comments on commit 6343e7c

Please sign in to comment.