Reduce unnecessary redux update during message receipt

This commit is contained in:
trevor-signal 2023-12-22 15:38:49 -05:00 committed by GitHub
parent 95842c6e0b
commit 844613272c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2266,7 +2266,7 @@ export async function startApp(): Promise<void> {
maxSize: Infinity,
});
const throttledSetInboxEnvelopeTimestamp = throttle(
const _throttledSetInboxEnvelopeTimestamp = throttle(
serverTimestamp => {
window.reduxActions.inbox.setInboxEnvelopeTimestamp(serverTimestamp);
},
@ -2274,16 +2274,24 @@ export async function startApp(): Promise<void> {
{ leading: false }
);
function setInboxEnvelopeTimestamp(timestamp: number): void {
// This timestamp is only used in the loading screen UI. If the app has loaded, let's
// not set it to avoid unnecessary renders
if (!window.reduxStore.getState().app.hasInitialLoadCompleted) {
_throttledSetInboxEnvelopeTimestamp(timestamp);
}
}
async function onEnvelopeQueued({
envelope,
}: EnvelopeQueuedEvent): Promise<void> {
throttledSetInboxEnvelopeTimestamp(envelope.serverTimestamp);
setInboxEnvelopeTimestamp(envelope.serverTimestamp);
}
async function onEnvelopeUnsealed({
envelope,
}: EnvelopeUnsealedEvent): Promise<void> {
throttledSetInboxEnvelopeTimestamp(envelope.serverTimestamp);
setInboxEnvelopeTimestamp(envelope.serverTimestamp);
const ourAci = window.textsecure.storage.user.getAci();
if (