Throttle failed endorsements toast

Co-authored-by: Jamie Kyle <113370520+jamiebuilds-signal@users.noreply.github.com>
This commit is contained in:
automated-signal 2024-10-18 13:25:08 -05:00 committed by GitHub
parent fe05810d7d
commit 8c7523cf33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
// Copyright 2024 Signal Messenger, LLC // Copyright 2024 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import { Aci } from '@signalapp/libsignal-client'; import { Aci } from '@signalapp/libsignal-client';
import { throttle } from 'lodash';
import type { import type {
GroupSendCombinedEndorsementRecord, GroupSendCombinedEndorsementRecord,
GroupSendMemberEndorsementRecord, GroupSendMemberEndorsementRecord,
@ -22,7 +23,7 @@ import type { ServiceIdString } from '../types/ServiceId';
import { fromAciObject } from '../types/ServiceId'; import { fromAciObject } from '../types/ServiceId';
import * as log from '../logging/log'; import * as log from '../logging/log';
import type { GroupV2MemberType } from '../model-types'; import type { GroupV2MemberType } from '../model-types';
import { DurationInSeconds } from './durations'; import { DurationInSeconds, MINUTE } from './durations';
import { ToastType } from '../types/Toast'; import { ToastType } from '../types/Toast';
import * as Errors from '../types/errors'; import * as Errors from '../types/errors';
import { isTestOrMockEnvironment } from '../environment'; import { isTestOrMockEnvironment } from '../environment';
@ -300,12 +301,20 @@ export class GroupSendEndorsementState {
} }
} }
export function onFailedToSendWithEndorsements(error: Error): void { const showFailedToSendWithEndorsementsToast = throttle(
log.error('onFailedToSendWithEndorsements', Errors.toLogFormat(error)); () => {
if (isTestOrMockEnvironment() || isAlpha(window.getVersion())) {
window.reduxActions.toast.showToast({ window.reduxActions.toast.showToast({
toastType: ToastType.FailedToSendWithEndorsements, toastType: ToastType.FailedToSendWithEndorsements,
}); });
},
5 * MINUTE,
{ trailing: false }
);
export function onFailedToSendWithEndorsements(error: Error): void {
log.error('onFailedToSendWithEndorsements', Errors.toLogFormat(error));
if (isTestOrMockEnvironment() || isAlpha(window.getVersion())) {
showFailedToSendWithEndorsementsToast();
} }
if (window.SignalCI) { if (window.SignalCI) {
window.SignalCI.handleEvent('fatalTestError', error); window.SignalCI.handleEvent('fatalTestError', error);