A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
refactor(app): flatten messaging, link and report ternaries
Hampuse2ca7d57f8ce
diff --git a/fluxer_app/src/features/messaging/components/markdown/renderers/LinkRenderer.tsx b/fluxer_app/src/features/messaging/components/markdown/renderers/LinkRenderer.tsxindex 1c225d294..1b64f4427 100644--- a/fluxer_app/src/features/messaging/components/markdown/renderers/LinkRenderer.tsx+++ b/fluxer_app/src/features/messaging/components/markdown/renderers/LinkRenderer.tsx@@ -17,11 +17,7 @@ import DiscoveryChannelPreviews from '@app/features/discovery/state/DiscoveryChaimport {GuildAcronym} from '@app/features/guild/components/GuildAcronym';import type {Guild} from '@app/features/guild/models/Guild';import Guilds from '@app/features/guild/state/Guilds';-import {- COPY_LINK_DESCRIPTOR,- OKAY_DESCRIPTOR,- OPEN_LINK_DESCRIPTOR,-} from '@app/features/i18n/utils/CommonMessageDescriptors';+import {COPY_LINK_DESCRIPTOR, OPEN_LINK_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';import * as InviteCommands from '@app/features/invite/commands/InviteCommands';import * as InviteUtils from '@app/features/invite/utils/InviteUtils';import {LinkDestinationTooltip} from '@app/features/messaging/components/LinkDestinationTooltip';@@ -70,6 +66,7 @@ import * as ModalCommands from '@app/features/ui/commands/ModalCommands';import {modal} from '@app/features/ui/commands/ModalCommands';import * as TextCopyCommands from '@app/features/ui/commands/TextCopyCommands';import FocusRing from '@app/features/ui/focus_ring/FocusRing';+import {CaretRightIcon} from '@app/features/ui/icons/DirectionalIcons';import {APP_PROTOCOL_PREFIX, APP_PROTOCOL_SCHEME, isAppProtocolUrl} from '@app/features/ui/utils/AppProtocol';import {openExternalUrl} from '@app/features/ui/utils/NativeUtils';import {@@ -84,7 +81,7 @@ import {isProbablyAValidSnowflake} from '@fluxer/snowflake/src/SnowflakeUtils';import type {I18n} from '@lingui/core';import {msg} from '@lingui/core/macro';import {useLingui} from '@lingui/react';-import {CaretRightIcon, ChatTeardropIcon, LockIcon} from '@phosphor-icons/react';+import {ChatTeardropIcon, LockIcon} from '@phosphor-icons/react';import {clsx} from 'clsx';import {observer} from 'mobx-react-lite';import type React from 'react';@@ -127,7 +124,7 @@ const OPEN_SETTINGS_SECTION_DESCRIPTOR = msg({const OPEN_APP_PAGE_DESCRIPTOR = msg({message: 'Open {labelText}',comment:- 'Accessible label for an inline chat link pill that opens an app page such as Discovery. labelText is the page name.',+ 'Accessible label for an inline chat link pill that opens an app page such as Explore. labelText is the page name.',});const PAGE_LINK_DESCRIPTOR = msg({message: 'page link',@@ -177,11 +174,6 @@ function showChannelAccessDeniedModal(i18n: I18n): void {<ConfirmModaltitle={i18n._(CHANNEL_ACCESS_DENIED_DESCRIPTOR)}description={i18n._(YOU_DO_NOT_HAVE_ACCESS_TO_THE_CHANNEL_DESCRIPTOR)}- primaryText={i18n._(OKAY_DESCRIPTOR)}- primaryVariant="primary"- secondaryText={false}- onPrimary={() => {}}- hideCloseButtondata-flx="messaging.markdown.renderers.link-renderer.show-channel-access-denied-modal.confirm-modal"/>)),@@ -355,19 +347,69 @@ const JumpLinkMention = observer(function JumpLinkMention({const shouldShowDMIconLabel = isDMChannel && !messageId;const hasDetailChunk = Boolean(messageId) || shouldShowChannelInfo;const roleDescription = messageId ? i18n._(MESSAGE_LINK_DESCRIPTOR) : i18n._(CHANNEL_LINK_DESCRIPTOR);- const ariaLabel = messageId- ? labelText- ? i18n._(JUMP_TO_THE_MESSAGE_IN_DESCRIPTOR, {labelText})- : i18n._(JUMP_TO_THE_LINKED_MESSAGE_DESCRIPTOR)- : labelText- ? i18n._(JUMP_TO_DESCRIPTOR, {labelText})- : i18n._(JUMP_TO_THE_LINKED_CHANNEL_DESCRIPTOR);+ let ariaLabel: string;+ if (messageId) {+ if (labelText) {+ ariaLabel = i18n._(JUMP_TO_THE_MESSAGE_IN_DESCRIPTOR, {labelText});+ } else {+ ariaLabel = i18n._(JUMP_TO_THE_LINKED_MESSAGE_DESCRIPTOR);+ }+ } else if (labelText) {+ ariaLabel = i18n._(JUMP_TO_DESCRIPTOR, {labelText});+ } else {+ ariaLabel = i18n._(JUMP_TO_THE_LINKED_CHANNEL_DESCRIPTOR);+ }const Component = interactive ? 'button' : 'span';+ const className = clsx(markupStyles.mention, interactive && markupStyles.interactive, jumpLinkStyles.jumpLinkButton);+ let leadingChunk: React.ReactNode;+ if (guild) {+ leadingChunk = (+ <span+ className={jumpLinkStyles.part}+ data-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.part--guild"+ >+ <CompactGuildMentionIcon+ guild={guild}+ data-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.compact-guild-mention-icon"+ />+ <span+ className={jumpLinkStyles.name}+ data-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.guild-name"+ >+ {guild.name}+ </span>+ </span>+ );+ } else if (shouldShowDMIconLabel) {+ leadingChunk = (+ <span+ className={jumpLinkStyles.part}+ data-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.part--dm"+ >+ {getIcon(channel, {className: jumpLinkStyles.icon})}+ <span+ className={jumpLinkStyles.name}+ data-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.dm-name"+ >+ {displayName}+ </span>+ </span>+ );+ } else {+ leadingChunk = (+ <span+ className={jumpLinkStyles.name}+ data-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.label"+ >+ {displayName}+ </span>+ );+ }return (<Componentdata-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.component.click"{...(interactive ? {type: 'button'} : {})}- className={clsx(markupStyles.mention, interactive && markupStyles.interactive, jumpLinkStyles.jumpLinkButton)}+ className={className}onClick={handleClick}onAuxClick={handleAuxClick}onContextMenu={handleContextMenu}@@ -375,43 +417,7 @@ const JumpLinkMention = observer(function JumpLinkMention({{...(interactive ? {'aria-roledescription': roleDescription} : {})}tabIndex={interactive ? 0 : -1}>- {guild ? (- <span- className={jumpLinkStyles.part}- data-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.part--guild"- >- <CompactGuildMentionIcon- guild={guild}- data-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.compact-guild-mention-icon"- />- <span- className={jumpLinkStyles.name}- data-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.guild-name"- >- {guild.name}- </span>- </span>- ) : shouldShowDMIconLabel ? (- <span- className={jumpLinkStyles.part}- data-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.part--dm"- >- {getIcon(channel, {className: jumpLinkStyles.icon})}- <span- className={jumpLinkStyles.name}- data-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.dm-name"- >- {displayName}- </span>- </span>- ) : (- <span- className={jumpLinkStyles.name}- data-flx="messaging.markdown.renderers.link-renderer.jump-link-mention.label"- >- {displayName}- </span>- )}+ {leadingChunk}{hasDetailChunk && (<><span@@ -988,11 +994,6 @@ export const LinkRenderer = observer(function LinkRenderer({<ConfirmModaltitle={i18n._(DEVELOPER_TOOLS_DESCRIPTOR)}description={i18n._(DEVELOPER_TOOLS_ARE_AVAILABLE_FROM_THE_STAFF_BADGE_DESCRIPTOR)}- primaryText={i18n._(OKAY_DESCRIPTOR)}- primaryVariant="primary"- secondaryText={false}- onPrimary={() => {}}- hideCloseButtondata-flx="messaging.markdown.renderers.link-renderer.handle-click.confirm-modal--2"/>)),@@ -1003,11 +1004,6 @@ export const LinkRenderer = observer(function LinkRenderer({<ConfirmModaltitle={i18n._(LINK_UNAVAILABLE_DESCRIPTOR)}description={i18n._(THIS_LINK_IS_NOT_AVAILABLE_FOR_YOUR_ACCOUNT_DESCRIPTOR)}- primaryText={i18n._(OKAY_DESCRIPTOR)}- primaryVariant="primary"- secondaryText={false}- onPrimary={() => {}}- hideCloseButtondata-flx="messaging.markdown.renderers.link-renderer.handle-click.confirm-modal--3"/>)),@@ -1032,11 +1028,6 @@ export const LinkRenderer = observer(function LinkRenderer({<ConfirmModaltitle={i18n._(LINK_UNAVAILABLE_DESCRIPTOR)}description={i18n._(THIS_LINK_IS_NOT_AVAILABLE_FOR_YOUR_ACCOUNT_DESCRIPTOR)}- primaryText={i18n._(OKAY_DESCRIPTOR)}- primaryVariant="primary"- secondaryText={false}- onPrimary={() => {}}- hideCloseButtondata-flx="messaging.markdown.renderers.link-renderer.handle-click.confirm-modal--4"/>)),diff --git a/fluxer_app/src/features/messaging/hooks/useMessageListKeyboardNavigation.ts b/fluxer_app/src/features/messaging/hooks/useMessageListKeyboardNavigation.tsindex 7c2de9dfe..5cd587c3f 100644--- a/fluxer_app/src/features/messaging/hooks/useMessageListKeyboardNavigation.ts+++ b/fluxer_app/src/features/messaging/hooks/useMessageListKeyboardNavigation.ts@@ -197,7 +197,12 @@ export function useMessageListKeyboardNavigation(options: MessageListKeyboardNavconst handleKeyDown = (event: KeyboardEvent) => {if (!keyboardModeEnabled) return;if (isEditableElement(document.activeElement)) return;- const delta = event.key === 'ArrowUp' ? -1 : event.key === 'ArrowDown' ? 1 : 0;+ let delta = 0;+ if (event.key === 'ArrowUp') {+ delta = -1;+ } else if (event.key === 'ArrowDown') {+ delta = 1;+ }const isNavigationKey = delta !== 0;if (isNavigationKey && hasShortcutModifier(event)) return;if (!isNavigationKey && event.key !== 'Escape') return;diff --git a/fluxer_app/src/features/messaging/hooks/useMessageSubmission.tsx b/fluxer_app/src/features/messaging/hooks/useMessageSubmission.tsxindex d64aafb75..35aee1866 100644--- a/fluxer_app/src/features/messaging/hooks/useMessageSubmission.tsx+++ b/fluxer_app/src/features/messaging/hooks/useMessageSubmission.tsx@@ -88,16 +88,15 @@ export const useMessageSubmission = ({) => {const isTtsCall = typeof stickersOrTts === 'boolean';const tts = isTtsCall ? stickersOrTts : undefined;- const stickers = isTtsCall- ? Array.isArray(favoriteMemeIdOrStickers)- ? favoriteMemeIdOrStickers- : []- : stickersOrTts;- const favoriteMemeId = isTtsCall- ? maybeFavoriteMemeId- : typeof favoriteMemeIdOrStickers === 'string'- ? favoriteMemeIdOrStickers- : undefined;+ let stickers: Array<MessageStickerItem>;+ let favoriteMemeId: string | undefined;+ if (isTtsCall) {+ stickers = Array.isArray(favoriteMemeIdOrStickers) ? favoriteMemeIdOrStickers : [];+ favoriteMemeId = maybeFavoriteMemeId;+ } else {+ stickers = stickersOrTts;+ favoriteMemeId = typeof favoriteMemeIdOrStickers === 'string' ? favoriteMemeIdOrStickers : undefined;+ }const currentUser = Users.getCurrentUser();if (!channel || !currentUser || !accountOwnsActiveView(accountKey)) return false;const hasNonTextContent =diff --git a/fluxer_app/src/features/messaging/hooks/useTextareaExpressionHandlers.ts b/fluxer_app/src/features/messaging/hooks/useTextareaExpressionHandlers.tsindex 9a08a10a7..c6658c05d 100644--- a/fluxer_app/src/features/messaging/hooks/useTextareaExpressionHandlers.ts+++ b/fluxer_app/src/features/messaging/hooks/useTextareaExpressionHandlers.ts@@ -133,7 +133,7 @@ export const useTextareaExpressionHandlers = ({const actualText = `<@${userId}>`;const displayText = `@${NicknameUtils.formatUserTagForStreamerMode(user)}`;const needsSpace = prevValue.length > 0 && !prevValue.endsWith(' ');- const prefix = prevValue.length === 0 ? '' : needsSpace ? ' ' : '';+ const prefix = needsSpace ? ' ' : '';const insertPosition = prevValue.length + prefix.length;const segmentManager = new TextareaSegmentManager();segmentManager.setSegments(segmentManagerRef.current.getSegmentsCopy());diff --git a/fluxer_app/src/features/messaging/state/SavedMessages.ts b/fluxer_app/src/features/messaging/state/SavedMessages.tsindex 370ef9aa4..88a233ae3 100644--- a/fluxer_app/src/features/messaging/state/SavedMessages.ts+++ b/fluxer_app/src/features/messaging/state/SavedMessages.ts@@ -9,7 +9,9 @@ import type {Message as WireMessage} from '@fluxer/schema/src/domains/message/Meimport {makeAutoObservable} from 'mobx';function byIdDescending(a: {id: string}, b: {id: string}): number {- return b.id > a.id ? 1 : a.id > b.id ? -1 : 0;+ if (b.id > a.id) return 1;+ if (a.id > b.id) return -1;+ return 0;}class SavedMessages {@@ -136,22 +138,6 @@ class SavedMessages {...this.savedMessages.slice(index + 1),];}-- handleMessageReactionAdd(messageId: string): void {- this.touchMessage(messageId);- }-- handleMessageReactionRemove(messageId: string): void {- this.touchMessage(messageId);- }-- handleMessageReactionRemoveAll(messageId: string): void {- this.touchMessage(messageId);- }-- handleMessageReactionRemoveEmoji(messageId: string): void {- this.touchMessage(messageId);- }}const savedMessages = new SavedMessages();diff --git a/fluxer_app/src/features/messaging/utils/AutocompleteOptionBuilders.ts b/fluxer_app/src/features/messaging/utils/AutocompleteOptionBuilders.tsindex 379dda449..c6476615c 100644--- a/fluxer_app/src/features/messaging/utils/AutocompleteOptionBuilders.ts+++ b/fluxer_app/src/features/messaging/utils/AutocompleteOptionBuilders.ts@@ -328,8 +328,10 @@ function buildEmojiAutocompleteEmojiOptions() {return emojiAutocompleteOptionsCache.options;}- const allEmojis =- showDefaultEmojis || showCustomEmojis ? (hasQuery ? Emoji.search(channel, query, 10) : allUnfilteredEmojis) : [];+ let allEmojis: typeof allUnfilteredEmojis = [];+ if (showDefaultEmojis || showCustomEmojis) {+ allEmojis = hasQuery ? Emoji.search(channel, query, 10) : allUnfilteredEmojis;+ }const permissionFiltered = filterEmojisForAutocomplete(ctx.i18n, allEmojis, channel);const filteredEmojis = permissionFiltered.filter((emoji) => {const isCustom = !!emoji.guildId;@@ -365,11 +367,10 @@ export function buildEmojiAutocompleteOptions(ctx: EmojiAutocompleteContext): Ar? Sticker.searchWithChannel(ctx.channel, hasQuery ? query : '').slice(0, hasQuery ? 5 : undefined): [];const filteredStickers = filterStickersForAutocomplete(ctx.i18n, allStickers, ctx.channel);- const stickerResults = hasQuery- ? filteredStickers- : showStickers- ? StickerPicker.getFrecentStickers(filteredStickers, 3)- : [];+ let stickerResults = filteredStickers;+ if (!hasQuery) {+ stickerResults = showStickers ? StickerPicker.getFrecentStickers(filteredStickers, 3) : [];+ }const stickerOptions: Array<AutocompleteOption> = stickerResults.map((sticker) => ({type: 'sticker' as const,sticker,diff --git a/fluxer_app/src/features/moderation/components/modals/BanMemberModal.tsx b/fluxer_app/src/features/moderation/components/modals/BanMemberModal.tsxindex 2ed4cf709..97529ff26 100644--- a/fluxer_app/src/features/moderation/components/modals/BanMemberModal.tsx+++ b/fluxer_app/src/features/moderation/components/modals/BanMemberModal.tsx@@ -171,7 +171,8 @@ export const BanMemberModal: React.FC<{guildId: string; targetUser: User}> = obs<source src={BANNED_WEBM} type="video/webm" data-flx="moderation.ban-member-modal.source.video-webm" /><source src={BANNED_MP4} type="video/mp4" data-flx="moderation.ban-member-modal.source.video-mp4" /></video>- ) : showArtwork ? (+ ) : null}+ {!motionArtworkAllowed && showArtwork ? (<imgsrc={BANNED_POSTER}alt=""diff --git a/fluxer_app/src/features/moderation/components/report/ReportStepDetails.tsx b/fluxer_app/src/features/moderation/components/report/ReportStepDetails.tsxindex 26f08af03..fe8fb362f 100644--- a/fluxer_app/src/features/moderation/components/report/ReportStepDetails.tsx+++ b/fluxer_app/src/features/moderation/components/report/ReportStepDetails.tsx@@ -229,7 +229,7 @@ export const ReportStepDetails: React.FC<Props> = ({autoComplete="off"error={fieldErrors.messageLink}footer={- !formValues.messageLink.trim() ? undefined : !messageLinkOk ? (+ formValues.messageLink.trim() && !messageLinkOk ? (<span className={styles.helperText} data-flx="moderation.report.report-step-details.helper-text"><Trans>That doesn't look like a valid URL.</Trans></span>diff --git a/fluxer_app/src/features/moderation/components/report/ReportStepEmail.tsx b/fluxer_app/src/features/moderation/components/report/ReportStepEmail.tsxindex b837dc07f..a95e8aa56 100644--- a/fluxer_app/src/features/moderation/components/report/ReportStepEmail.tsx+++ b/fluxer_app/src/features/moderation/components/report/ReportStepEmail.tsx@@ -39,6 +39,20 @@ export const ReportStepEmail: React.FC<Props> = ({const {i18n} = useLingui();const normalizedEmail = email.trim();const emailLooksValid = normalizedEmail.length > 0 && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(normalizedEmail);+ const emailLabel = i18n._(EMAIL_ADDRESS_DESCRIPTOR);+ let submitLabel: React.ReactNode;+ if (verified) {+ submitLabel = i18n._(CONTINUE_DESCRIPTOR);+ } else if (resendCooldownSeconds > 0) {+ submitLabel = (+ <ResendCooldownLabel+ resendCooldownSeconds={resendCooldownSeconds}+ data-flx="moderation.report.report-step-email.resend-cooldown-label"+ />+ );+ } else {+ submitLabel = <Trans>Send verification code</Trans>;+ }return (<div className={styles.card} data-flx="moderation.report.report-step-email.card"><header className={styles.cardHeader} data-flx="moderation.report.report-step-email.card-header">@@ -46,7 +60,7 @@ export const ReportStepEmail: React.FC<Props> = ({<Trans>Step 2</Trans></p><h1 className={styles.title} data-flx="moderation.report.report-step-email.title">- <Trans>Verify your email</Trans>+ <Trans>Confirm your email</Trans></h1><p className={styles.description} data-flx="moderation.report.report-step-email.description"><Trans>We'll send a short code to confirm you can receive updates about this report.</Trans>@@ -72,7 +86,7 @@ export const ReportStepEmail: React.FC<Props> = ({data-flx="moderation.report.report-step-email.form.prevent-default"><Input- label={i18n._(EMAIL_ADDRESS_DESCRIPTOR)}+ label={emailLabel}type="email"dir="ltr"value={email}@@ -90,16 +104,7 @@ export const ReportStepEmail: React.FC<Props> = ({className={styles.actionButton}data-flx="moderation.report.report-step-email.action-button.submit">- {verified ? (- i18n._(CONTINUE_DESCRIPTOR)- ) : resendCooldownSeconds > 0 ? (- <ResendCooldownLabel- resendCooldownSeconds={resendCooldownSeconds}- data-flx="moderation.report.report-step-email.resend-cooldown-label"- />- ) : (- <Trans>Send verification code</Trans>- )}+ {submitLabel}</Button><Buttonvariant="secondary"diff --git a/fluxer_app/src/features/moderation/components/report_flow/ReportFlowThankYou.tsx b/fluxer_app/src/features/moderation/components/report_flow/ReportFlowThankYou.tsxindex bf2f74142..ead7135c6 100644--- a/fluxer_app/src/features/moderation/components/report_flow/ReportFlowThankYou.tsx+++ b/fluxer_app/src/features/moderation/components/report_flow/ReportFlowThankYou.tsx@@ -34,14 +34,18 @@ export const ReportFlowThankYou: React.FC<ReportFlowThankYouProps> = observer(const {i18n} = useLingui();const isBlocked = blockTarget !== null && Relationships.isBlocked(blockTarget.id);const blockTargetName = blockTarget !== null ? NicknameUtils.getNickname(blockTarget, guildId, channelId) : '';+ let body: string;+ if (reportSent) {+ body = i18n._(THANK_YOU_BODY_DESCRIPTOR, {productName});+ } else if (endedOnStart) {+ body = i18n._(THANK_YOU_NO_REPORT_BODY_DESCRIPTOR);+ } else {+ body = i18n._(THANK_YOU_NO_REPORT_SHORT_BODY_DESCRIPTOR);+ }return (<div className={styles.container} data-flx="moderation.report-flow.report-flow-thank-you.container"><p className={styles.body} data-flx="moderation.report-flow.report-flow-thank-you.body">- {reportSent- ? i18n._(THANK_YOU_BODY_DESCRIPTOR, {productName})- : endedOnStart- ? i18n._(THANK_YOU_NO_REPORT_BODY_DESCRIPTOR)- : i18n._(THANK_YOU_NO_REPORT_SHORT_BODY_DESCRIPTOR)}+ {body}</p>{blockTarget !== null && (<section className={styles.section} data-flx="moderation.report-flow.report-flow-thank-you.section">diff --git a/fluxer_app/src/features/permissions/system/components/useMacPermissionControl.ts b/fluxer_app/src/features/permissions/system/components/useMacPermissionControl.tsindex 7eb4bc45d..3c230fb77 100644--- a/fluxer_app/src/features/permissions/system/components/useMacPermissionControl.ts+++ b/fluxer_app/src/features/permissions/system/components/useMacPermissionControl.ts@@ -94,13 +94,13 @@ export function useMacPermissionControl(kind: MacPermissionKind): MacPermissionCsetBusy(true);void action(kind).finally(() => setBusy(false));}, [kind, status]);+ let actionDescriptor: MessageDescriptor | null = null;+ if (needsAction) {+ actionDescriptor = status === 'not-determined' ? ALLOW_DESCRIPTOR : OPEN_SYSTEM_SETTINGS_DESCRIPTOR;+ }return {status,- actionDescriptor: needsAction- ? status === 'not-determined'- ? ALLOW_DESCRIPTOR- : OPEN_SYSTEM_SETTINGS_DESCRIPTOR- : null,+ actionDescriptor,busy,relaunchMayHelp: relaunchMayHelp(kind, status),quitPromptAdvice: MacPermissions.showsQuitPromptAdvice(kind),