A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.
fix(app): keep the home button when DMs are off
Hampus2deaa8ef76e1
diff --git a/fluxer_app/src/features/app/components/layout/DiscoveryLayout.tsx b/fluxer_app/src/features/app/components/layout/DiscoveryLayout.tsxindex 1f4bf1e27..e7eb65aa2 100644--- a/fluxer_app/src/features/app/components/layout/DiscoveryLayout.tsx+++ b/fluxer_app/src/features/app/components/layout/DiscoveryLayout.tsx@@ -1,6 +1,5 @@// SPDX-License-Identifier: AGPL-3.0-or-later-import {Routes} from '@app/app/Routes';import {DiscoveryGuildHeader} from '@app/features/app/components/layout/DiscoveryGuildHeader';import styles from '@app/features/app/components/layout/GuildLayout.module.css';import {GuildSidebar} from '@app/features/app/components/layout/GuildSidebar';@@ -8,6 +7,7 @@ import RuntimeConfig from '@app/features/app/state/RuntimeConfig';import {DiscoveryPage} from '@app/features/discovery/discovery/DiscoveryPage';import {DiscoverySidebar} from '@app/features/discovery/discovery/DiscoverySidebar';import Discovery from '@app/features/discovery/state/Discovery';+import {getDefaultLandingPath} from '@app/features/navigation/utils/DefaultLandingUtils';import * as RouterUtils from '@app/features/navigation/utils/RouterUtils';import MobileLayout from '@app/features/ui/state/MobileLayout';import {observer} from 'mobx-react-lite';@@ -18,7 +18,7 @@ export const DiscoveryLayout = observer(function DiscoveryLayout() {const available = RuntimeConfig.discoveryAvailable;useEffect(() => {if (!available) {- RouterUtils.replaceWith(Routes.ME);+ RouterUtils.replaceWith(getDefaultLandingPath());return;}void Discovery.loadCategories();diff --git a/fluxer_app/src/features/app/components/layout/MobileBottomNav.tsx b/fluxer_app/src/features/app/components/layout/MobileBottomNav.tsxindex f173bedec..501dd2af3 100644--- a/fluxer_app/src/features/app/components/layout/MobileBottomNav.tsx+++ b/fluxer_app/src/features/app/components/layout/MobileBottomNav.tsx@@ -4,12 +4,10 @@ import {Routes} from '@app/app/Routes';import styles from '@app/features/app/components/layout/MobileBottomNav.module.css';import {reportSkeletonVoiceConnected} from '@app/features/app/components/skeleton/SkeletonLayoutMemory';import {useSkeletonLayoutReport} from '@app/features/app/hooks/useSkeletonLayoutMemoryCapture';-import RuntimeConfig from '@app/features/app/state/RuntimeConfig';import Channels from '@app/features/channel/state/Channels';import {PRIMARY_NAVIGATION_LANDMARK_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';import * as NavigationCommands from '@app/features/navigation/commands/NavigationCommands';import Navigation from '@app/features/navigation/state/Navigation';-import {getDirectMessagesFallbackPath} from '@app/features/navigation/utils/DefaultLandingUtils';import * as RouterUtils from '@app/features/navigation/utils/RouterUtils';import {createNamedLoadableComponent} from '@app/features/platform/components/loadable/LoadableComponent';import {useLocation} from '@app/features/platform/components/router/RouterReact';@@ -71,8 +69,6 @@ export const MobileBottomNav = observer(({currentUser}: MobileBottomNavProps) =>const last = lastChannelRef.current;if (last?.channelId && (isNotificationsActive || isYouActive)) {NavigationCommands.selectChannel(last.guildId ?? undefined, last.channelId);- } else if (RuntimeConfig.directMessagesDisabled) {- RouterUtils.transitionTo(getDirectMessagesFallbackPath());} else {NavigationCommands.deselectGuild();}diff --git a/fluxer_app/src/features/app/components/layout/sidebar_nav/FluxerButton.tsx b/fluxer_app/src/features/app/components/layout/sidebar_nav/FluxerButton.tsxindex 2cc7312b3..bef319753 100644--- a/fluxer_app/src/features/app/components/layout/sidebar_nav/FluxerButton.tsx+++ b/fluxer_app/src/features/app/components/layout/sidebar_nav/FluxerButton.tsx@@ -9,7 +9,7 @@ import {useHover} from '@app/features/app/hooks/useHover';import {useMergeRefs} from '@app/features/app/hooks/useMergeRefs';import RuntimeConfig from '@app/features/app/state/RuntimeConfig';import Channels from '@app/features/channel/state/Channels';-import {DIRECT_MESSAGES_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';+import {DIRECT_MESSAGES_DESCRIPTOR, PERSONAL_NOTES_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors';import SelectedChannel from '@app/features/navigation/state/SelectedChannel';import * as RouterUtils from '@app/features/navigation/utils/RouterUtils';import {useLocation} from '@app/features/platform/components/router/RouterReact';@@ -43,6 +43,10 @@ const FRIEND_REQUESTS_DESCRIPTOR = msg({comment:'Sidebar Fluxer-home button tooltip showing how many incoming friend requests are pending. Count is interpolated.',});+const FRIENDS_DESCRIPTOR = msg({+ message: 'Friends',+ comment: 'Sidebar home button tooltip when the instance turns direct messages off but keeps friends.',+});export const FluxerButton = observer(() => {const {i18n} = useLingui();const [hoverRef, isHovering] = useHover();@@ -79,8 +83,12 @@ export const FluxerButton = observer(() => {});const displayedUnreadDmCount = inlineDmsCollapsed && showCollapsedUnreadDmsBadge ? unreadDmCount : 0;const displayedIncomingFriendRequestCount = showIncomingFriendRequestBadge ? incomingFriendRequestCount : 0;+ let homeDescriptor = DIRECT_MESSAGES_DESCRIPTOR;+ if (RuntimeConfig.directMessagesDisabled) {+ homeDescriptor = RuntimeConfig.friendsDisabled ? PERSONAL_NOTES_DESCRIPTOR : FRIENDS_DESCRIPTOR;+ }const directMessagesLabel = useMemo(() => {- const parts = [i18n._(DIRECT_MESSAGES_DESCRIPTOR)];+ const parts = [i18n._(homeDescriptor)];if (displayedUnreadDmCount > 0) {parts.push(i18n._(UNREAD_DMS_DESCRIPTOR, {displayedUnreadDmCount}));}@@ -88,12 +96,12 @@ export const FluxerButton = observer(() => {parts.push(i18n._(FRIEND_REQUESTS_DESCRIPTOR, {displayedIncomingFriendRequestCount}));}return parts.join(', ');- }, [displayedIncomingFriendRequestCount, displayedUnreadDmCount, i18n.locale]);+ }, [displayedIncomingFriendRequestCount, displayedUnreadDmCount, homeDescriptor, i18n.locale]);const handleSelect = () => {const isMobile = MobileLayout.isMobileLayout();const route = (() => {if (isMobile) return Routes.ME;- if (selectedChannel) return Routes.dmChannel(selectedChannel);+ if (selectedChannel && !RuntimeConfig.directMessagesDisabled) return Routes.dmChannel(selectedChannel);return Routes.ME;})();RouterUtils.transitionTo(route);@@ -110,14 +118,11 @@ export const FluxerButton = observer(() => {const shouldShowHoverState = isHovering || contextMenuOpen;const indicatorTarget = resolveGuildListIndicatorBarTarget({isSelected, showHoverState: shouldShowHoverState});const isActive = shouldShowHoverState || isSelected;- if (RuntimeConfig.directMessagesDisabled) {- return null;- }return (<Tooltipposition="right"size="large"- text={i18n._(DIRECT_MESSAGES_DESCRIPTOR)}+ text={i18n._(homeDescriptor)}data-flx="app.sidebar-nav.fluxer-button.tooltip"><FocusRingdiff --git a/fluxer_app/src/features/app/components/skeleton/AppSkeleton.tsx b/fluxer_app/src/features/app/components/skeleton/AppSkeleton.tsxindex 54a77351a..50834f1bb 100644--- a/fluxer_app/src/features/app/components/skeleton/AppSkeleton.tsx+++ b/fluxer_app/src/features/app/components/skeleton/AppSkeleton.tsx@@ -71,6 +71,8 @@ function renderSidebar(sidebar: SkeletonSidebarVariant, guildId: string | null)return (<DiscoverySidebarSkeleton data-flx="app.skeleton.app-skeleton.render-sidebar.discovery-sidebar-skeleton" />);+ case SkeletonSidebarVariant.NONE:+ return null;}}@@ -173,7 +175,8 @@ export const AppSkeleton = observer(({isExiting = false, onTransitionEnd, effect</flx-app-skeleton>);}- const showMobileSidebarInline = isMobile && showsMobileSidebar(pathname);+ const hasSidebar = shell.sidebar !== SkeletonSidebarVariant.NONE;+ const showMobileSidebarInline = isMobile && hasSidebar && showsMobileSidebar(pathname);const showRail = !isMobile || showsMobileGuildRail(pathname);const reserveMobileBottomNav = isMobile && reservesMobileBottomNavSpace(pathname);const showUserArea = !isMobile && !isVoiceCallFullscreenActive;@@ -227,7 +230,7 @@ export const AppSkeleton = observer(({isExiting = false, onTransitionEnd, effectdata-flx="app.skeleton.app-skeleton.outline-frame"><flx-app-skeleton-main- className={flxElementClassName(styles.main, isMobile && styles.mainSidebarless)}+ className={flxElementClassName(styles.main, (isMobile || !hasSidebar) && styles.mainSidebarless)}data-flx="app.skeleton.app-skeleton.main">{!isMobile && renderSidebar(shell.sidebar, guildId)}diff --git a/fluxer_app/src/features/app/components/skeleton/ResolveSkeletonShell.ts b/fluxer_app/src/features/app/components/skeleton/ResolveSkeletonShell.tsindex cb55011b7..9d7a2506e 100644--- a/fluxer_app/src/features/app/components/skeleton/ResolveSkeletonShell.ts+++ b/fluxer_app/src/features/app/components/skeleton/ResolveSkeletonShell.ts@@ -2,11 +2,16 @@import {Routes} from '@app/app/Routes';import {SkeletonSimplePageRoute} from '@app/features/app/components/skeleton/SkeletonLayoutMemory';+import {+ skeletonDirectMessagesDisabled,+ skeletonFriendsDisabled,+} from '@app/features/app/components/skeleton/SkeletonRuntimeConfig';export const SkeletonSidebarVariant = Object.freeze({DM: 'dm',GUILD: 'guild',DISCOVERY: 'discovery',+ NONE: 'none',} as const);export type SkeletonSidebarVariant = (typeof SkeletonSidebarVariant)[keyof typeof SkeletonSidebarVariant];@@ -29,9 +34,17 @@ function isGuildRootPath(pathname: string): boolean {return pathname.split('/').length === GUILD_ROOT_PATH_SEGMENT_COUNT;}+function resolveHomeSidebar(): SkeletonSidebarVariant {+ return skeletonDirectMessagesDisabled() ? SkeletonSidebarVariant.NONE : SkeletonSidebarVariant.DM;+}++function resolveHomeContent(): SkeletonContent {+ return skeletonFriendsDisabled() ? {kind: 'empty'} : {kind: 'friends'};+}+function resolveDirectMessageContent(pathname: string): SkeletonContent {if (pathname === Routes.ME) {- return {kind: 'friends'};+ return resolveHomeContent();}return {kind: 'chat'};}@@ -89,21 +102,21 @@ export function resolveSkeletonShell(pathname: string): SkeletonShell {if (pathname === Routes.BOOKMARKS) {return {chrome: 'guilds',- sidebar: SkeletonSidebarVariant.DM,+ sidebar: resolveHomeSidebar(),content: {kind: 'page', route: SkeletonSimplePageRoute.BOOKMARKS},};}if (pathname === Routes.MENTIONS) {return {chrome: 'guilds',- sidebar: SkeletonSidebarVariant.DM,+ sidebar: resolveHomeSidebar(),content: {kind: 'page', route: SkeletonSimplePageRoute.MENTIONS},};}if (Routes.isDMRoute(pathname)) {return {chrome: 'guilds',- sidebar: SkeletonSidebarVariant.DM,+ sidebar: resolveHomeSidebar(),content: resolveDirectMessageContent(pathname),};}@@ -121,5 +134,5 @@ export function resolveSkeletonShell(pathname: string): SkeletonShell {content: resolveGuildContent(pathname),};}- return {chrome: 'guilds', sidebar: SkeletonSidebarVariant.DM, content: {kind: 'friends'}};+ return {chrome: 'guilds', sidebar: resolveHomeSidebar(), content: resolveHomeContent()};}diff --git a/fluxer_app/src/features/app/components/skeleton/SkeletonRuntimeConfig.ts b/fluxer_app/src/features/app/components/skeleton/SkeletonRuntimeConfig.tsindex aa3370af0..41a0dc1eb 100644--- a/fluxer_app/src/features/app/components/skeleton/SkeletonRuntimeConfig.ts+++ b/fluxer_app/src/features/app/components/skeleton/SkeletonRuntimeConfig.ts@@ -17,6 +17,11 @@ export function skeletonDirectMessagesDisabled(): boolean {return RuntimeConfig.getSnapshotOrNull()?.community.direct_messages_disabled ?? false;}+export function skeletonFriendsDisabled(): boolean {+ const community = RuntimeConfig.getSnapshotOrNull()?.community;+ return community?.friends_disabled ?? community?.direct_messages_disabled ?? false;+}+export function skeletonGifEnabled(): boolean {return RuntimeConfig.getSnapshotOrNull()?.services.gif_enabled ?? true;}diff --git a/fluxer_app/src/features/navigation/utils/DefaultLandingUtils.ts b/fluxer_app/src/features/navigation/utils/DefaultLandingUtils.tsindex 6eb434089..f20e801ec 100644--- a/fluxer_app/src/features/navigation/utils/DefaultLandingUtils.ts+++ b/fluxer_app/src/features/navigation/utils/DefaultLandingUtils.ts@@ -3,6 +3,7 @@import {Routes} from '@app/app/Routes';import Accessibility from '@app/features/accessibility/state/Accessibility';import RuntimeConfig from '@app/features/app/state/RuntimeConfig';+import GatewaySessions from '@app/features/gateway/transport/GatewaySessionPool';import GuildListState from '@app/features/guild/state/GuildList';function getFirstAvailableGuildId(): string | null {@@ -15,18 +16,25 @@ function getFirstAvailableGuildId(): string | null {return null;}-export function getDirectMessagesFallbackPath(): string {+function getHomeFallbackPath(): string | null {const firstGuildId = getFirstAvailableGuildId();if (firstGuildId) {return Routes.guildChannel(firstGuildId);}+ if (!GatewaySessions.foregroundConnection.isReady) {+ return null;+ }if (Accessibility.showFavorites) {return Routes.FAVORITES;}if (RuntimeConfig.discoveryAvailable) {return Routes.DISCOVER;}- return Routes.ME;+ return null;+}++function getDirectMessagesFallbackPath(): string {+ return getHomeFallbackPath() ?? Routes.ME;}export function getDefaultLandingPath(): string {diff --git a/fluxer_app/src/features/platform/utils/DesktopJumpListBridge.ts b/fluxer_app/src/features/platform/utils/DesktopJumpListBridge.tsindex d53bde1a1..dca84f363 100644--- a/fluxer_app/src/features/platform/utils/DesktopJumpListBridge.ts+++ b/fluxer_app/src/features/platform/utils/DesktopJumpListBridge.ts@@ -1,16 +1,27 @@// SPDX-License-Identifier: AGPL-3.0-or-later+import RuntimeConfig from '@app/features/app/state/RuntimeConfig';import Authentication from '@app/features/auth/state/Authentication';import {CreateDMModal} from '@app/features/channel/components/modals/CreateDMModal';import * as ModalCommands from '@app/features/ui/commands/ModalCommands';import {getElectronAPI} from '@app/features/ui/utils/NativeUtils';+import {reaction} from 'mobx';import React from 'react';-export function startDesktopJumpListBridge(): void {+export function startDesktopJumpListBridge(): (() => void) | undefined {const electronApi = getElectronAPI();if (!electronApi || typeof electronApi.onJumpListNewDm !== 'function') return;- electronApi.onJumpListNewDm(() => {- if (!Authentication.isAuthenticated) return;+ const disposeAvailability = reaction(+ () => !Authentication.isAuthenticated || RuntimeConfig.dmPickerAvailable,+ (available) => electronApi.setDirectMessagesAvailable?.(available),+ {fireImmediately: true, name: 'DesktopJumpListBridge-directMessages'},+ );+ const disposeTask = electronApi.onJumpListNewDm(() => {+ if (!Authentication.isAuthenticated || !RuntimeConfig.dmPickerAvailable) return;ModalCommands.push(ModalCommands.modal(() => React.createElement(CreateDMModal)));});+ return () => {+ disposeAvailability();+ disposeTask();+ };}