Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

refactor(app): drop sudo from forget IPs tool, flatten labels

Hampuse173dc4220b8
diff --git a/fluxer_app/src/features/channel/components/channel_header_components/developer_tools/DeveloperOptionLabels.ts b/fluxer_app/src/features/channel/components/channel_header_components/developer_tools/DeveloperOptionLabels.ts
index dedec6679..b7bd15c0e 100644
--- a/fluxer_app/src/features/channel/components/channel_header_components/developer_tools/DeveloperOptionLabels.ts
+++ b/fluxer_app/src/features/channel/components/channel_header_components/developer_tools/DeveloperOptionLabels.ts
@@ -253,11 +253,13 @@ const formatDeveloperOptionValue = <K extends keyof DeveloperOptionsState>(
}
case 'mockGiftDurationMonths': {
const months = value as number | null;
- return months === 0
- ? i18n._(LIFETIME_DESCRIPTOR)
- : months === null
- ? i18n._(USE_DEFAULT_DESCRIPTOR)
- : i18n._(MONTHS_PLURAL_DESCRIPTOR, {months});
+ if (months === 0) {
+ return i18n._(LIFETIME_DESCRIPTOR);
+ }
+ if (months === null) {
+ return i18n._(USE_DEFAULT_DESCRIPTOR);
+ }
+ return i18n._(MONTHS_PLURAL_DESCRIPTOR, {months});
}
case 'mockAttachmentStates': {
const count = Object.keys(value as DeveloperOptionsState['mockAttachmentStates']).length;
diff --git a/fluxer_app/src/features/channel/components/channel_header_components/developer_tools/ToolsMenu.tsx b/fluxer_app/src/features/channel/components/channel_header_components/developer_tools/ToolsMenu.tsx
index 1eefb6b12..8a54c8512 100644
--- a/fluxer_app/src/features/channel/components/channel_header_components/developer_tools/ToolsMenu.tsx
+++ b/fluxer_app/src/features/channel/components/channel_header_components/developer_tools/ToolsMenu.tsx
@@ -2,7 +2,6 @@
import RuntimeCrash from '@app/features/app/state/RuntimeCrash';
import {openClaimAccountModal} from '@app/features/auth/components/modals/ClaimAccountModal';
-import {useSudo} from '@app/features/auth/hooks/useSudo';
import NewDeviceMonitoring from '@app/features/auth/state/NewDeviceMonitoring';
import SudoPrompt from '@app/features/auth/state/SudoPrompt';
import * as PrivateChannelCommands from '@app/features/channel/commands/PrivateChannelCommands';
@@ -17,6 +16,7 @@ import GatewaySessions from '@app/features/gateway/transport/GatewaySessionPool'
import {TRY_AGAIN_IN_A_MOMENT_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';
import {KeyboardModeIntroModal} from '@app/features/input/components/modals/KeyboardModeIntroModal';
import {Logger} from '@app/features/platform/utils/AppLogger';
+import {isAbortError} from '@app/features/platform/utils/PlatformHelpers';
import {remFromPx} from '@app/features/theme/layout/RemFromPx';
import TrustedDomain from '@app/features/trusted_domain/state/TrustedDomain';
@@ -115,7 +115,6 @@ const RESETTING_PREMIUM_STATE_DESCRIPTOR = msg({
});
export const ToolsMenu: React.FC<{onClose: () => void}> = observer(({onClose}) => {
const {i18n} = useLingui();
- const sudo = useSudo();
const [isForgettingAuthorizedIps, setIsForgettingAuthorizedIps] = useState(false);
const [isClearingTrustedDomains, setIsClearingTrustedDomains] = useState(false);
const [isResettingPremiumState, setIsResettingPremiumState] = useState(false);
@@ -124,9 +123,7 @@ export const ToolsMenu: React.FC<{onClose: () => void}> = observer(({onClose}) =
const handleForgetAuthorizedIps = useCallback(async () => {
setIsForgettingAuthorizedIps(true);
try {
- const sudoPayload = await sudo.require();
- await UserCommands.forgetAuthorizedIps(sudoPayload);
- sudo.finalize();
+ await UserCommands.forgetAuthorizedIps();
ToastCommands.createToast({
type: 'success',
children: i18n._(AUTHORIZED_IPS_CLEARED_NEW_LOGINS_WILL_REQUIRE_EMAIL_DESCRIPTOR),
@@ -142,7 +139,7 @@ export const ToolsMenu: React.FC<{onClose: () => void}> = observer(({onClose}) =
} finally {
setIsForgettingAuthorizedIps(false);
}
- }, [sudo, i18n]);
+ }, [i18n]);
const handleForgetAuthorizedIpsClick = useCallback(() => {
openDangerConfirmation({
onClose,
@@ -205,11 +202,14 @@ export const ToolsMenu: React.FC<{onClose: () => void}> = observer(({onClose}) =
onPrimary: handleResetPremiumState,
});
}, [handleResetPremiumState, onClose, i18n]);
- const clearTrustedDomainsLabel = TrustedDomain.trustAllDomains
- ? i18n._(CLEAR_TRUST_ALL_SETTING_DESCRIPTOR)
- : trustedDomainsCount === 0
- ? i18n._(NO_TRUSTED_DOMAINS_DESCRIPTOR)
- : i18n._(CLEAR_TRUSTED_DOMAINS_COUNT_DESCRIPTOR, {trustedDomainsCount});
+ let clearTrustedDomainsLabel: string;
+ if (TrustedDomain.trustAllDomains) {
+ clearTrustedDomainsLabel = i18n._(CLEAR_TRUST_ALL_SETTING_DESCRIPTOR);
+ } else if (trustedDomainsCount === 0) {
+ clearTrustedDomainsLabel = i18n._(NO_TRUSTED_DOMAINS_DESCRIPTOR);
+ } else {
+ clearTrustedDomainsLabel = i18n._(CLEAR_TRUSTED_DOMAINS_COUNT_DESCRIPTOR, {trustedDomainsCount});
+ }
return (
<MenuItemSubmenu
label={i18n._(RUNTIME_UTILITIES_DESCRIPTOR)}
@@ -285,7 +285,7 @@ export const ToolsMenu: React.FC<{onClose: () => void}> = observer(({onClose}) =
<Trans>Show keyboard mode intro</Trans>
</MenuItem>
<MenuItem
- onClick={() => openClaimAccountModal({force: true})}
+ onClick={() => openClaimAccountModal()}
data-flx="channel.channel-header-components.developer-tools-context-menu.tools-menu.menu-item.open-claim-account-modal"
>
<Trans>Open claim account modal</Trans>
@@ -297,7 +297,9 @@ export const ToolsMenu: React.FC<{onClose: () => void}> = observer(({onClose}) =
void SudoPrompt.requestVerification({
method: 'POST',
path: '<developer-tools>',
- }).catch(() => {});
+ }).catch((error: unknown) => {
+ if (!isAbortError(error)) logger.warn('Failed to open sudo verification', error);
+ });
}}
data-flx="channel.channel-header-components.developer-tools-context-menu.tools-menu.menu-item.close--2"
>
diff --git a/fluxer_app/src/features/channel/components/invite_embed/InviteEmbedUtils.ts b/fluxer_app/src/features/channel/components/invite_embed/InviteEmbedUtils.ts
index 6ed937209..681177c0c 100644
--- a/fluxer_app/src/features/channel/components/invite_embed/InviteEmbedUtils.ts
+++ b/fluxer_app/src/features/channel/components/invite_embed/InviteEmbedUtils.ts
@@ -7,10 +7,6 @@ import type {Channel} from '@fluxer/schema/src/domains/channel/ChannelSchemas';
import type {Guild as WireGuild} from '@fluxer/schema/src/domains/guild/GuildResponseSchemas';
export function getGroupDMTitle(channel: Channel, unnamedGroupLabel: string): string {
- return getChannelDisplayName(channel, unnamedGroupLabel);
-}
-
-function getChannelDisplayName(channel: Channel, unnamedGroupLabel: string): string {
const channelName = channel.name?.trim();
if (channelName && channelName.length > 0) {
return channelName;