From aa86c1d751087d0f49b624bbc3fc82589d6e69ac Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 23 Feb 2021 12:51:47 +0000 Subject: [PATCH] Ensure that a dismissed usage alert toast stays dismissed --- src/components/structures/LoggedInView.tsx | 19 +++++++++++++++++-- src/toasts/ServerLimitToast.tsx | 7 +++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/components/structures/LoggedInView.tsx b/src/components/structures/LoggedInView.tsx index 77c846d816..60969e3220 100644 --- a/src/components/structures/LoggedInView.tsx +++ b/src/components/structures/LoggedInView.tsx @@ -107,6 +107,7 @@ interface IState { errcode: string; }; }; + usageLimitDismissed: boolean; usageLimitEventContent?: IUsageLimit; usageLimitEventTs?: number; useCompactLayout: boolean; @@ -152,6 +153,7 @@ class LoggedInView extends React.Component { syncErrorData: undefined, // use compact timeline view useCompactLayout: SettingsStore.getValue('useCompactLayout'), + usageLimitDismissed: false, }; // stash the MatrixClient in case we log out before we are unmounted @@ -303,14 +305,27 @@ class LoggedInView extends React.Component { } }; + _onHideToast = () => { + this.setState({ + usageLimitDismissed: true, + }); + } + _calculateServerLimitToast(syncError: IState["syncErrorData"], usageLimitEventContent?: IUsageLimit) { const error = syncError && syncError.error && syncError.error.errcode === "M_RESOURCE_LIMIT_EXCEEDED"; if (error) { usageLimitEventContent = syncError.error.data; } - if (usageLimitEventContent) { - showServerLimitToast(usageLimitEventContent.limit_type, usageLimitEventContent.admin_contact, error); + // usageLimitDismissed is true when the user has explicitly hidden the toast + // and it will be reset to false if a *new* usage alert comes in. + if (usageLimitEventContent && this.state.usageLimitDismissed) { + showServerLimitToast( + usageLimitEventContent.limit_type, + this._onHideToast, + usageLimitEventContent.admin_contact, + error, + ); } else { hideServerLimitToast(); } diff --git a/src/toasts/ServerLimitToast.tsx b/src/toasts/ServerLimitToast.tsx index d35140be3d..068d62f9ea 100644 --- a/src/toasts/ServerLimitToast.tsx +++ b/src/toasts/ServerLimitToast.tsx @@ -23,7 +23,7 @@ import {messageForResourceLimitError} from "../utils/ErrorUtils"; const TOAST_KEY = "serverlimit"; -export const showToast = (limitType: string, adminContact?: string, syncError?: boolean) => { +export const showToast = (limitType: string, onHideToast: () => void, adminContact?: string, syncError?: boolean) => { const errorText = messageForResourceLimitError(limitType, adminContact, { 'monthly_active_user': _td("Your homeserver has exceeded its user limit."), '': _td("Your homeserver has exceeded one of its resource limits."), @@ -38,7 +38,10 @@ export const showToast = (limitType: string, adminContact?: string, syncError?: props: { description: {errorText} {contactText}, acceptLabel: _t("Ok"), - onAccept: hideToast, + onAccept: () => { + hideToast() + onHideToast() + }, }, component: GenericToast, priority: 70,