refactor progress

This commit is contained in:
Hampus Kraft
2026-02-17 12:22:36 +00:00
parent cb31608523
commit d5abd1a7e4
8257 changed files with 1190207 additions and 761040 deletions

View File

@@ -17,64 +17,55 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import '@app/components/modals/SudoVerificationModal';
import 'highlight.js/styles/github-dark.css';
import 'katex/dist/katex.min.css';
import styles from '@app/App.module.css';
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import * as WindowActionCreators from '@app/actions/WindowActionCreators';
import Config from '@app/Config';
import {DndContext} from '@app/components/layout/DndContext';
import GlobalOverlays from '@app/components/layout/GlobalOverlays';
import {NativeTitlebar} from '@app/components/layout/NativeTitlebar';
import {NativeTrafficLightsBackdrop} from '@app/components/layout/NativeTrafficLightsBackdrop';
import {UserSettingsModal} from '@app/components/modals/UserSettingsModal';
import {QUICK_SWITCHER_PORTAL_ID} from '@app/components/quick_switcher/QuickSwitcherConstants';
import FocusRingScope from '@app/components/uikit/focus_ring/FocusRingScope';
import {SVGMasks} from '@app/components/uikit/SVGMasks';
import {IncomingCallManager} from '@app/components/voice/IncomingCallManager';
import {type LayoutVariant, LayoutVariantProvider} from '@app/contexts/LayoutVariantContext';
import {showMyselfTypingHelper} from '@app/devtools/ShowMyselfTypingHelper';
import {useActivityRecorder} from '@app/hooks/useActivityRecorder';
import {useElectronScreenSharePicker} from '@app/hooks/useElectronScreenSharePicker';
import {useNativePlatform} from '@app/hooks/useNativePlatform';
import {useTextInputContextMenu} from '@app/hooks/useTextInputContextMenu';
import CaptchaInterceptorStore from '@app/lib/CaptchaInterceptor';
import FocusManager from '@app/lib/FocusManager';
import KeybindManager from '@app/lib/KeybindManager';
import {Logger} from '@app/lib/Logger';
import {startReadStateCleanup} from '@app/lib/ReadStateCleanup';
import {Outlet, RouterProvider} from '@app/lib/router/React';
import {router} from '@app/Router';
import AccessibilityStore, {HdrDisplayMode} from '@app/stores/AccessibilityStore';
import ModalStore from '@app/stores/ModalStore';
import PopoutStore from '@app/stores/PopoutStore';
import ReadStateStore from '@app/stores/ReadStateStore';
import RuntimeCrashStore from '@app/stores/RuntimeCrashStore';
import ThemeStore from '@app/stores/ThemeStore';
import UserStore from '@app/stores/UserStore';
import MediaEngineStore from '@app/stores/voice/MediaEngineFacade';
import {ensureAutostartDefaultEnabled} from '@app/utils/AutostartUtils';
import {startDeepLinkHandling} from '@app/utils/DeepLinkUtils';
import {attachExternalLinkInterceptor, getElectronAPI, getNativePlatform} from '@app/utils/NativeUtils';
import {i18n} from '@lingui/core';
import {I18nProvider} from '@lingui/react';
import {RoomAudioRenderer, RoomContext} from '@livekit/components-react';
import {IconContext} from '@phosphor-icons/react';
import * as Sentry from '@sentry/react';
import {observer} from 'mobx-react-lite';
import React, {type ReactNode} from 'react';
import React, {type ReactNode, useCallback, useEffect, useMemo, useRef, useState} from 'react';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import * as WindowActionCreators from '~/actions/WindowActionCreators';
import {DndContext} from '~/components/layout/DndContext';
import GlobalOverlays from '~/components/layout/GlobalOverlays';
import {NativeTitlebar} from '~/components/layout/NativeTitlebar';
import {NativeTrafficLightsBackdrop} from '~/components/layout/NativeTrafficLightsBackdrop';
import {UserSettingsModal} from '~/components/modals/UserSettingsModal';
import '~/components/modals/SudoVerificationModal';
import {QUICK_SWITCHER_PORTAL_ID} from '~/components/quick-switcher/QuickSwitcherConstants';
import FocusRingScope from '~/components/uikit/FocusRing/FocusRingScope';
import {SVGMasks} from '~/components/uikit/SVGMasks';
import {IncomingCallManager} from '~/components/voice/IncomingCallManager';
import {type LayoutVariant, LayoutVariantProvider} from '~/contexts/LayoutVariantContext';
import {showMyselfTypingHelper} from '~/devtools/ShowMyselfTypingHelper';
import {useActivityRecorder} from '~/hooks/useActivityRecorder';
import {useElectronScreenSharePicker} from '~/hooks/useElectronScreenSharePicker';
import {useNativePlatform} from '~/hooks/useNativePlatform';
import {useTextInputContextMenu} from '~/hooks/useTextInputContextMenu';
import CaptchaInterceptorStore from '~/lib/CaptchaInterceptor';
import FocusManager from '~/lib/FocusManager';
import KeybindManager from '~/lib/KeybindManager';
import {startReadStateCleanup} from '~/lib/ReadStateCleanup';
import {Outlet, RouterProvider} from '~/lib/router';
import {router} from '~/router';
import AccessibilityStore from '~/stores/AccessibilityStore';
import ConnectionStore from '~/stores/ConnectionStore';
import ModalStore from '~/stores/ModalStore';
import PopoutStore from '~/stores/PopoutStore';
import ReadStateStore from '~/stores/ReadStateStore';
import UserSettingsStore from '~/stores/UserSettingsStore';
import UserStore from '~/stores/UserStore';
import MediaEngineStore from '~/stores/voice/MediaEngineFacade';
import {ensureAutostartDefaultEnabled} from '~/utils/AutostartUtils';
import {startDeepLinkHandling} from '~/utils/DeepLinkUtils';
import {attachExternalLinkInterceptor, getElectronAPI, getNativePlatform} from '~/utils/NativeUtils';
import styles from './App.module.css';
import Config from './Config';
const logger = new Logger('App');
interface AppWrapperProps {
children: ReactNode;
@@ -88,13 +79,13 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
const messageGutter = AccessibilityStore.messageGutter;
const messageGroupSpacing = AccessibilityStore.messageGroupSpacingValue;
const reducedMotion = AccessibilityStore.useReducedMotion;
const hdrDisplayMode = AccessibilityStore.hdrDisplayMode;
const {platform, isNative, isMacOS} = useNativePlatform();
useElectronScreenSharePicker();
const syncThemeAcrossDevices = AccessibilityStore.syncThemeAcrossDevices;
const localThemeOverride = AccessibilityStore.localThemeOverride;
const customThemeCss = AccessibilityStore.customThemeCss;
const [layoutVariant, setLayoutVariant] = React.useState<LayoutVariant>('app');
const layoutVariantContextValue = React.useMemo(
const effectiveTheme = ThemeStore.effectiveTheme;
const [layoutVariant, setLayoutVariant] = useState<LayoutVariant>('app');
const layoutVariantContextValue = useMemo(
() => ({variant: layoutVariant, setVariant: setLayoutVariant}),
[layoutVariant],
);
@@ -103,24 +94,19 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
const topPopout = popouts.length ? popouts[popouts.length - 1] : null;
const topPopoutRequiresBackdrop = Boolean(topPopout && !topPopout.disableBackdrop);
const userSettings = UserSettingsStore;
const room = MediaEngineStore.room;
const ringsContainerRef = React.useRef<HTMLDivElement>(null);
const overlayScopeRef = React.useRef<HTMLDivElement>(null);
const ringsContainerRef = useRef<HTMLDivElement>(null);
const overlayScopeRef = useRef<HTMLDivElement>(null);
const recordActivity = useActivityRecorder();
const handleUserActivity = React.useCallback(() => recordActivity(), [recordActivity]);
const handleImmediateActivity = React.useCallback(() => recordActivity(true), [recordActivity]);
const handleResize = React.useCallback(() => WindowActionCreators.resized(), []);
const handleUserActivity = useCallback(() => recordActivity(), [recordActivity]);
const handleImmediateActivity = useCallback(() => recordActivity(true), [recordActivity]);
const handleResize = useCallback(() => WindowActionCreators.resized(), []);
useTextInputContextMenu();
const effectiveTheme = React.useMemo(() => {
return UserSettingsStore.getTheme();
}, [userSettings.theme, syncThemeAcrossDevices, localThemeOverride]);
const hasBlockingModal = ModalStore.hasModalOpen();
React.useEffect(() => {
useEffect(() => {
const node = ringsContainerRef.current;
if (!node) return;
@@ -133,16 +119,16 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
};
}, [hasBlockingModal, topPopoutRequiresBackdrop]);
React.useEffect(() => {
useEffect(() => {
showMyselfTypingHelper.start();
return () => showMyselfTypingHelper.stop();
}, []);
React.useEffect(() => {
useEffect(() => {
startReadStateCleanup();
}, []);
React.useEffect(() => {
useEffect(() => {
if (!('serviceWorker' in navigator)) {
return;
}
@@ -155,7 +141,7 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
try {
controller.postMessage({type: 'APP_UPDATE_BADGE', count});
} catch (error) {
console.warn('[Badge] Failed to post badge update to service worker', error);
logger.warn('Failed to post badge update to service worker', error);
}
};
@@ -174,7 +160,7 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
};
}, []);
React.useEffect(() => {
useEffect(() => {
void KeybindManager.init(i18n);
void CaptchaInterceptorStore;
return () => {
@@ -182,7 +168,7 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
};
}, []);
React.useEffect(() => {
useEffect(() => {
void AccessibilityStore.applyStoredZoom();
const electronApi = getElectronAPI();
@@ -203,7 +189,7 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
};
}, []);
React.useEffect(() => {
useEffect(() => {
const root = document.documentElement;
root.classList.toggle('reduced-motion', reducedMotion);
return () => {
@@ -211,12 +197,12 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
};
}, [reducedMotion]);
React.useEffect(() => {
useEffect(() => {
if (Config.PUBLIC_BUILD_SHA && Config.PUBLIC_BUILD_TIMESTAMP) {
const buildInfo = Config.PUBLIC_BUILD_NUMBER
? `build ${Config.PUBLIC_BUILD_NUMBER} (${Config.PUBLIC_BUILD_SHA})`
: Config.PUBLIC_BUILD_SHA;
console.info(`[BUILD INFO] ${Config.PUBLIC_PROJECT_ENV} - ${buildInfo} - ${Config.PUBLIC_BUILD_TIMESTAMP}`);
logger.info(`[BUILD INFO] ${Config.PUBLIC_RELEASE_CHANNEL} - ${buildInfo} - ${Config.PUBLIC_BUILD_TIMESTAMP}`);
}
FocusManager.init();
@@ -228,13 +214,13 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
const preventScroll = (event: Event) => event.preventDefault();
const handleBlur = () => {
WindowActionCreators.focus(false);
WindowActionCreators.focused(false);
if (shouldRegisterWindowListeners) {
document.documentElement.classList.remove('window-focused');
}
};
const handleFocus = () => {
WindowActionCreators.focus(true);
WindowActionCreators.focused(true);
if (shouldRegisterWindowListeners) {
document.documentElement.classList.add('window-focused');
}
@@ -256,7 +242,6 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
window.addEventListener('focus', handleFocus);
document.addEventListener('visibilitychange', handleVisibilityChange);
window.addEventListener('mousedown', handleImmediateActivity);
window.addEventListener('mousemove', handleUserActivity);
window.addEventListener('keydown', handleUserActivity);
window.addEventListener('resize', handleResize);
window.addEventListener('touchstart', handleImmediateActivity);
@@ -272,7 +257,6 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
window.removeEventListener('focus', handleFocus);
document.removeEventListener('visibilitychange', handleVisibilityChange);
window.removeEventListener('mousedown', handleImmediateActivity);
window.removeEventListener('mousemove', handleUserActivity);
window.removeEventListener('keydown', handleUserActivity);
window.removeEventListener('resize', handleResize);
window.removeEventListener('touchstart', handleImmediateActivity);
@@ -280,9 +264,9 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
document.removeEventListener('touchmove', preventPinchZoom);
}
};
}, [handleImmediateActivity, handleUserActivity, handleResize, isNative]);
}, [handleImmediateActivity, handleResize, isNative]);
React.useEffect(() => {
useEffect(() => {
if (!isNative) {
return;
}
@@ -292,12 +276,12 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
};
const handleFocus = () => {
updateClass(true);
WindowActionCreators.focus(true);
WindowActionCreators.focused(true);
handleImmediateActivity();
};
const handleBlur = () => {
updateClass(false);
WindowActionCreators.focus(false);
WindowActionCreators.focused(false);
};
const handleVisibilityChange = () => {
WindowActionCreators.visibilityChanged(!document.hidden);
@@ -312,7 +296,6 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
window.addEventListener('blur', handleBlur);
document.addEventListener('visibilitychange', handleVisibilityChange);
window.addEventListener('mousedown', handleImmediateActivity);
window.addEventListener('mousemove', handleUserActivity);
window.addEventListener('keydown', handleUserActivity);
window.addEventListener('resize', handleResize);
window.addEventListener('touchstart', handleImmediateActivity);
@@ -323,16 +306,15 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
window.removeEventListener('blur', handleBlur);
document.removeEventListener('visibilitychange', handleVisibilityChange);
window.removeEventListener('mousedown', handleImmediateActivity);
window.removeEventListener('mousemove', handleUserActivity);
window.removeEventListener('keydown', handleUserActivity);
window.removeEventListener('resize', handleResize);
window.removeEventListener('touchstart', handleImmediateActivity);
document.removeEventListener('touchstart', preventPinchZoom);
document.removeEventListener('touchmove', preventPinchZoom);
};
}, [handleImmediateActivity, handleResize, handleUserActivity, isNative]);
}, [handleImmediateActivity, handleResize, isNative]);
React.useEffect(() => {
useEffect(() => {
const htmlNode = document.documentElement;
const platformClasses = [isNative ? 'platform-native' : 'platform-web', `platform-${platform}`];
@@ -343,48 +325,7 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
};
}, [isNative, platform]);
React.useEffect(() => {
if (isNative) {
return;
}
const handlePageUnload = () => {
const guildId = MediaEngineStore.guildId;
const connected = MediaEngineStore.connected;
const room = MediaEngineStore.room;
const socket = ConnectionStore.socket;
if (socket && connected && guildId) {
try {
if (room) {
room.disconnect(true);
}
socket.updateVoiceState({
guild_id: guildId,
channel_id: null,
self_mute: true,
self_deaf: true,
self_video: false,
self_stream: false,
connection_id: MediaEngineStore.connectionId ?? null,
});
} catch (error) {
console.error('Failed to send disconnect on page unload:', error);
}
}
};
window.addEventListener('beforeunload', handlePageUnload);
window.addEventListener('pagehide', handlePageUnload);
return () => {
window.removeEventListener('beforeunload', handlePageUnload);
window.removeEventListener('pagehide', handlePageUnload);
};
}, [isNative]);
React.useEffect(() => {
useEffect(() => {
const htmlNode = document.documentElement;
htmlNode.classList.add(`theme-${effectiveTheme}`);
htmlNode.style.setProperty('--saturation-factor', saturationFactor.toString());
@@ -392,6 +333,7 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
htmlNode.style.setProperty('--font-size', `${fontSize}px`);
htmlNode.style.setProperty('--chat-horizontal-padding', `${messageGutter}px`);
htmlNode.style.setProperty('--message-group-spacing', `${messageGroupSpacing}px`);
htmlNode.style.setProperty('dynamic-range-limit', hdrDisplayMode === HdrDisplayMode.FULL ? 'high' : 'standard');
if (alwaysUnderlineLinks) {
htmlNode.style.setProperty('--link-decoration', 'underline');
@@ -407,6 +349,7 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
htmlNode.style.removeProperty('--font-size');
htmlNode.style.removeProperty('--chat-horizontal-padding');
htmlNode.style.removeProperty('--message-group-spacing');
htmlNode.style.removeProperty('dynamic-range-limit');
};
}, [
effectiveTheme,
@@ -416,9 +359,10 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
fontSize,
messageGutter,
messageGroupSpacing,
hdrDisplayMode,
]);
React.useEffect(() => {
useEffect(() => {
const styleElementId = 'fluxer-custom-theme-style';
const existing = document.getElementById(styleElementId) as HTMLStyleElement | null;
@@ -469,8 +413,13 @@ export const AppWrapper = observer(({children}: AppWrapperProps) => {
export const App = observer((): React.ReactElement => {
const currentUser = UserStore.currentUser;
const fatalError = RuntimeCrashStore.fatalError;
React.useEffect(() => {
if (fatalError) {
throw fatalError;
}
useEffect(() => {
const initAutostart = async () => {
const platform = await getNativePlatform();
if (platform === 'macos') {
@@ -481,16 +430,16 @@ export const App = observer((): React.ReactElement => {
void initAutostart();
}, []);
React.useEffect(() => {
useEffect(() => {
void startDeepLinkHandling();
}, []);
React.useEffect(() => {
useEffect(() => {
const detach = attachExternalLinkInterceptor();
return () => detach?.();
}, []);
React.useEffect(() => {
useEffect(() => {
if (currentUser) {
Sentry.setUser({
id: currentUser.id,

View File

@@ -0,0 +1,62 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {OAuth2Scope} from '@fluxer/constants/src/OAuth2Constants';
import {isStatusType, normalizeStatus, type StatusType, StatusTypes} from '@fluxer/constants/src/StatusConstants';
import type {I18n, MessageDescriptor} from '@lingui/core';
import {msg} from '@lingui/core/macro';
const OAuth2ScopeDescriptorsInternal: Record<OAuth2Scope, MessageDescriptor> = {
identify: msg`Access your basic profile information (username, avatar, etc.)`,
email: msg`View your email address`,
guilds: msg`View the communities you are a member of`,
connections: msg`View your connected accounts`,
bot: msg`Add a bot to a community with requested permissions`,
admin: msg`Access administrative endpoints`,
};
export function getOAuth2ScopeDescription(i18n: I18n, scope: OAuth2Scope): string {
return i18n._(OAuth2ScopeDescriptorsInternal[scope]);
}
const StatusTypeToLabelDescriptorsInternal: Record<StatusType, MessageDescriptor> = {
[StatusTypes.ONLINE]: msg`Online`,
[StatusTypes.DND]: msg`Do Not Disturb`,
[StatusTypes.IDLE]: msg`Idle`,
[StatusTypes.INVISIBLE]: msg`Invisible`,
[StatusTypes.OFFLINE]: msg`Offline`,
};
export function getStatusTypeLabel(i18n: I18n, statusType: StatusType | string): string {
const normalized = isStatusType(statusType) ? statusType : normalizeStatus(statusType);
return i18n._(StatusTypeToLabelDescriptorsInternal[normalized]);
}
const StatusTypeToDescriptionDescriptorsInternal: Record<StatusType, MessageDescriptor> = {
[StatusTypes.ONLINE]: msg`Charged up on 1.21 gigawatts, ready to talk`,
[StatusTypes.DND]: msg`In the zone, please do not disturb`,
[StatusTypes.IDLE]: msg`Took the DeLorean out, but I'll be back in time`,
[StatusTypes.INVISIBLE]: msg`Currently stuck in 1885, appearing offline`,
[StatusTypes.OFFLINE]: msg`Currently stuck in 1885, appearing offline`,
};
export function getStatusTypeDescription(i18n: I18n, statusType: StatusType | string): string {
const normalized = isStatusType(statusType) ? statusType : normalizeStatus(statusType);
return i18n._(StatusTypeToDescriptionDescriptorsInternal[normalized]);
}

View File

@@ -20,46 +20,34 @@
import * as v from 'valibot';
const envSchema = v.object({
PUBLIC_BUILD_SHA: v.optional(v.string(), 'dev'),
PUBLIC_BUILD_NUMBER: v.optional(v.pipe(v.string(), v.transform(Number), v.number()), '0'),
PUBLIC_BUILD_TIMESTAMP: v.optional(
PUBLIC_BUILD_SHA: v.nullish(v.string(), 'dev'),
PUBLIC_BUILD_NUMBER: v.nullish(v.pipe(v.string(), v.transform(Number), v.number()), '0'),
PUBLIC_BUILD_TIMESTAMP: v.nullish(
v.pipe(v.string(), v.transform(Number), v.number()),
`${Math.floor(Date.now() / 1000)}`,
),
PUBLIC_PROJECT_ENV: v.optional(v.picklist(['stable', 'canary', 'development']), 'development'),
PUBLIC_SENTRY_DSN: v.optional(v.nullable(v.string()), null),
PUBLIC_SENTRY_PROJECT_ID: v.optional(v.nullable(v.string()), null),
PUBLIC_SENTRY_PUBLIC_KEY: v.optional(v.nullable(v.string()), null),
PUBLIC_SENTRY_PROXY_PATH: v.optional(v.string(), '/error-reporting-proxy'),
PUBLIC_API_VERSION: v.optional(v.pipe(v.string(), v.transform(Number), v.number()), '1'),
PUBLIC_BOOTSTRAP_API_ENDPOINT: v.optional(v.string(), '/api'),
PUBLIC_BOOTSTRAP_API_PUBLIC_ENDPOINT: v.optional(v.string()),
PUBLIC_RELEASE_CHANNEL: v.nullish(v.picklist(['stable', 'canary', 'nightly']), 'nightly'),
PUBLIC_BOOTSTRAP_API_ENDPOINT: v.nullish(v.string(), '/api'),
PUBLIC_BOOTSTRAP_API_PUBLIC_ENDPOINT: v.nullish(v.string()),
PUBLIC_RELAY_DIRECTORY_URL: v.nullish(v.string()),
});
const env = v.parse(envSchema, {
PUBLIC_BUILD_SHA: import.meta.env.PUBLIC_BUILD_SHA,
PUBLIC_BUILD_NUMBER: import.meta.env.PUBLIC_BUILD_NUMBER,
PUBLIC_BUILD_TIMESTAMP: import.meta.env.PUBLIC_BUILD_TIMESTAMP,
PUBLIC_PROJECT_ENV: import.meta.env.PUBLIC_PROJECT_ENV,
PUBLIC_SENTRY_DSN: import.meta.env.PUBLIC_SENTRY_DSN,
PUBLIC_SENTRY_PROJECT_ID: import.meta.env.PUBLIC_SENTRY_PROJECT_ID,
PUBLIC_SENTRY_PUBLIC_KEY: import.meta.env.PUBLIC_SENTRY_PUBLIC_KEY,
PUBLIC_SENTRY_PROXY_PATH: import.meta.env.PUBLIC_SENTRY_PROXY_PATH,
PUBLIC_API_VERSION: import.meta.env.PUBLIC_API_VERSION,
PUBLIC_RELEASE_CHANNEL: import.meta.env.PUBLIC_RELEASE_CHANNEL,
PUBLIC_BOOTSTRAP_API_ENDPOINT: import.meta.env.PUBLIC_BOOTSTRAP_API_ENDPOINT,
PUBLIC_BOOTSTRAP_API_PUBLIC_ENDPOINT: import.meta.env.PUBLIC_BOOTSTRAP_API_PUBLIC_ENDPOINT,
PUBLIC_RELAY_DIRECTORY_URL: import.meta.env.PUBLIC_RELAY_DIRECTORY_URL,
});
export default {
PUBLIC_BUILD_SHA: env.PUBLIC_BUILD_SHA,
PUBLIC_BUILD_NUMBER: env.PUBLIC_BUILD_NUMBER,
PUBLIC_BUILD_TIMESTAMP: env.PUBLIC_BUILD_TIMESTAMP,
PUBLIC_PROJECT_ENV: env.PUBLIC_PROJECT_ENV,
PUBLIC_SENTRY_DSN: env.PUBLIC_SENTRY_DSN,
PUBLIC_SENTRY_PROJECT_ID: env.PUBLIC_SENTRY_PROJECT_ID,
PUBLIC_SENTRY_PUBLIC_KEY: env.PUBLIC_SENTRY_PUBLIC_KEY,
PUBLIC_SENTRY_PROXY_PATH: env.PUBLIC_SENTRY_PROXY_PATH,
PUBLIC_API_VERSION: env.PUBLIC_API_VERSION,
PUBLIC_RELEASE_CHANNEL: env.PUBLIC_RELEASE_CHANNEL,
PUBLIC_BOOTSTRAP_API_ENDPOINT: env.PUBLIC_BOOTSTRAP_API_ENDPOINT,
PUBLIC_BOOTSTRAP_API_PUBLIC_ENDPOINT: env.PUBLIC_BOOTSTRAP_API_PUBLIC_ENDPOINT ?? env.PUBLIC_BOOTSTRAP_API_ENDPOINT,
PUBLIC_RELAY_DIRECTORY_URL: env.PUBLIC_RELAY_DIRECTORY_URL ?? null,
};

View File

@@ -1,652 +0,0 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {I18n, MessageDescriptor} from '@lingui/core';
import {msg} from '@lingui/core/macro';
export const FLUXER_EPOCH = 1420070400000;
export const ME = '@me';
export const FAVORITES_GUILD_ID = '1337';
export const FLUXERBOT_ID = '0';
export const OAuth2Scopes = ['identify', 'email', 'guilds', 'bot', 'applications.commands'] as const;
export type OAuth2Scope = (typeof OAuth2Scopes)[number];
const OAuth2ScopeDescriptorsInternal: Record<OAuth2Scope, MessageDescriptor> = {
identify: msg`Access your basic profile information (username, avatar, etc.)`,
email: msg`View your email address`,
guilds: msg`View the communities you are a member of`,
bot: msg`Add a bot to a community with requested permissions`,
'applications.commands': msg`Manage slash commands for this application`,
};
export function getOAuth2ScopeDescription(i18n: I18n, scope: OAuth2Scope): string {
return i18n._(OAuth2ScopeDescriptorsInternal[scope]);
}
export const DEFAULT_ACCENT_COLOR = '#4641D9';
export const MAX_GUILDS_PREMIUM = 200;
export const MAX_GUILDS_NON_PREMIUM = 100;
export const MAX_GUILD_EMOJIS_ANIMATED = 50;
export const MAX_GUILD_EMOJIS_STATIC = 50;
export const MAX_GUILD_EMOJIS_ANIMATED_MORE_EMOJI = 250;
export const MAX_GUILD_EMOJIS_STATIC_MORE_EMOJI = 250;
export const MAX_GUILD_STICKERS = 50;
export const MAX_GUILD_STICKERS_MORE_STICKERS = 250;
export const MAX_GUILD_MEMBERS = 1000;
export const MAX_GUILD_MEMBERS_VERY_LARGE = 10000;
export const MAX_CHANNELS_PER_CATEGORY = 50;
export const MAX_MESSAGE_LENGTH_PREMIUM = 4000;
export const MAX_MESSAGE_LENGTH_NON_PREMIUM = 2000;
export const MAX_ATTACHMENTS_PER_MESSAGE = 10;
export const MAX_MESSAGES_PER_CHANNEL = 50;
export const MAX_LOADED_MESSAGES = MAX_MESSAGES_PER_CHANNEL * 4;
export const TRUNCATED_MESSAGE_VIEW_SIZE = MAX_LOADED_MESSAGES * 0.5;
export const MAX_MESSAGE_CACHE_SIZE = MAX_MESSAGES_PER_CHANNEL * 5;
export const NEW_MESSAGES_BAR_BUFFER = 32;
export const MAX_BOOKMARKS_PREMIUM = 300;
export const MAX_BOOKMARKS_NON_PREMIUM = 50;
export const MAX_FAVORITE_MEMES_PREMIUM = 500;
export const MAX_FAVORITE_MEMES_NON_PREMIUM = 50;
export const MAX_FAVORITE_MEME_TAGS = 10;
export const MAX_BIO_LENGTH_PREMIUM = 320;
export const MAX_BIO_LENGTH_NON_PREMIUM = 160;
export const EMOJI_MAX_SIZE = 384 * 1024;
export const SKIN_TONE_SURROGATES = ['🏻', '🏼', '🏽', '🏾', '🏿'];
export const STICKER_MAX_SIZE = 512 * 1024;
export const ATTACHMENT_MAX_SIZE_PREMIUM = 500 * 1024 * 1024;
export const ATTACHMENT_MAX_SIZE_NON_PREMIUM = 25 * 1024 * 1024;
export const API_CODE_VERSION = 1;
export const UserAuthenticatorTypes = {
TOTP: 0,
SMS: 1,
WEBAUTHN: 2,
} as const;
export const UserPremiumTypes = {
NONE: 0,
SUBSCRIPTION: 1,
LIFETIME: 2,
} as const;
export const UserFlags = {
STAFF: 1 << 0,
CTP_MEMBER: 1 << 1,
PARTNER: 1 << 2,
BUG_HUNTER: 1 << 3,
} as const;
export const StatusTypes = {
ONLINE: 'online',
DND: 'dnd',
IDLE: 'idle',
INVISIBLE: 'invisible',
OFFLINE: 'offline',
} as const;
export type StatusType = (typeof StatusTypes)[keyof typeof StatusTypes];
const STATUS_VALUES = Object.values(StatusTypes) as Array<StatusType>;
const STATUS_SET = new Set<StatusType>(STATUS_VALUES);
export const isStatusType = (value: unknown): value is StatusType =>
typeof value === 'string' && STATUS_SET.has(value as StatusType);
export const normalizeStatus = (value: unknown): StatusType => (isStatusType(value) ? value : StatusTypes.OFFLINE);
export const OFFLINE_STATUS_TYPES: Set<StatusType> = new Set([StatusTypes.OFFLINE, StatusTypes.INVISIBLE]);
export const isOfflineStatus = (
status: StatusType,
): status is typeof StatusTypes.OFFLINE | typeof StatusTypes.INVISIBLE =>
status === StatusTypes.OFFLINE || status === StatusTypes.INVISIBLE;
const StatusTypeToLabelDescriptorsInternal: Record<StatusType, MessageDescriptor> = {
[StatusTypes.ONLINE]: msg`Online`,
[StatusTypes.DND]: msg`Do Not Disturb`,
[StatusTypes.IDLE]: msg`Idle`,
[StatusTypes.INVISIBLE]: msg`Invisible`,
[StatusTypes.OFFLINE]: msg`Offline`,
};
export function getStatusTypeLabel(i18n: I18n, statusType: StatusType | string): string {
const normalized = isStatusType(statusType) ? statusType : normalizeStatus(statusType);
return i18n._(StatusTypeToLabelDescriptorsInternal[normalized]);
}
const StatusTypeToDescriptionDescriptorsInternal: Record<StatusType, MessageDescriptor> = {
[StatusTypes.ONLINE]: msg`Charged up on 1.21 gigawatts, ready to talk`,
[StatusTypes.DND]: msg`In the zone, please do not disturb`,
[StatusTypes.IDLE]: msg`Took the DeLorean out, but I'll be back in time`,
[StatusTypes.INVISIBLE]: msg`Currently stuck in 1885, appearing offline`,
[StatusTypes.OFFLINE]: msg`Currently stuck in 1885, appearing offline`,
};
export function getStatusTypeDescription(i18n: I18n, statusType: StatusType | string): string {
const normalized = isStatusType(statusType) ? statusType : normalizeStatus(statusType);
return i18n._(StatusTypeToDescriptionDescriptorsInternal[normalized]);
}
export const InviteTypes = {
GUILD: 0,
GROUP_DM: 1,
EMOJI_PACK: 2,
STICKER_PACK: 3,
} as const;
export const ThemeTypes = {
DARK: 'dark',
COAL: 'coal',
LIGHT: 'light',
SYSTEM: 'system',
} as const;
export const FeatureFlags = {
MESSAGE_SCHEDULING: 'message_scheduling',
EXPRESSION_PACKS: 'expression_packs',
} as const;
export type FeatureFlag = (typeof FeatureFlags)[keyof typeof FeatureFlags];
export const ALL_FEATURE_FLAGS: Array<FeatureFlag> = Object.values(FeatureFlags);
export const TimeFormatTypes = {
AUTO: 0,
TWELVE_HOUR: 1,
TWENTY_FOUR_HOUR: 2,
} as const;
export const StickerAnimationOptions = {
ALWAYS_ANIMATE: 0,
ANIMATE_ON_INTERACTION: 1,
NEVER_ANIMATE: 2,
} as const;
export const RenderSpoilers = {
ALWAYS: 0,
ON_CLICK: 1,
IF_MODERATOR: 2,
} as const;
export const GuildExplicitContentFilterTypes = {
DISABLED: 0,
MEMBERS_WITHOUT_ROLES: 1,
ALL_MEMBERS: 2,
} as const;
export const FriendSourceFlags = {
MUTUAL_FRIENDS: 1 << 0,
MUTUAL_GUILDS: 1 << 1,
NO_RELATION: 1 << 2,
} as const;
export const IncomingCallFlags = {
FRIENDS_OF_FRIENDS: 1 << 0,
GUILD_MEMBERS: 1 << 1,
EVERYONE: 1 << 2,
FRIENDS_ONLY: 1 << 3,
NOBODY: 1 << 4,
SILENT_EVERYONE: 1 << 5,
} as const;
export const GroupDmAddPermissionFlags = {
FRIENDS_OF_FRIENDS: 1 << 0,
GUILD_MEMBERS: 1 << 1,
EVERYONE: 1 << 2,
FRIENDS_ONLY: 1 << 3,
NOBODY: 1 << 4,
} as const;
export const MessageNotifications = {
NULL: -1,
ALL_MESSAGES: 0,
ONLY_MENTIONS: 1,
NO_MESSAGES: 2,
INHERIT: 3,
} as const;
export const RelationshipTypes = {
FRIEND: 1,
BLOCKED: 2,
INCOMING_REQUEST: 3,
OUTGOING_REQUEST: 4,
} as const;
export const GuildVerificationLevel = {
NONE: 0,
LOW: 1,
MEDIUM: 2,
HIGH: 3,
VERY_HIGH: 4,
} as const;
export const GuildMFALevel = {
NONE: 0,
ELEVATED: 1,
} as const;
export const GuildSplashCardAlignment = {
CENTER: 0,
LEFT: 1,
RIGHT: 2,
} as const;
export type GuildSplashCardAlignmentValue = (typeof GuildSplashCardAlignment)[keyof typeof GuildSplashCardAlignment];
export const SystemChannelFlags = {
SUPPRESS_JOIN_NOTIFICATIONS: 1 << 0,
} as const;
export const GuildOperations = {
PUSH_NOTIFICATIONS: 1 << 0,
EVERYONE_MENTIONS: 1 << 1,
TYPING_EVENTS: 1 << 2,
INSTANT_INVITES: 1 << 3,
SEND_MESSAGE: 1 << 4,
REACTIONS: 1 << 5,
} as const;
export const StickerFormatTypes = {
PNG: 1,
APNG: 2,
LOTTIE: 3,
GIF: 4,
} as const;
export const GuildMemberProfileFlags = {
AVATAR_UNSET: 1 << 0,
BANNER_UNSET: 1 << 1,
} as const;
export const ChannelTypes = {
GUILD_TEXT: 0,
DM: 1,
GUILD_VOICE: 2,
GROUP_DM: 3,
GUILD_CATEGORY: 4,
GUILD_LINK: 998,
DM_PERSONAL_NOTES: 999,
} as const;
export const TEXT_BASED_CHANNEL_TYPES = new Set<number>([
ChannelTypes.GUILD_TEXT,
ChannelTypes.DM,
ChannelTypes.DM_PERSONAL_NOTES,
ChannelTypes.GROUP_DM,
]);
export const QuickSwitcherResultTypes = {
HEADER: 'header',
USER: 'user',
GROUP_DM: 'group_dm',
TEXT_CHANNEL: 'text_channel',
VOICE_CHANNEL: 'voice_channel',
GUILD: 'guild',
VIRTUAL_GUILD: 'virtual_guild',
SETTINGS: 'settings',
QUICK_ACTION: 'quick_action',
LINK: 'link',
} as const;
export type QuickSwitcherResultType = (typeof QuickSwitcherResultTypes)[keyof typeof QuickSwitcherResultTypes];
export const MessageTypes = {
DEFAULT: 0,
RECIPIENT_ADD: 1,
RECIPIENT_REMOVE: 2,
CALL: 3,
CHANNEL_NAME_CHANGE: 4,
CHANNEL_ICON_CHANGE: 5,
CHANNEL_PINNED_MESSAGE: 6,
USER_JOIN: 7,
REPLY: 19,
CLIENT_SYSTEM: 99,
} as const;
export type MessageTypeValue = (typeof MessageTypes)[keyof typeof MessageTypes];
export const MESSAGE_TYPE_DELETABLE = {
[MessageTypes.DEFAULT]: true,
[MessageTypes.REPLY]: true,
[MessageTypes.CHANNEL_PINNED_MESSAGE]: true,
[MessageTypes.USER_JOIN]: true,
[MessageTypes.RECIPIENT_ADD]: false,
[MessageTypes.RECIPIENT_REMOVE]: false,
[MessageTypes.CALL]: false,
[MessageTypes.CHANNEL_NAME_CHANGE]: false,
[MessageTypes.CHANNEL_ICON_CHANGE]: false,
[MessageTypes.CLIENT_SYSTEM]: false,
} as const satisfies Record<MessageTypeValue, boolean>;
export const isMessageTypeDeletable = (type: number): boolean => {
return type in MESSAGE_TYPE_DELETABLE ? MESSAGE_TYPE_DELETABLE[type as MessageTypeValue] : false;
};
export const MessageFlags = {
SUPPRESS_EMBEDS: 1 << 2,
SUPPRESS_NOTIFICATIONS: 1 << 12,
COMPACT_ATTACHMENTS: 1 << 17,
} as const;
export const MessageAttachmentFlags = {
IS_SPOILER: 1 << 3,
CONTAINS_EXPLICIT_MEDIA: 1 << 4,
IS_ANIMATED: 1 << 5,
} as const;
export const MessageEmbedTypes = {
RICH: 'rich',
ARTICLE: 'article',
LINK: 'link',
IMAGE: 'image',
VIDEO: 'video',
AUDIO: 'audio',
GIFV: 'gifv',
} as const;
export const MessageStates = {
SENT: 'SENT',
SENDING: 'SENDING',
EDITING: 'EDITING',
FAILED: 'FAILED',
} as const;
export const MessagePreviewContext = {
SETTINGS: 'SETTINGS',
LIST_POPOUT: 'LIST_POPOUT',
} as const;
export const Permissions = {
CREATE_INSTANT_INVITE: 1n << 0n,
KICK_MEMBERS: 1n << 1n,
BAN_MEMBERS: 1n << 2n,
ADMINISTRATOR: 1n << 3n,
MANAGE_CHANNELS: 1n << 4n,
MANAGE_GUILD: 1n << 5n,
ADD_REACTIONS: 1n << 6n,
VIEW_AUDIT_LOG: 1n << 7n,
PRIORITY_SPEAKER: 1n << 8n,
STREAM: 1n << 9n,
VIEW_CHANNEL: 1n << 10n,
SEND_MESSAGES: 1n << 11n,
SEND_TTS_MESSAGES: 1n << 12n,
MANAGE_MESSAGES: 1n << 13n,
EMBED_LINKS: 1n << 14n,
ATTACH_FILES: 1n << 15n,
READ_MESSAGE_HISTORY: 1n << 16n,
MENTION_EVERYONE: 1n << 17n,
USE_EXTERNAL_EMOJIS: 1n << 18n,
CONNECT: 1n << 20n,
SPEAK: 1n << 21n,
MUTE_MEMBERS: 1n << 22n,
DEAFEN_MEMBERS: 1n << 23n,
MOVE_MEMBERS: 1n << 24n,
USE_VAD: 1n << 25n,
CHANGE_NICKNAME: 1n << 26n,
MANAGE_NICKNAMES: 1n << 27n,
MANAGE_ROLES: 1n << 28n,
MANAGE_WEBHOOKS: 1n << 29n,
MANAGE_EXPRESSIONS: 1n << 30n,
USE_EXTERNAL_STICKERS: 1n << 37n,
MODERATE_MEMBERS: 1n << 40n,
CREATE_EXPRESSIONS: 1n << 43n,
PIN_MESSAGES: 1n << 51n,
BYPASS_SLOWMODE: 1n << 52n,
UPDATE_RTC_REGION: 1n << 53n,
} as const;
export const ALL_PERMISSIONS = Object.values(Permissions).reduce((acc, p) => acc | p, 0n);
export const DEFAULT_PERMISSIONS =
Permissions.CREATE_INSTANT_INVITE |
Permissions.ADD_REACTIONS |
Permissions.STREAM |
Permissions.VIEW_CHANNEL |
Permissions.SEND_MESSAGES |
Permissions.EMBED_LINKS |
Permissions.ATTACH_FILES |
Permissions.READ_MESSAGE_HISTORY |
Permissions.USE_EXTERNAL_EMOJIS |
Permissions.CONNECT |
Permissions.SPEAK |
Permissions.USE_VAD |
Permissions.CHANGE_NICKNAME |
Permissions.USE_EXTERNAL_STICKERS |
Permissions.CREATE_EXPRESSIONS;
export const ElevatedPermissions =
Permissions.KICK_MEMBERS |
Permissions.BAN_MEMBERS |
Permissions.ADMINISTRATOR |
Permissions.MANAGE_CHANNELS |
Permissions.MANAGE_GUILD |
Permissions.MANAGE_ROLES |
Permissions.MANAGE_MESSAGES |
Permissions.MANAGE_WEBHOOKS |
Permissions.MANAGE_EXPRESSIONS |
Permissions.MODERATE_MEMBERS;
export const GatewayOpcodes = {
DISPATCH: 0,
HEARTBEAT: 1,
IDENTIFY: 2,
PRESENCE_UPDATE: 3,
VOICE_STATE_UPDATE: 4,
VOICE_SERVER_PING: 5,
RESUME: 6,
RECONNECT: 7,
REQUEST_GUILD_MEMBERS: 8,
INVALID_SESSION: 9,
HELLO: 10,
HEARTBEAT_ACK: 11,
GATEWAY_ERROR: 12,
CALL_CONNECT: 13,
LAZY_REQUEST: 14,
} as const;
export const LARGE_GUILD_THRESHOLD = 250;
export const MEMBER_CHUNK_SIZE = 1000;
export const GatewayIdentifyFlags = {
USE_CANARY_API: 1 << 0,
} as const;
export const GatewayCloseCodes = {
UNKNOWN_ERROR: 4000,
UNKNOWN_OPCODE: 4001,
DECODE_ERROR: 4002,
NOT_AUTHENTICATED: 4003,
AUTHENTICATION_FAILED: 4004,
ALREADY_AUTHENTICATED: 4005,
INVALID_SEQ: 4007,
RATE_LIMITED: 4008,
SESSION_TIMEOUT: 4009,
INVALID_SHARD: 4010,
SHARDING_REQUIRED: 4011,
INVALID_API_VERSION: 4012,
} as const;
export const GatewayErrorCodes = {
VOICE_CONNECTION_NOT_FOUND: 'VOICE_CONNECTION_NOT_FOUND',
VOICE_CHANNEL_NOT_FOUND: 'VOICE_CHANNEL_NOT_FOUND',
VOICE_INVALID_CHANNEL_TYPE: 'VOICE_INVALID_CHANNEL_TYPE',
VOICE_MEMBER_NOT_FOUND: 'VOICE_MEMBER_NOT_FOUND',
VOICE_MEMBER_TIMED_OUT: 'VOICE_MEMBER_TIMED_OUT',
VOICE_USER_NOT_IN_VOICE: 'VOICE_USER_NOT_IN_VOICE',
VOICE_GUILD_NOT_FOUND: 'VOICE_GUILD_NOT_FOUND',
VOICE_PERMISSION_DENIED: 'VOICE_PERMISSION_DENIED',
VOICE_CHANNEL_FULL: 'VOICE_CHANNEL_FULL',
VOICE_MISSING_CONNECTION_ID: 'VOICE_MISSING_CONNECTION_ID',
VOICE_INVALID_USER_ID: 'VOICE_INVALID_USER_ID',
VOICE_INVALID_CHANNEL_ID: 'VOICE_INVALID_CHANNEL_ID',
VOICE_INVALID_STATE: 'VOICE_INVALID_STATE',
VOICE_USER_MISMATCH: 'VOICE_USER_MISMATCH',
VOICE_TOKEN_FAILED: 'VOICE_TOKEN_FAILED',
VOICE_GUILD_ID_MISSING: 'VOICE_GUILD_ID_MISSING',
VOICE_INVALID_GUILD_ID: 'VOICE_INVALID_GUILD_ID',
VOICE_UNCLAIMED_ACCOUNT: 'VOICE_UNCLAIMED_ACCOUNT',
DM_NOT_RECIPIENT: 'DM_NOT_RECIPIENT',
DM_INVALID_CHANNEL_TYPE: 'DM_INVALID_CHANNEL_TYPE',
UNKNOWN_ERROR: 'UNKNOWN_ERROR',
} as const;
export type GatewayErrorCode = (typeof GatewayErrorCodes)[keyof typeof GatewayErrorCodes];
export const APIErrorCodes = {
GENERAL_ERROR: 'GENERAL_ERROR',
UNKNOWN_CHANNEL: 'UNKNOWN_CHANNEL',
UNKNOWN_GUILD: 'UNKNOWN_GUILD',
UNKNOWN_INVITE: 'UNKNOWN_INVITE',
UNKNOWN_MEMBER: 'UNKNOWN_MEMBER',
UNKNOWN_MESSAGE: 'UNKNOWN_MESSAGE',
UNKNOWN_ROLE: 'UNKNOWN_ROLE',
UNKNOWN_USER: 'UNKNOWN_USER',
UNKNOWN_EMOJI: 'UNKNOWN_EMOJI',
UNKNOWN_PACK: 'UNKNOWN_PACK',
UNKNOWN_WEBHOOK: 'UNKNOWN_WEBHOOK',
UNKNOWN_BETA_CODE: 'UNKNOWN_BETA_CODE',
EXPLICIT_CONTENT_CANNOT_BE_SENT: 'EXPLICIT_CONTENT_CANNOT_BE_SENT',
FILE_SIZE_TOO_LARGE: 'FILE_SIZE_TOO_LARGE',
MAX_GUILDS: 'MAX_GUILDS',
MAX_FRIENDS: 'MAX_FRIENDS',
MAX_PINS_PER_CHANNEL: 'MAX_PINS_PER_CHANNEL',
MAX_GUILD_ROLES: 'MAX_GUILD_ROLES',
MAX_WEBHOOKS: 'MAX_WEBHOOKS',
MAX_EMOJIS: 'MAX_EMOJIS',
MAX_REACTIONS: 'MAX_REACTIONS',
MAX_GUILD_CHANNELS: 'MAX_GUILD_CHANNELS',
MAX_CATEGORY_CHANNELS: 'MAX_CATEGORY_CHANNELS',
MAX_INVITES: 'MAX_INVITES',
MAX_PACKS: 'MAX_PACKS',
MAX_ANIMATED_EMOJIS: 'MAX_ANIMATED_EMOJIS',
MAX_GUILD_MEMBERS: 'MAX_GUILD_MEMBERS',
MAX_WEBHOOKS_PER_GUILD: 'MAX_WEBHOOKS_PER_GUILD',
MAX_BETA_CODES_REACHED: 'MAX_BETA_CODES_REACHED',
RATE_LIMITED: 'RATE_LIMITED',
SLOWMODE_RATE_LIMITED: 'SLOWMODE_RATE_LIMITED',
CAPTCHA_REQUIRED: 'CAPTCHA_REQUIRED',
INVALID_CAPTCHA: 'INVALID_CAPTCHA',
UNAUTHORIZED: 'UNAUTHORIZED',
USER_BANNED_FROM_GUILD: 'USER_BANNED_FROM_GUILD',
USER_IP_BANNED_FROM_GUILD: 'USER_IP_BANNED_FROM_GUILD',
MISSING_ACCESS: 'MISSING_ACCESS',
PREMIUM_REQUIRED: 'PREMIUM_REQUIRED',
CANNOT_EXECUTE_ON_DM: 'CANNOT_EXECUTE_ON_DM',
CANNOT_EDIT_OTHER_USER_MESSAGE: 'CANNOT_EDIT_OTHER_USER_MESSAGE',
CANNOT_SEND_EMPTY_MESSAGE: 'CANNOT_SEND_EMPTY_MESSAGE',
CANNOT_SEND_MESSAGES_TO_USER: 'CANNOT_SEND_MESSAGES_TO_USER',
CANNOT_SEND_MESSAGES_IN_NON_TEXT_CHANNEL: 'CANNOT_SEND_MESSAGES_IN_NON_TEXT_CHANNEL',
COMMUNICATION_DISABLED: 'COMMUNICATION_DISABLED',
MISSING_PERMISSIONS: 'MISSING_PERMISSIONS',
INVALID_FORM_BODY: 'INVALID_FORM_BODY',
CANNOT_MODIFY_SYSTEM_WEBHOOK: 'CANNOT_MODIFY_SYSTEM_WEBHOOK',
TWO_FACTOR_REQUIRED: 'TWO_FACTOR_REQUIRED',
FRIEND_REQUEST_BLOCKED: 'FRIEND_REQUEST_BLOCKED',
CANNOT_SEND_FRIEND_REQUEST_TO_BLOCKED_USER: 'CANNOT_SEND_FRIEND_REQUEST_TO_BLOCKED_USER',
BOTS_CANNOT_HAVE_FRIENDS: 'BOTS_CANNOT_HAVE_FRIENDS',
CANNOT_SEND_FRIEND_REQUEST_TO_SELF: 'CANNOT_SEND_FRIEND_REQUEST_TO_SELF',
NO_USERS_WITH_FLUXERTAG_EXIST: 'NO_USERS_WITH_FLUXERTAG_EXIST',
ALREADY_FRIENDS: 'ALREADY_FRIENDS',
DISCRIMINATOR_REQUIRED: 'DISCRIMINATOR_REQUIRED',
TWO_FA_NOT_ENABLED: 'TWO_FA_NOT_ENABLED',
MISSING_ACL: 'MISSING_ACL',
IP_BANNED: 'IP_BANNED',
IP_AUTHORIZATION_REQUIRED: 'IP_AUTHORIZATION_REQUIRED',
USER_NOT_IN_VOICE: 'USER_NOT_IN_VOICE',
CANNOT_MODIFY_VOICE_STATE: 'CANNOT_MODIFY_VOICE_STATE',
ACCOUNT_DISABLED: 'ACCOUNT_DISABLED',
ACCOUNT_SCHEDULED_FOR_DELETION: 'ACCOUNT_SCHEDULED_FOR_DELETION',
TAG_ALREADY_TAKEN: 'TAG_ALREADY_TAKEN',
INVALID_PHONE_NUMBER: 'INVALID_PHONE_NUMBER',
PHONE_ALREADY_USED: 'PHONE_ALREADY_USED',
PHONE_VERIFICATION_REQUIRED: 'PHONE_VERIFICATION_REQUIRED',
INVALID_PHONE_VERIFICATION_CODE: 'INVALID_PHONE_VERIFICATION_CODE',
PHONE_RATE_LIMIT_EXCEEDED: 'PHONE_RATE_LIMIT_EXCEEDED',
SMS_MFA_NOT_ENABLED: 'SMS_MFA_NOT_ENABLED',
SMS_MFA_REQUIRES_TOTP: 'SMS_MFA_REQUIRES_TOTP',
PHONE_REQUIRED_FOR_SMS_MFA: 'PHONE_REQUIRED_FOR_SMS_MFA',
INVALID_WEBAUTHN_CREDENTIAL: 'INVALID_WEBAUTHN_CREDENTIAL',
WEBAUTHN_CREDENTIAL_LIMIT_REACHED: 'WEBAUTHN_CREDENTIAL_LIMIT_REACHED',
UNKNOWN_WEBAUTHN_CREDENTIAL: 'UNKNOWN_WEBAUTHN_CREDENTIAL',
PASSKEY_AUTHENTICATION_FAILED: 'PASSKEY_AUTHENTICATION_FAILED',
ACCOUNT_SUSPICIOUS_ACTIVITY: 'ACCOUNT_SUSPICIOUS_ACTIVITY',
PREMIUM_PURCHASE_BLOCKED: 'PREMIUM_PURCHASE_BLOCKED',
HARVEST_ON_COOLDOWN: 'HARVEST_ON_COOLDOWN',
UNKNOWN_GIFT_CODE: 'UNKNOWN_GIFT_CODE',
GIFT_CODE_ALREADY_REDEEMED: 'GIFT_CODE_ALREADY_REDEEMED',
STRIPE_ERROR: 'STRIPE_ERROR',
STRIPE_WEBHOOK_SIGNATURE_INVALID: 'STRIPE_WEBHOOK_SIGNATURE_INVALID',
USER_OWNS_GUILDS: 'USER_OWNS_GUILDS',
FEATURE_TEMPORARILY_DISABLED: 'FEATURE_TEMPORARILY_DISABLED',
INVITES_DISABLED: 'INVITES_DISABLED',
TEMPORARY_INVITE_REQUIRES_PRESENCE: 'TEMPORARY_INVITE_REQUIRES_PRESENCE',
MAX_GROUP_DM_RECIPIENTS: 'MAX_GROUP_DM_RECIPIENTS',
NOT_FRIENDS_WITH_USER: 'NOT_FRIENDS_WITH_USER',
INVALID_CHANNEL_TYPE: 'INVALID_CHANNEL_TYPE',
NSFW_CONTENT_AGE_RESTRICTED: 'NSFW_CONTENT_AGE_RESTRICTED',
MAX_BOOKMARKS: 'MAX_BOOKMARKS',
MAX_PACK_EXPRESSIONS: 'MAX_PACK_EXPRESSIONS',
MAX_FAVORITE_MEMES: 'MAX_FAVORITE_MEMES',
CANNOT_REDEEM_PLUTONIUM_WITH_VISIONARY: 'CANNOT_REDEEM_PLUTONIUM_WITH_VISIONARY',
NO_VISIONARY_SLOTS_AVAILABLE: 'NO_VISIONARY_SLOTS_AVAILABLE',
CANNOT_SHRINK_RESERVED_SLOTS: 'CANNOT_SHRINK_RESERVED_SLOTS',
UNCLAIMED_ACCOUNT_RESTRICTED: 'UNCLAIMED_ACCOUNT_RESTRICTED',
GUILD_DISALLOWS_UNCLAIMED_ACCOUNTS: 'GUILD_DISALLOWS_UNCLAIMED_ACCOUNTS',
} as const;
export const GuildFeatures = {
ANIMATED_ICON: 'ANIMATED_ICON',
ANIMATED_BANNER: 'ANIMATED_BANNER',
BANNER: 'BANNER',
DETACHED_BANNER: 'DETACHED_BANNER',
INVITE_SPLASH: 'INVITE_SPLASH',
INVITES_DISABLED: 'INVITES_DISABLED',
TEXT_CHANNEL_FLEXIBLE_NAMES: 'TEXT_CHANNEL_FLEXIBLE_NAMES',
MORE_EMOJI: 'MORE_EMOJI',
MORE_STICKERS: 'MORE_STICKERS',
UNLIMITED_EMOJI: 'UNLIMITED_EMOJI',
UNLIMITED_STICKERS: 'UNLIMITED_STICKERS',
EXPRESSION_PURGE_ALLOWED: 'EXPRESSION_PURGE_ALLOWED',
VANITY_URL: 'VANITY_URL',
VERIFIED: 'VERIFIED',
VIP_VOICE: 'VIP_VOICE',
UNAVAILABLE_FOR_EVERYONE: 'UNAVAILABLE_FOR_EVERYONE',
UNAVAILABLE_FOR_EVERYONE_BUT_STAFF: 'UNAVAILABLE_FOR_EVERYONE_BUT_STAFF',
VISIONARY: 'VISIONARY',
OPERATOR: 'OPERATOR',
DISALLOW_UNCLAIMED_ACCOUNTS: 'DISALLOW_UNCLAIMED_ACCOUNTS',
LARGE_GUILD_OVERRIDE: 'LARGE_GUILD_OVERRIDE',
VERY_LARGE_GUILD: 'VERY_LARGE_GUILD',
} as const;
export const JumpTypes = {
ANIMATED: 'ANIMATED',
INSTANT: 'INSTANT',
NONE: 'NONE',
} as const;
export type JumpTypes = (typeof JumpTypes)[keyof typeof JumpTypes];

View File

@@ -17,7 +17,7 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {ME} from '~/Constants';
import {ME} from '@fluxer/constants/src/AppConstants';
export const Endpoints = {
INSTANCE: '/instance',
@@ -33,7 +33,6 @@ export const Endpoints = {
AUTH_LOGOUT: '/auth/logout',
AUTH_REGISTER: '/auth/register',
AUTH_USERNAME_SUGGESTIONS: '/auth/username-suggestions',
AUTH_REDEEM_BETA_CODE: '/auth/redeem-beta-code',
AUTH_SESSIONS: '/auth/sessions',
AUTH_SESSIONS_LOGOUT: '/auth/sessions/logout',
AUTH_HANDOFF_INITIATE: '/auth/handoff/initiate',
@@ -47,8 +46,13 @@ export const Endpoints = {
AUTH_RESEND_VERIFICATION: '/auth/verify/resend',
AUTH_AUTHORIZE_IP: '/auth/authorize-ip',
AUTH_IP_AUTHORIZATION_RESEND: '/auth/ip-authorization/resend',
AUTH_IP_AUTHORIZATION_STREAM: (ticket: string) =>
`/auth/ip-authorization/stream?ticket=${encodeURIComponent(ticket)}`,
AUTH_IP_AUTHORIZATION_POLL: (ticket: string) => {
const url = new URL('https://fluxer.invalid/auth/ip-authorization/poll');
url.searchParams.set('ticket', ticket);
return `${url.pathname}${url.search}`;
},
AUTH_SSO_START: '/auth/sso/start',
AUTH_SSO_COMPLETE: '/auth/sso/complete',
SUDO_MFA_METHODS: '/users/@me/sudo/mfa-methods',
SUDO_SMS_SEND: '/users/@me/sudo/mfa/sms/send',
@@ -101,6 +105,7 @@ export const Endpoints = {
GUILD_CHANNELS: (guildId: string) => `/guilds/${guildId}/channels`,
GUILD_MEMBER: (guildId: string, query = ME) => `/guilds/${guildId}/members/${query}`,
GUILD_MEMBERS: (guildId: string) => `/guilds/${guildId}/members`,
GUILD_MEMBERS_SEARCH: (guildId: string) => `/guilds/${guildId}/members-search`,
GUILD_MEMBER_ROLE: (guildId: string, userId: string, roleId: string) =>
`/guilds/${guildId}/members/${userId}/roles/${roleId}`,
GUILD_BAN: (guildId: string, userId: string) => `/guilds/${guildId}/bans/${userId}`,
@@ -112,7 +117,6 @@ export const Endpoints = {
GUILD_TRANSFER_OWNERSHIP: (guildId: string) => `/guilds/${guildId}/transfer-ownership`,
GUILD_TEXT_CHANNEL_FLEXIBLE_NAMES: (guildId: string) => `/guilds/${guildId}/text-channel-flexible-names`,
GUILD_DETACHED_BANNER: (guildId: string) => `/guilds/${guildId}/detached-banner`,
GUILD_DISALLOW_UNCLAIMED_ACCOUNTS: (guildId: string) => `/guilds/${guildId}/disallow-unclaimed-accounts`,
GUILD_EMOJI: (guildId: string, emojiId: string) => `/guilds/${guildId}/emojis/${emojiId}`,
GUILD_EMOJIS: (guildId: string) => `/guilds/${guildId}/emojis`,
GUILD_STICKER: (guildId: string, stickerId: string) => `/guilds/${guildId}/stickers/${stickerId}`,
@@ -128,7 +132,6 @@ export const Endpoints = {
GIFT_REDEEM: (code: string) => `/gifts/${code}/redeem`,
USER_GIFTS: '/users/@me/gifts',
PREMIUM_VISIONARY_SLOTS: '/premium/visionary/slots',
PREMIUM_VISIONARY_REJOIN: '/premium/visionary/rejoin',
PREMIUM_OPERATOR_REJOIN: '/premium/operator/rejoin',
PREMIUM_PRICE_IDS: '/premium/price-ids',
@@ -150,14 +153,18 @@ export const Endpoints = {
DSA_REPORT_EMAIL_VERIFY: '/reports/dsa/email/verify',
DSA_REPORT_CREATE: '/reports/dsa',
KLIPY_FEATURED: '/klipy/featured',
KLIPY_REGISTER_SHARE: '/klipy/register-share',
KLIPY_SEARCH: '/klipy/search',
KLIPY_SUGGEST: '/klipy/suggest',
KLIPY_TRENDING_GIFS: '/klipy/trending-gifs',
TENOR_FEATURED: '/tenor/featured',
TENOR_REGISTER_SHARE: '/tenor/register-share',
TENOR_SEARCH: '/tenor/search',
TENOR_SUGGEST: '/tenor/suggest',
TENOR_TRENDING_GIFS: '/tenor/trending-gifs',
USER_BETA_CODE: (code: string) => `/users/@me/beta-codes/${code}`,
USER_BETA_CODES: '/users/@me/beta-codes',
USER_CHANNELS: '/users/@me/channels',
USER_CHANNEL_PIN: (channelId: string) => `/users/@me/channels/${channelId}/pin`,
USER_GUILDS_LIST: '/users/@me/guilds',
@@ -170,6 +177,7 @@ export const Endpoints = {
USER_MFA_TOTP_ENABLE: '/users/@me/mfa/totp/enable',
USER_MFA_SMS_ENABLE: '/users/@me/mfa/sms/enable',
USER_MFA_SMS_DISABLE: '/users/@me/mfa/sms/disable',
USER_AUTHORIZED_IPS: '/users/@me/authorized-ips',
USER_MFA_WEBAUTHN_CREDENTIALS: '/users/@me/mfa/webauthn/credentials',
USER_MFA_WEBAUTHN_REGISTRATION_OPTIONS: '/users/@me/mfa/webauthn/credentials/registration-options',
USER_MFA_WEBAUTHN_CREDENTIAL: (credentialId: string) => `/users/@me/mfa/webauthn/credentials/${credentialId}`,
@@ -182,10 +190,18 @@ export const Endpoints = {
USER_EMAIL_CHANGE_REQUEST_NEW: '/users/@me/email-change/request-new',
USER_EMAIL_CHANGE_RESEND_NEW: '/users/@me/email-change/resend-new',
USER_EMAIL_CHANGE_VERIFY_NEW: '/users/@me/email-change/verify-new',
USER_EMAIL_CHANGE_BOUNCED_REQUEST_NEW: '/users/@me/email-change/bounced/request-new',
USER_EMAIL_CHANGE_BOUNCED_RESEND_NEW: '/users/@me/email-change/bounced/resend-new',
USER_EMAIL_CHANGE_BOUNCED_VERIFY_NEW: '/users/@me/email-change/bounced/verify-new',
USER_PASSWORD_CHANGE_START: '/users/@me/password-change/start',
USER_PASSWORD_CHANGE_RESEND: '/users/@me/password-change/resend',
USER_PASSWORD_CHANGE_VERIFY: '/users/@me/password-change/verify',
USER_PASSWORD_CHANGE_COMPLETE: '/users/@me/password-change/complete',
USER_DISABLE: '/users/@me/disable',
USER_DELETE: '/users/@me/delete',
USER_BULK_DELETE_MESSAGES: '/users/@me/messages/delete',
USER_BULK_DELETE_MESSAGES_TEST: '/users/@me/messages/delete/test',
USER_PREMIUM_RESET: '/users/@me/premium/reset',
USER_HARVEST: '/users/@me/harvest',
USER_HARVEST_LATEST: '/users/@me/harvest/latest',
USER_HARVEST_STATUS: (harvestId: string) => `/users/@me/harvest/${harvestId}`,
@@ -228,4 +244,16 @@ export const Endpoints = {
REPORT_MESSAGE: '/reports/message',
REPORT_USER: '/reports/user',
REPORT_GUILD: '/reports/guild',
DISCOVERY_GUILDS: '/discovery/guilds',
DISCOVERY_CATEGORIES: '/discovery/categories',
DISCOVERY_JOIN: (guildId: string) => `/discovery/guilds/${guildId}/join`,
GUILD_DISCOVERY: (guildId: string) => `/guilds/${guildId}/discovery`,
CONNECTIONS: '/users/@me/connections',
CONNECTIONS_VERIFY_AND_CREATE: '/users/@me/connections/verify',
BLUESKY_AUTHORIZE: '/users/@me/connections/bluesky/authorize',
CONNECTION: (type: string, connectionId: string) => `/users/@me/connections/${type}/${connectionId}`,
CONNECTION_VERIFY: (type: string, connectionId: string) => `/users/@me/connections/${type}/${connectionId}/verify`,
CONNECTIONS_REORDER: '/users/@me/connections/reorder',
} as const;

View File

@@ -17,44 +17,44 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import AppStorage from '@app/lib/AppStorage';
import {Logger} from '@app/lib/Logger';
import {getNativeLocaleIdentifier} from '@app/lib/Platform';
import {messages as messagesAr} from '@app/locales/ar/messages.mjs';
import {messages as messagesBg} from '@app/locales/bg/messages.mjs';
import {messages as messagesCs} from '@app/locales/cs/messages.mjs';
import {messages as messagesDa} from '@app/locales/da/messages.mjs';
import {messages as messagesDe} from '@app/locales/de/messages.mjs';
import {messages as messagesEl} from '@app/locales/el/messages.mjs';
import {messages as messagesEnGB} from '@app/locales/en-GB/messages.mjs';
import {messages as messagesEnUS} from '@app/locales/en-US/messages.mjs';
import {messages as messagesEs419} from '@app/locales/es-419/messages.mjs';
import {messages as messagesEsES} from '@app/locales/es-ES/messages.mjs';
import {messages as messagesFi} from '@app/locales/fi/messages.mjs';
import {messages as messagesFr} from '@app/locales/fr/messages.mjs';
import {messages as messagesHe} from '@app/locales/he/messages.mjs';
import {messages as messagesHi} from '@app/locales/hi/messages.mjs';
import {messages as messagesHr} from '@app/locales/hr/messages.mjs';
import {messages as messagesHu} from '@app/locales/hu/messages.mjs';
import {messages as messagesId} from '@app/locales/id/messages.mjs';
import {messages as messagesIt} from '@app/locales/it/messages.mjs';
import {messages as messagesJa} from '@app/locales/ja/messages.mjs';
import {messages as messagesKo} from '@app/locales/ko/messages.mjs';
import {messages as messagesLt} from '@app/locales/lt/messages.mjs';
import {messages as messagesNl} from '@app/locales/nl/messages.mjs';
import {messages as messagesNo} from '@app/locales/no/messages.mjs';
import {messages as messagesPl} from '@app/locales/pl/messages.mjs';
import {messages as messagesPtBR} from '@app/locales/pt-BR/messages.mjs';
import {messages as messagesRo} from '@app/locales/ro/messages.mjs';
import {messages as messagesRu} from '@app/locales/ru/messages.mjs';
import {messages as messagesSvSE} from '@app/locales/sv-SE/messages.mjs';
import {messages as messagesTh} from '@app/locales/th/messages.mjs';
import {messages as messagesTr} from '@app/locales/tr/messages.mjs';
import {messages as messagesUk} from '@app/locales/uk/messages.mjs';
import {messages as messagesVi} from '@app/locales/vi/messages.mjs';
import {messages as messagesZhCN} from '@app/locales/zh-CN/messages.mjs';
import {messages as messagesZhTW} from '@app/locales/zh-TW/messages.mjs';
import {i18n, type Messages} from '@lingui/core';
import AppStorage from '~/lib/AppStorage';
import {getNativeLocaleIdentifier} from '~/lib/Platform';
import {messages as messagesAr} from '~/locales/ar/messages.mjs';
import {messages as messagesBg} from '~/locales/bg/messages.mjs';
import {messages as messagesCs} from '~/locales/cs/messages.mjs';
import {messages as messagesDa} from '~/locales/da/messages.mjs';
import {messages as messagesDe} from '~/locales/de/messages.mjs';
import {messages as messagesEl} from '~/locales/el/messages.mjs';
import {messages as messagesEnGB} from '~/locales/en-GB/messages.mjs';
import {messages as messagesEnUS} from '~/locales/en-US/messages.mjs';
import {messages as messagesEs419} from '~/locales/es-419/messages.mjs';
import {messages as messagesEsES} from '~/locales/es-ES/messages.mjs';
import {messages as messagesFi} from '~/locales/fi/messages.mjs';
import {messages as messagesFr} from '~/locales/fr/messages.mjs';
import {messages as messagesHe} from '~/locales/he/messages.mjs';
import {messages as messagesHi} from '~/locales/hi/messages.mjs';
import {messages as messagesHr} from '~/locales/hr/messages.mjs';
import {messages as messagesHu} from '~/locales/hu/messages.mjs';
import {messages as messagesId} from '~/locales/id/messages.mjs';
import {messages as messagesIt} from '~/locales/it/messages.mjs';
import {messages as messagesJa} from '~/locales/ja/messages.mjs';
import {messages as messagesKo} from '~/locales/ko/messages.mjs';
import {messages as messagesLt} from '~/locales/lt/messages.mjs';
import {messages as messagesNl} from '~/locales/nl/messages.mjs';
import {messages as messagesNo} from '~/locales/no/messages.mjs';
import {messages as messagesPl} from '~/locales/pl/messages.mjs';
import {messages as messagesPtBR} from '~/locales/pt-BR/messages.mjs';
import {messages as messagesRo} from '~/locales/ro/messages.mjs';
import {messages as messagesRu} from '~/locales/ru/messages.mjs';
import {messages as messagesSvSE} from '~/locales/sv-SE/messages.mjs';
import {messages as messagesTh} from '~/locales/th/messages.mjs';
import {messages as messagesTr} from '~/locales/tr/messages.mjs';
import {messages as messagesUk} from '~/locales/uk/messages.mjs';
import {messages as messagesVi} from '~/locales/vi/messages.mjs';
import {messages as messagesZhCN} from '~/locales/zh-CN/messages.mjs';
import {messages as messagesZhTW} from '~/locales/zh-TW/messages.mjs';
const supportedLocales = [
'ar',
@@ -97,6 +97,8 @@ type LocaleCode = (typeof supportedLocales)[number];
const DEFAULT_LOCALE: LocaleCode = 'en-US';
const supportedLocaleSet = new Set<LocaleCode>(supportedLocales);
const logger = new Logger('i18n');
const LANGUAGE_OVERRIDES: Record<string, LocaleCode> = {
en: 'en-US',
};
@@ -244,7 +246,7 @@ export async function initI18n(forceLocale?: string) {
const localeToLoad = detectPreferredLocale(forceLocale);
loadLocaleCatalog(localeToLoad);
} catch (error) {
console.error('Failed to initialize i18n, falling back to default locale', error);
logger.error('Failed to initialize i18n, falling back to default locale', error);
loadLocaleCatalog(DEFAULT_LOCALE);
}

View File

@@ -17,10 +17,11 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {createRouter} from '~/lib/router';
import {buildRoutes} from '~/router/routes';
import NavigationStore from '~/stores/NavigationStore';
import * as RouterUtils from '~/utils/RouterUtils';
import {createRouter} from '@app/lib/router/Core';
import {buildRoutes} from '@app/router/routes/Routes';
import NavigationSideEffectsStore from '@app/stores/NavigationSideEffectsStore';
import NavigationStore from '@app/stores/NavigationStore';
import * as RouterUtils from '@app/utils/RouterUtils';
const routes = buildRoutes();
@@ -32,3 +33,4 @@ export const router = createRouter({
});
NavigationStore.initialize(router);
NavigationSideEffectsStore.initialize();

View File

@@ -17,7 +17,7 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {marketingUrl} from '~/utils/UrlUtils';
import {marketingUrl} from '@app/utils/UrlUtils';
export const Routes = {
HOME: '/',
@@ -28,7 +28,7 @@ export const Routes = {
VERIFY_EMAIL: '/verify',
AUTHORIZE_IP: '/authorize-ip',
EMAIL_REVERT: '/wasntme',
PENDING_VERIFICATION: '/pending',
PENDING: '/pending',
OAUTH_AUTHORIZE: '/oauth2/authorize',
INVITE_REGISTER: '/invite/:code',
@@ -46,6 +46,7 @@ export const Routes = {
YOU: '/you',
REPORT: '/report',
PREMIUM_CALLBACK: '/premium-callback',
CONNECTION_CALLBACK: '/connection-callback',
terms: () => marketingUrl('terms'),
privacy: () => marketingUrl('privacy'),
@@ -54,11 +55,12 @@ export const Routes = {
partners: () => marketingUrl('partners'),
bugs: () => marketingUrl('bugs'),
plutonium: () => marketingUrl('plutonium'),
plutoniumVisionary: () => marketingUrl('plutonium#visionary'),
help: () => marketingUrl('help'),
helpArticle: (slug: string) => marketingUrl(`help/${slug}`),
dmChannel: (channelId: string) => `/channels/@me/${channelId}`,
favoritesChannel: (channelId: string) => `/channels/@favorites/${channelId}`,
guildMembers: (guildId: string) => `/channels/${guildId}/members`,
guildChannel: (guildId: string, channelId?: string) =>
channelId ? `/channels/${guildId}/${channelId}` : `/channels/${guildId}`,
channelMessage: (guildId: string, channelId: string, messageId: string) =>

View File

@@ -17,8 +17,8 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import AccessibilityStore, {type AccessibilitySettings} from '~/stores/AccessibilityStore';
import AccessibilityStore, {type AccessibilitySettings} from '@app/stores/AccessibilityStore';
export const update = (settings: Partial<AccessibilitySettings>): void => {
export function update(settings: Partial<AccessibilitySettings>): void {
AccessibilityStore.updateSettings(settings);
};
}

View File

@@ -17,20 +17,20 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {AuthSession} from '~/records/AuthSessionRecord';
import AuthSessionStore from '~/stores/AuthSessionStore';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import AuthSessionStore from '@app/stores/AuthSessionStore';
import type {AuthSessionResponse} from '@fluxer/schema/src/domains/auth/AuthSchemas';
const logger = new Logger('AuthSessionsService');
export const fetch = async (): Promise<void> => {
export async function fetch(): Promise<void> {
logger.debug('Fetching authentication sessions');
AuthSessionStore.fetchPending();
try {
const response = await http.get<Array<AuthSession>>({url: Endpoints.AUTH_SESSIONS, retries: 2});
const response = await http.get<Array<AuthSessionResponse>>({url: Endpoints.AUTH_SESSIONS, retries: 2});
const sessions = response.body ?? [];
logger.info(`Fetched ${sessions.length} authentication sessions`);
AuthSessionStore.fetchSuccess(sessions);
@@ -39,9 +39,9 @@ export const fetch = async (): Promise<void> => {
AuthSessionStore.fetchError();
throw error;
}
};
}
export const logout = async (sessionIdHashes: Array<string>): Promise<void> => {
export async function logout(sessionIdHashes: Array<string>): Promise<void> {
if (!sessionIdHashes.length) {
logger.warn('Attempted to logout with empty session list');
return;
@@ -62,4 +62,4 @@ export const logout = async (sessionIdHashes: Array<string>): Promise<void> => {
AuthSessionStore.logoutError();
throw error;
}
};
}

View File

@@ -17,17 +17,19 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '@app/Endpoints';
import type {UserData} from '@app/lib/AccountStorage';
import http from '@app/lib/HttpClient';
import {HttpError} from '@app/lib/HttpError';
import {Logger} from '@app/lib/Logger';
import AccountManager from '@app/stores/AccountManager';
import AuthenticationStore from '@app/stores/AuthenticationStore';
import GatewayConnectionStore from '@app/stores/gateway/GatewayConnectionStore';
import {getApiErrorCode} from '@app/utils/ApiErrorUtils';
import {isDesktop} from '@app/utils/NativeUtils';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import type {ValueOf} from '@fluxer/constants/src/ValueOf';
import type {AuthenticationResponseJSON, PublicKeyCredentialRequestOptionsJSON} from '@simplewebauthn/browser';
import {APIErrorCodes} from '~/Constants';
import {Endpoints} from '~/Endpoints';
import type {UserData} from '~/lib/AccountStorage';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import AccountManager from '~/stores/AccountManager';
import AuthenticationStore from '~/stores/AuthenticationStore';
import ConnectionStore from '~/stores/ConnectionStore';
import RuntimeConfigStore from '~/stores/RuntimeConfigStore';
import {isDesktop} from '~/utils/NativeUtils';
const logger = new Logger('AuthService');
@@ -43,14 +45,13 @@ export const VerificationResult = {
RATE_LIMITED: 'RATE_LIMITED',
SERVER_ERROR: 'SERVER_ERROR',
} as const;
export type VerificationResult = (typeof VerificationResult)[keyof typeof VerificationResult];
export type VerificationResult = ValueOf<typeof VerificationResult>;
interface RegisterData {
email?: string;
global_name?: string;
username?: string;
password?: string;
beta_code: string;
date_of_birth: string;
consent: boolean;
captchaToken?: string;
@@ -63,7 +64,6 @@ interface StandardLoginResponse {
user_id: string;
token: string;
theme?: string;
pending_verification?: boolean;
}
interface MfaLoginResponse {
@@ -72,6 +72,8 @@ interface MfaLoginResponse {
sms: boolean;
totp: boolean;
webauthn: boolean;
allowed_methods?: Array<string>;
sms_phone_hint?: string | null;
}
type LoginResponse = StandardLoginResponse | MfaLoginResponse;
@@ -83,19 +85,21 @@ export interface IpAuthorizationRequiredResponse {
resend_available_in: number;
}
export const isIpAuthorizationRequiredResponse = (
export function isIpAuthorizationRequiredResponse(
response: LoginResponse | IpAuthorizationRequiredResponse,
): response is IpAuthorizationRequiredResponse => {
): response is IpAuthorizationRequiredResponse {
return (response as IpAuthorizationRequiredResponse).ip_authorization_required === true;
};
}
interface TokenResponse {
user_id: string;
token: string;
theme?: string;
pending_verification?: boolean;
redirect_to?: string;
}
export type ResetPasswordResponse = TokenResponse | MfaLoginResponse;
interface DesktopHandoffInitiateResponse {
code: string;
expires_at: string;
@@ -107,26 +111,20 @@ interface DesktopHandoffStatusResponse {
user_id?: string;
}
export const login = async ({
export async function login({
email,
password,
captchaToken,
inviteCode,
captchaType,
customApiEndpoint,
}: {
email: string;
password: string;
captchaToken?: string;
inviteCode?: string;
captchaType?: 'turnstile' | 'hcaptcha';
customApiEndpoint?: string;
}): Promise<LoginResponse | IpAuthorizationRequiredResponse> => {
}): Promise<LoginResponse | IpAuthorizationRequiredResponse> {
try {
if (customApiEndpoint) {
await RuntimeConfigStore.connectToEndpoint(customApiEndpoint);
}
const headers: Record<string, string> = {};
if (captchaToken) {
headers['X-Captcha-Token'] = captchaToken;
@@ -148,22 +146,26 @@ export const login = async ({
logger.debug('Login successful', {mfa: response.body?.mfa});
return response.body;
} catch (error) {
const httpError = error as {status?: number; body?: any};
if (httpError.status === 403 && httpError.body?.code === APIErrorCodes.IP_AUTHORIZATION_REQUIRED) {
if (
error instanceof HttpError &&
error.status === 403 &&
getApiErrorCode(error) === APIErrorCodes.IP_AUTHORIZATION_REQUIRED
) {
logger.info('Login requires IP authorization', {email});
const body = error.body as Record<string, unknown> | undefined;
return {
ip_authorization_required: true,
ticket: httpError.body?.ticket,
email: httpError.body?.email,
resend_available_in: httpError.body?.resend_available_in ?? 30,
ticket: body?.ticket as string,
email: body?.email as string,
resend_available_in: (body?.resend_available_in as number) ?? 30,
};
}
logger.error('Login failed', error);
throw error;
}
};
}
export const loginMfaTotp = async (code: string, ticket: string, inviteCode?: string): Promise<TokenResponse> => {
export async function loginMfaTotp(code: string, ticket: string, inviteCode?: string): Promise<TokenResponse> {
try {
const body: {
code: string;
@@ -185,9 +187,9 @@ export const loginMfaTotp = async (code: string, ticket: string, inviteCode?: st
logger.error('MFA TOTP authentication failed', error);
throw error;
}
};
}
export const loginMfaSmsSend = async (ticket: string): Promise<void> => {
export async function loginMfaSmsSend(ticket: string): Promise<void> {
try {
await http.post({
url: Endpoints.AUTH_LOGIN_MFA_SMS_SEND,
@@ -199,9 +201,9 @@ export const loginMfaSmsSend = async (ticket: string): Promise<void> => {
logger.error('Failed to send SMS MFA code', error);
throw error;
}
};
}
export const loginMfaSms = async (code: string, ticket: string, inviteCode?: string): Promise<TokenResponse> => {
export async function loginMfaSms(code: string, ticket: string, inviteCode?: string): Promise<TokenResponse> {
try {
const body: {
code: string;
@@ -223,14 +225,14 @@ export const loginMfaSms = async (code: string, ticket: string, inviteCode?: str
logger.error('MFA SMS authentication failed', error);
throw error;
}
};
}
export const loginMfaWebAuthn = async (
export async function loginMfaWebAuthn(
response: AuthenticationResponseJSON,
challenge: string,
ticket: string,
inviteCode?: string,
): Promise<TokenResponse> => {
): Promise<TokenResponse> {
try {
const body: {
response: AuthenticationResponseJSON;
@@ -253,9 +255,9 @@ export const loginMfaWebAuthn = async (
logger.error('MFA WebAuthn authentication failed', error);
throw error;
}
};
}
export const getWebAuthnMfaOptions = async (ticket: string): Promise<PublicKeyCredentialRequestOptionsJSON> => {
export async function getWebAuthnMfaOptions(ticket: string): Promise<PublicKeyCredentialRequestOptionsJSON> {
try {
const response = await http.post<PublicKeyCredentialRequestOptionsJSON>({
url: Endpoints.AUTH_LOGIN_MFA_WEBAUTHN_OPTIONS,
@@ -269,9 +271,9 @@ export const getWebAuthnMfaOptions = async (ticket: string): Promise<PublicKeyCr
logger.error('Failed to get WebAuthn MFA options', error);
throw error;
}
};
}
export const getWebAuthnAuthenticationOptions = async (): Promise<PublicKeyCredentialRequestOptionsJSON> => {
export async function getWebAuthnAuthenticationOptions(): Promise<PublicKeyCredentialRequestOptionsJSON> {
try {
const response = await http.post<PublicKeyCredentialRequestOptionsJSON>({
url: Endpoints.AUTH_WEBAUTHN_OPTIONS,
@@ -284,13 +286,13 @@ export const getWebAuthnAuthenticationOptions = async (): Promise<PublicKeyCrede
logger.error('Failed to get WebAuthn authentication options', error);
throw error;
}
};
}
export const authenticateWithWebAuthn = async (
export async function authenticateWithWebAuthn(
response: AuthenticationResponseJSON,
challenge: string,
inviteCode?: string,
): Promise<TokenResponse> => {
): Promise<TokenResponse> {
try {
const body: {
response: AuthenticationResponseJSON;
@@ -312,9 +314,9 @@ export const authenticateWithWebAuthn = async (
logger.error('WebAuthn authentication failed', error);
throw error;
}
};
}
export const register = async (data: RegisterData): Promise<TokenResponse> => {
export async function register(data: RegisterData): Promise<TokenResponse> {
try {
const headers: Record<string, string> = {};
if (data.captchaToken) {
@@ -334,13 +336,13 @@ export const register = async (data: RegisterData): Promise<TokenResponse> => {
logger.error('Registration failed', error);
throw error;
}
};
}
interface UsernameSuggestionsResponse {
suggestions: Array<string>;
}
export const getUsernameSuggestions = async (globalName: string): Promise<Array<string>> => {
export async function getUsernameSuggestions(globalName: string): Promise<Array<string>> {
try {
const response = await http.post<UsernameSuggestionsResponse>({
url: Endpoints.AUTH_USERNAME_SUGGESTIONS,
@@ -354,13 +356,13 @@ export const getUsernameSuggestions = async (globalName: string): Promise<Array<
logger.error('Failed to fetch username suggestions', error);
throw error;
}
};
}
export const forgotPassword = async (
export async function forgotPassword(
email: string,
captchaToken?: string,
captchaType?: 'turnstile' | 'hcaptcha',
): Promise<void> => {
): Promise<void> {
try {
const headers: Record<string, string> = {};
if (captchaToken) {
@@ -376,11 +378,11 @@ export const forgotPassword = async (
} catch (error) {
logger.warn('Password reset request failed, but returning success to user', error);
}
};
}
export const resetPassword = async (token: string, password: string): Promise<TokenResponse> => {
export async function resetPassword(token: string, password: string): Promise<ResetPasswordResponse> {
try {
const response = await http.post<TokenResponse>({
const response = await http.post<ResetPasswordResponse>({
url: Endpoints.AUTH_RESET_PASSWORD,
body: {token, password},
headers: withPlatformHeader(),
@@ -392,9 +394,9 @@ export const resetPassword = async (token: string, password: string): Promise<To
logger.error('Password reset failed', error);
throw error;
}
};
}
export const revertEmailChange = async (token: string, password: string): Promise<TokenResponse> => {
export async function revertEmailChange(token: string, password: string): Promise<TokenResponse> {
try {
const response = await http.post<TokenResponse>({
url: Endpoints.AUTH_EMAIL_REVERT,
@@ -408,9 +410,9 @@ export const revertEmailChange = async (token: string, password: string): Promis
logger.error('Email revert failed', error);
throw error;
}
};
}
export const verifyEmail = async (token: string): Promise<VerificationResult> => {
export async function verifyEmail(token: string): Promise<VerificationResult> {
try {
await http.post({
url: Endpoints.AUTH_VERIFY_EMAIL,
@@ -428,9 +430,9 @@ export const verifyEmail = async (token: string): Promise<VerificationResult> =>
logger.error('Email verification failed - server error', error);
return VerificationResult.SERVER_ERROR;
}
};
}
export const resendVerificationEmail = async (): Promise<VerificationResult> => {
export async function resendVerificationEmail(): Promise<VerificationResult> {
try {
await http.post({
url: Endpoints.AUTH_RESEND_VERIFICATION,
@@ -447,13 +449,13 @@ export const resendVerificationEmail = async (): Promise<VerificationResult> =>
logger.error('Failed to resend verification email - server error', error);
return VerificationResult.SERVER_ERROR;
}
};
}
export const logout = async (): Promise<void> => {
export async function logout(): Promise<void> {
await AccountManager.logout();
};
}
export const authorizeIp = async (token: string): Promise<VerificationResult> => {
export async function authorizeIp(token: string): Promise<VerificationResult> {
try {
await http.post({
url: Endpoints.AUTH_AUTHORIZE_IP,
@@ -471,45 +473,47 @@ export const authorizeIp = async (token: string): Promise<VerificationResult> =>
logger.error('IP authorization failed - server error', error);
return VerificationResult.SERVER_ERROR;
}
};
}
export const resendIpAuthorization = async (ticket: string): Promise<void> => {
export async function resendIpAuthorization(ticket: string): Promise<void> {
await http.post({
url: Endpoints.AUTH_IP_AUTHORIZATION_RESEND,
body: {ticket},
headers: withPlatformHeader(),
});
};
}
export const subscribeToIpAuthorization = (ticket: string): EventSource => {
const base = RuntimeConfigStore.apiEndpoint || '';
const url = `${base}${Endpoints.AUTH_IP_AUTHORIZATION_STREAM(ticket)}`;
return new EventSource(url);
};
export interface IpAuthorizationPollResult {
completed: boolean;
token?: string;
user_id?: string;
}
export const initiateDesktopHandoff = async (): Promise<DesktopHandoffInitiateResponse> => {
export async function pollIpAuthorization(ticket: string): Promise<IpAuthorizationPollResult> {
const response = await http.get<IpAuthorizationPollResult>({
url: Endpoints.AUTH_IP_AUTHORIZATION_POLL(ticket),
headers: withPlatformHeader(),
});
return response.body;
}
export async function initiateDesktopHandoff(): Promise<DesktopHandoffInitiateResponse> {
const response = await http.post<DesktopHandoffInitiateResponse>({
url: Endpoints.AUTH_HANDOFF_INITIATE,
skipAuth: true,
});
return response.body;
};
}
export const pollDesktopHandoffStatus = async (
code: string,
customApiEndpoint?: string,
): Promise<DesktopHandoffStatusResponse> => {
const url = customApiEndpoint
? `${customApiEndpoint}${Endpoints.AUTH_HANDOFF_STATUS(code)}`
: Endpoints.AUTH_HANDOFF_STATUS(code);
export async function pollDesktopHandoffStatus(code: string): Promise<DesktopHandoffStatusResponse> {
const response = await http.get<DesktopHandoffStatusResponse>({
url,
url: Endpoints.AUTH_HANDOFF_STATUS(code),
skipAuth: true,
});
return response.body;
};
}
export const completeDesktopHandoff = async ({
export async function completeDesktopHandoff({
code,
token,
userId,
@@ -517,15 +521,15 @@ export const completeDesktopHandoff = async ({
code: string;
token: string;
userId: string;
}): Promise<void> => {
}): Promise<void> {
await http.post({
url: Endpoints.AUTH_HANDOFF_COMPLETE,
body: {code, token, user_id: userId},
skipAuth: true,
});
};
}
export const startSession = (token: string, options: {startGateway?: boolean} = {}): void => {
export function startSession(token: string, options: {startGateway?: boolean} = {}): void {
const {startGateway = true} = options;
logger.info('Starting new session');
@@ -535,12 +539,12 @@ export const startSession = (token: string, options: {startGateway?: boolean} =
return;
}
ConnectionStore.startSession(token);
};
GatewayConnectionStore.startSession(token);
}
let sessionStartInProgress = false;
export const ensureSessionStarted = async (): Promise<void> => {
export async function ensureSessionStarted(): Promise<void> {
if (sessionStartInProgress) {
return;
}
@@ -553,11 +557,11 @@ export const ensureSessionStarted = async (): Promise<void> => {
return;
}
if (ConnectionStore.isConnected || ConnectionStore.isConnecting) {
if (GatewayConnectionStore.isConnected || GatewayConnectionStore.isConnecting) {
return;
}
if (ConnectionStore.socket) {
if (GatewayConnectionStore.socket) {
return;
}
@@ -568,16 +572,16 @@ export const ensureSessionStarted = async (): Promise<void> => {
const token = AuthenticationStore.authToken;
if (token) {
ConnectionStore.startSession(token);
GatewayConnectionStore.startSession(token);
}
} finally {
setTimeout(() => {
sessionStartInProgress = false;
}, 100);
}
};
}
export const completeLogin = async ({
export async function completeLogin({
token,
userId,
userData,
@@ -585,7 +589,7 @@ export const completeLogin = async ({
token: string;
userId: string;
userData?: UserData;
}): Promise<void> => {
}): Promise<void> {
logger.info('Completing login process');
if (userId && token) {
@@ -593,7 +597,25 @@ export const completeLogin = async ({
} else {
startSession(token, {startGateway: true});
}
};
}
export async function startSso(redirectTo?: string): Promise<{authorization_url: string}> {
const response = await http.post<{authorization_url: string}>({
url: Endpoints.AUTH_SSO_START,
body: {redirect_to: redirectTo},
headers: withPlatformHeader(),
});
return response.body;
}
export async function completeSso({code, state}: {code: string; state: string}): Promise<TokenResponse> {
const response = await http.post<TokenResponse>({
url: Endpoints.AUTH_SSO_COMPLETE,
body: {code, state},
headers: withPlatformHeader(),
});
return response.body;
}
interface SetMfaTicketPayload {
ticket: string;
@@ -602,26 +624,12 @@ interface SetMfaTicketPayload {
webauthn: boolean;
}
export const setMfaTicket = ({ticket, sms, totp, webauthn}: SetMfaTicketPayload): void => {
export function setMfaTicket({ticket, sms, totp, webauthn}: SetMfaTicketPayload): void {
logger.debug('Setting MFA ticket');
AuthenticationStore.handleMfaTicketSet({ticket, sms, totp, webauthn});
};
}
export const clearMfaTicket = (): void => {
export function clearMfaTicket(): void {
logger.debug('Clearing MFA ticket');
AuthenticationStore.handleMfaTicketClear();
};
export const redeemBetaCode = async (betaCode: string): Promise<void> => {
try {
await http.post({
url: Endpoints.AUTH_REDEEM_BETA_CODE,
body: {beta_code: betaCode},
headers: withPlatformHeader(),
});
logger.info('Beta code redeemed successfully');
} catch (error) {
logger.error('Beta code redemption failed', error);
throw error;
}
};
}

View File

@@ -1,75 +0,0 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import {type BetaCode, BetaCodeRecord} from '~/records/BetaCodeRecord';
import BetaCodeStore from '~/stores/BetaCodeStore';
const logger = new Logger('BetaCodes');
interface BetaCodesListResponse {
beta_codes: Array<BetaCode>;
allowance: number;
next_reset_at: string | null;
}
export const fetch = async () => {
BetaCodeStore.fetchPending();
try {
const response = await http.get<BetaCodesListResponse>({url: Endpoints.USER_BETA_CODES, retries: 1});
const data = response.body;
BetaCodeStore.fetchSuccess(data.beta_codes, data.allowance, data.next_reset_at);
return data;
} catch (error) {
logger.error('Failed to fetch beta codes:', error);
BetaCodeStore.fetchError();
throw error;
}
};
export const create = async () => {
BetaCodeStore.createPending();
try {
const response = await http.post<BetaCode>(Endpoints.USER_BETA_CODES);
const betaCode = new BetaCodeRecord(response.body);
BetaCodeStore.createSuccess(betaCode);
return betaCode;
} catch (error) {
logger.error('Failed to create beta code:', error);
BetaCodeStore.createError();
throw error;
}
};
export const remove = async (code: string) => {
if (!code) {
throw new Error('No beta code provided');
}
BetaCodeStore.deletePending();
try {
await http.delete({url: Endpoints.USER_BETA_CODE(code)});
BetaCodeStore.deleteSuccess(code);
} catch (error) {
logger.error(`Failed to delete beta code ${code}:`, error);
BetaCodeStore.deleteError();
throw error;
}
};

View File

@@ -17,17 +17,19 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '@app/Endpoints';
import HttpClient from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import CallInitiatorStore from '@app/stores/CallInitiatorStore';
import CallStateStore from '@app/stores/CallStateStore';
import ChannelStore from '@app/stores/ChannelStore';
import GeoIPStore from '@app/stores/GeoIPStore';
import RtcRegionsStore from '@app/stores/RtcRegionsStore';
import SoundStore from '@app/stores/SoundStore';
import UserStore from '@app/stores/UserStore';
import MediaEngineStore from '@app/stores/voice/MediaEngineFacade';
import type {RtcRegionResponse} from '@fluxer/schema/src/domains/channel/ChannelSchemas';
import {reaction} from 'mobx';
import {Endpoints} from '~/Endpoints';
import HttpClient from '~/lib/HttpClient';
import CallInitiatorStore from '~/stores/CallInitiatorStore';
import CallStateStore from '~/stores/CallStateStore';
import ChannelStore from '~/stores/ChannelStore';
import GeoIPStore from '~/stores/GeoIPStore';
import SoundStore from '~/stores/SoundStore';
import UserStore from '~/stores/UserStore';
import MediaEngineStore from '~/stores/voice/MediaEngineFacade';
import {SoundType} from '~/utils/SoundUtils';
interface PendingRing {
channelId: string;
@@ -35,6 +37,8 @@ interface PendingRing {
dispose: () => void;
}
const logger = new Logger('CallActionCreators');
let pendingRing: PendingRing | null = null;
export async function checkCallEligibility(channelId: string): Promise<{ringable: boolean}> {
@@ -86,7 +90,7 @@ function setupPendingRing(channelId: string, recipients: Array<string>): void {
({connected, currentChannelId}) => {
if (connected && currentChannelId === channelId && pendingRing?.channelId === channelId) {
void ringCallRecipients(channelId, pendingRing.recipients).catch((error) => {
console.error('Failed to ring call recipients:', error);
logger.error('Failed to ring call recipients:', error);
});
clearPendingRing();
}
@@ -107,7 +111,12 @@ export function startCall(channelId: string, silent = false): void {
CallInitiatorStore.markInitiated(channelId, recipients);
if (!silent) {
if (silent) {
clearPendingRing();
void ringCallRecipients(channelId, []).catch((error) => {
logger.error('Failed to start silent call:', error);
});
} else {
setupPendingRing(channelId, recipients);
}
@@ -121,7 +130,6 @@ export function joinCall(channelId: string): void {
}
CallStateStore.clearPendingRinging(channelId, [currentUser.id]);
SoundStore.stopIncomingRing();
SoundStore.playSound(SoundType.UserJoin);
void MediaEngineStore.connectToVoiceChannel(null, channelId);
}
@@ -147,7 +155,7 @@ export async function leaveCall(channelId: string): Promise<void> {
try {
await stopRingingCallRecipients(channelId, toStop);
} catch (error) {
console.error('Failed to stop ringing pending recipients:', error);
logger.error('Failed to stop ringing pending recipients:', error);
}
}
@@ -167,7 +175,7 @@ export function rejectCall(channelId: string): void {
void MediaEngineStore.disconnectFromVoiceChannel('user');
}
void stopRingingCallRecipients(channelId).catch((error) => {
console.error('Failed to stop ringing:', error);
logger.error('Failed to stop ringing:', error);
});
SoundStore.stopIncomingRing();
CallInitiatorStore.clearChannel(channelId);
@@ -180,7 +188,20 @@ export function ignoreCall(channelId: string): void {
}
CallStateStore.clearPendingRinging(channelId, [currentUser.id]);
void stopRingingCallRecipients(channelId, [currentUser.id]).catch((error) => {
console.error('Failed to stop ringing:', error);
logger.error('Failed to stop ringing:', error);
});
SoundStore.stopIncomingRing();
}
export async function fetchCallRegions(channelId: string): Promise<Array<RtcRegionResponse>> {
const channel = ChannelStore.getChannel(channelId);
if (channel?.isPrivate()) {
return RtcRegionsStore.getRegions();
}
const response = await HttpClient.get<Array<RtcRegionResponse>>({url: Endpoints.CHANNEL_RTC_REGIONS(channelId)});
return response.body ?? [];
}
export async function updateCallRegion(channelId: string, region: string | null): Promise<void> {
await HttpClient.patch(Endpoints.CHANNEL_CALL(channelId), {region});
}

View File

@@ -17,14 +17,14 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {ChannelTypes} from '~/Constants';
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {Channel} from '~/records/ChannelRecord';
import type {Invite} from '~/records/MessageRecord';
import ChannelStore from '~/stores/ChannelStore';
import InviteStore from '~/stores/InviteStore';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import ChannelStore from '@app/stores/ChannelStore';
import InviteStore from '@app/stores/InviteStore';
import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';
import type {Channel} from '@fluxer/schema/src/domains/channel/ChannelSchemas';
import type {Invite} from '@fluxer/schema/src/domains/invite/InviteSchemas';
const logger = new Logger('Channels');
@@ -34,10 +34,10 @@ export interface ChannelRtcRegion {
emoji: string;
}
export const create = async (
export async function create(
guildId: string,
params: Pick<Channel, 'name' | 'url' | 'type' | 'parent_id' | 'bitrate' | 'user_limit'>,
) => {
) {
try {
const response = await http.post<Channel>(Endpoints.GUILD_CHANNELS(guildId), params);
return response.body;
@@ -45,12 +45,12 @@ export const create = async (
logger.error('Failed to create channel:', error);
throw error;
}
};
}
export const update = async (
export async function update(
channelId: string,
params: Partial<Pick<Channel, 'name' | 'topic' | 'url' | 'nsfw' | 'icon' | 'owner_id' | 'rtc_region'>>,
) => {
) {
try {
const response = await http.patch<Channel>(Endpoints.CHANNEL(channelId), params);
return response.body;
@@ -58,9 +58,9 @@ export const update = async (
logger.error(`Failed to update channel ${channelId}:`, error);
throw error;
}
};
}
export const updateGroupDMNickname = async (channelId: string, userId: string, nickname: string | null) => {
export async function updateGroupDMNickname(channelId: string, userId: string, nickname: string | null) {
try {
const response = await http.patch<Channel>({
url: Endpoints.CHANNEL(channelId),
@@ -75,13 +75,13 @@ export const updateGroupDMNickname = async (channelId: string, userId: string, n
logger.error(`Failed to update nickname for user ${userId} in channel ${channelId}:`, error);
throw error;
}
};
}
export interface RemoveChannelOptions {
optimistic?: boolean;
}
export const remove = async (channelId: string, silent?: boolean, options?: RemoveChannelOptions) => {
export async function remove(channelId: string, silent?: boolean, options?: RemoveChannelOptions) {
const channel = ChannelStore.getChannel(channelId);
const isPrivateChannel =
channel != null && !channel.guildId && (channel.type === ChannelTypes.DM || channel.type === ChannelTypes.GROUP_DM);
@@ -92,8 +92,10 @@ export const remove = async (channelId: string, silent?: boolean, options?: Remo
}
try {
const url = silent ? `${Endpoints.CHANNEL(channelId)}?silent=true` : Endpoints.CHANNEL(channelId);
await http.delete({url});
await http.delete({
url: Endpoints.CHANNEL(channelId),
query: silent ? {silent: true} : undefined,
});
if (shouldOptimisticallyRemove) {
ChannelStore.clearOptimisticallyRemovedChannel(channelId);
}
@@ -104,12 +106,12 @@ export const remove = async (channelId: string, silent?: boolean, options?: Remo
logger.error(`Failed to delete channel ${channelId}:`, error);
throw error;
}
};
}
export const updatePermissionOverwrites = async (
export async function updatePermissionOverwrites(
channelId: string,
permissionOverwrites: Array<{id: string; type: 0 | 1; allow: string; deny: string}>,
) => {
) {
try {
const response = await http.patch<Channel>({
url: Endpoints.CHANNEL(channelId),
@@ -120,9 +122,9 @@ export const updatePermissionOverwrites = async (
logger.error(`Failed to update permission overwrites for channel ${channelId}:`, error);
throw error;
}
};
}
export const fetchChannelInvites = async (channelId: string): Promise<Array<Invite>> => {
export async function fetchChannelInvites(channelId: string): Promise<Array<Invite>> {
try {
InviteStore.handleChannelInvitesFetchPending(channelId);
const response = await http.get<Array<Invite>>({url: Endpoints.CHANNEL_INVITES(channelId)});
@@ -134,9 +136,9 @@ export const fetchChannelInvites = async (channelId: string): Promise<Array<Invi
InviteStore.handleChannelInvitesFetchError(channelId);
throw error;
}
};
}
export const fetchRtcRegions = async (channelId: string): Promise<Array<ChannelRtcRegion>> => {
export async function fetchRtcRegions(channelId: string): Promise<Array<ChannelRtcRegion>> {
try {
const response = await http.get<Array<ChannelRtcRegion>>({url: Endpoints.CHANNEL_RTC_REGIONS(channelId)});
return response.body ?? [];
@@ -144,4 +146,4 @@ export const fetchRtcRegions = async (channelId: string): Promise<Array<ChannelR
logger.error(`Failed to fetch RTC regions for channel ${channelId}:`, error);
throw error;
}
};
}

View File

@@ -17,15 +17,18 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import {APIErrorCodes} from '~/Constants';
import {PinFailedModal, type PinFailureReason} from '~/components/alerts/PinFailedModal';
import {Endpoints} from '~/Endpoints';
import http, {type HttpError} from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {Message} from '~/records/MessageRecord';
import ChannelPinsStore from '~/stores/ChannelPinsStore';
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import {PinFailedModal, type PinFailureReason} from '@app/components/alerts/PinFailedModal';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import type {HttpError} from '@app/lib/HttpError';
import {Logger} from '@app/lib/Logger';
import ChannelPinsStore from '@app/stores/ChannelPinsStore';
import ChannelStore from '@app/stores/ChannelStore';
import GuildNSFWAgreeStore from '@app/stores/GuildNSFWAgreeStore';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import type {Message} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';
interface ApiErrorBody {
code?: string;
@@ -40,6 +43,14 @@ const getApiErrorCode = (error: HttpError): string | undefined => {
const logger = new Logger('Pins');
const PIN_PAGE_SIZE = 25;
const shouldBlockPinsFetch = (channelId: string): boolean => {
const channel = ChannelStore.getChannel(channelId);
if (!channel || channel.isPrivate()) {
return false;
}
return GuildNSFWAgreeStore.shouldShowGate({channelId: channel.id, guildId: channel.guildId ?? null});
};
interface ChannelPinResponse {
message: Message;
pinned_at: string;
@@ -49,7 +60,12 @@ interface ChannelPinsPayload {
has_more: boolean;
}
export const fetch = async (channelId: string) => {
export async function fetch(channelId: string) {
if (shouldBlockPinsFetch(channelId)) {
ChannelPinsStore.handleChannelPinsFetchSuccess(channelId, [], false);
return [];
}
ChannelPinsStore.handleFetchPending(channelId);
try {
const response = await http.get<ChannelPinsPayload>({
@@ -64,9 +80,14 @@ export const fetch = async (channelId: string) => {
ChannelPinsStore.handleChannelPinsFetchError(channelId);
return [];
}
};
}
export async function loadMore(channelId: string): Promise<Array<Message>> {
if (shouldBlockPinsFetch(channelId)) {
ChannelPinsStore.handleChannelPinsFetchSuccess(channelId, [], false);
return [];
}
export const loadMore = async (channelId: string): Promise<Array<Message>> => {
if (!ChannelPinsStore.getHasMore(channelId) || ChannelPinsStore.getIsLoading(channelId)) {
return [];
}
@@ -94,7 +115,7 @@ export const loadMore = async (channelId: string): Promise<Array<Message>> => {
ChannelPinsStore.handleChannelPinsFetchError(channelId);
return [];
}
};
}
const getFailureReason = (error: HttpError): PinFailureReason => {
const errorCode = getApiErrorCode(error);
@@ -104,7 +125,7 @@ const getFailureReason = (error: HttpError): PinFailureReason => {
return 'generic';
};
export const pin = async (channelId: string, messageId: string): Promise<void> => {
export async function pin(channelId: string, messageId: string): Promise<void> {
try {
await http.put({url: Endpoints.CHANNEL_PIN(channelId, messageId)});
logger.debug(`Pinned message ${messageId} in channel ${channelId}`);
@@ -113,9 +134,9 @@ export const pin = async (channelId: string, messageId: string): Promise<void> =
const reason = getFailureReason(error as HttpError);
ModalActionCreators.push(modal(() => <PinFailedModal reason={reason} />));
}
};
}
export const unpin = async (channelId: string, messageId: string): Promise<void> => {
export async function unpin(channelId: string, messageId: string): Promise<void> {
try {
await http.delete({url: Endpoints.CHANNEL_PIN(channelId, messageId)});
logger.debug(`Unpinned message ${messageId} from channel ${channelId}`);
@@ -124,4 +145,4 @@ export const unpin = async (channelId: string, messageId: string): Promise<void>
const reason = getFailureReason(error as HttpError);
ModalActionCreators.push(modal(() => <PinFailedModal isUnpin reason={reason} />));
}
};
}

View File

@@ -17,8 +17,8 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {GuildStickerRecord} from '~/records/GuildStickerRecord';
import ChannelStickerStore from '~/stores/ChannelStickerStore';
import type {GuildStickerRecord} from '@app/records/GuildStickerRecord';
import ChannelStickerStore from '@app/stores/ChannelStickerStore';
export function setPendingSticker(channelId: string, sticker: GuildStickerRecord): void {
ChannelStickerStore.setPendingSticker(channelId, sticker);

View File

@@ -0,0 +1,196 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ToastActionCreators from '@app/actions/ToastActionCreators';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import UserConnectionStore from '@app/stores/UserConnectionStore';
import * as ApiErrorUtils from '@app/utils/ApiErrorUtils';
import type {ConnectionType} from '@fluxer/constants/src/ConnectionConstants';
import type {
ConnectionListResponse,
ConnectionResponse,
ConnectionVerificationResponse,
CreateConnectionRequest,
ReorderConnectionsRequest,
UpdateConnectionRequest,
VerifyAndCreateConnectionRequest,
} from '@fluxer/schema/src/domains/connection/ConnectionSchemas';
import type {I18n, MessageDescriptor} from '@lingui/core';
import {msg} from '@lingui/core/macro';
const logger = new Logger('Connections');
function showErrorToast(i18n: I18n, error: unknown, fallbackMessage: MessageDescriptor): void {
const errorMessage = ApiErrorUtils.getApiErrorMessage(error);
ToastActionCreators.createToast({
type: 'error',
children: errorMessage ?? i18n._(fallbackMessage),
});
}
export async function fetchConnections(): Promise<void> {
try {
const response = await http.get<ConnectionListResponse>(Endpoints.CONNECTIONS);
UserConnectionStore.setConnections(response.body);
logger.debug('Successfully fetched connections');
} catch (error) {
logger.error('Failed to fetch connections:', error);
throw error;
}
}
export async function initiateConnection(
i18n: I18n,
type: ConnectionType,
identifier: string,
): Promise<ConnectionVerificationResponse> {
try {
const payload: CreateConnectionRequest = {
type,
identifier,
};
const response = await http.post<ConnectionVerificationResponse>(Endpoints.CONNECTIONS, payload);
logger.debug(`Successfully initiated connection: ${type}/${identifier}`);
return response.body;
} catch (error) {
logger.error(`Failed to initiate connection ${type}/${identifier}:`, error);
showErrorToast(i18n, error, msg`Failed to initiate connection`);
throw error;
}
}
export async function authorizeBlueskyConnection(i18n: I18n, handle: string): Promise<void> {
try {
const response = await http.post<{authorize_url: string}>(Endpoints.BLUESKY_AUTHORIZE, {handle});
window.open(response.body.authorize_url, '_blank');
} catch (error) {
logger.error(`Failed to start Bluesky OAuth flow for ${handle}:`, error);
showErrorToast(i18n, error, msg`Failed to start Bluesky authorisation`);
throw error;
}
}
export async function verifyAndCreateConnection(
i18n: I18n,
initiationToken: string,
visibilityFlags?: number,
): Promise<ConnectionResponse> {
try {
const payload: VerifyAndCreateConnectionRequest = {
initiation_token: initiationToken,
visibility_flags: visibilityFlags,
};
const response = await http.post<ConnectionResponse>(Endpoints.CONNECTIONS_VERIFY_AND_CREATE, payload);
UserConnectionStore.addConnection(response.body);
ToastActionCreators.createToast({
type: 'success',
children: i18n._(msg`Connection verified`),
});
logger.debug('Successfully verified and created connection');
return response.body;
} catch (error) {
logger.error('Failed to verify and create connection:', error);
showErrorToast(i18n, error, msg`Failed to verify connection`);
throw error;
}
}
export async function updateConnection(
i18n: I18n,
type: string,
connectionId: string,
patch: UpdateConnectionRequest,
): Promise<void> {
try {
await http.patch(Endpoints.CONNECTION(type, connectionId), patch);
UserConnectionStore.updateConnection(connectionId, patch);
ToastActionCreators.createToast({
type: 'success',
children: i18n._(msg`Connection updated`),
});
logger.debug(`Successfully updated connection: ${type}/${connectionId}`);
} catch (error) {
logger.error(`Failed to update connection ${type}/${connectionId}:`, error);
throw error;
}
}
export async function deleteConnection(i18n: I18n, type: string, connectionId: string): Promise<void> {
try {
await http.delete({url: Endpoints.CONNECTION(type, connectionId)});
UserConnectionStore.removeConnection(connectionId);
ToastActionCreators.createToast({
type: 'success',
children: i18n._(msg`Connection removed`),
});
logger.debug(`Successfully deleted connection: ${type}/${connectionId}`);
} catch (error) {
logger.error(`Failed to delete connection ${type}/${connectionId}:`, error);
throw error;
}
}
export async function verifyConnection(i18n: I18n, type: string, connectionId: string): Promise<void> {
try {
const response = await http.post<ConnectionResponse>(Endpoints.CONNECTION_VERIFY(type, connectionId), {});
UserConnectionStore.updateConnection(connectionId, response.body);
ToastActionCreators.createToast({
type: 'success',
children: i18n._(msg`Connection verified`),
});
logger.debug(`Successfully verified connection: ${type}/${connectionId}`);
} catch (error) {
logger.error(`Failed to verify connection ${type}/${connectionId}:`, error);
throw error;
}
}
export async function reorderConnections(i18n: I18n, connectionIds: Array<string>): Promise<void> {
try {
const payload: ReorderConnectionsRequest = {
connection_ids: connectionIds,
};
await http.patch(Endpoints.CONNECTIONS_REORDER, payload);
await fetchConnections();
ToastActionCreators.createToast({
type: 'success',
children: i18n._(msg`Connections reordered`),
});
logger.debug('Successfully reordered connections');
} catch (error) {
logger.error('Failed to reorder connections:', error);
throw error;
}
}

View File

@@ -17,9 +17,9 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {ContextMenu, ContextMenuConfig, ContextMenuTargetElement} from '@app/stores/ContextMenuStore';
import ContextMenuStore from '@app/stores/ContextMenuStore';
import type React from 'react';
import type {ContextMenu, ContextMenuConfig, ContextMenuTargetElement} from '~/stores/ContextMenuStore';
import ContextMenuStore from '~/stores/ContextMenuStore';
const nativeContextMenuTarget: ContextMenuTargetElement = {
tagName: 'ReactNativeContextMenu',
@@ -47,18 +47,18 @@ const toHTMLElement = (value: unknown): HTMLElement | null => {
return null;
};
export const close = (): void => {
export function close(): void {
ContextMenuStore.close();
};
}
type RenderFn = (props: {onClose: () => void}) => React.ReactNode;
export const openAtPoint = (
export function openAtPoint(
point: {x: number; y: number},
render: RenderFn,
config?: ContextMenuConfig,
target: ContextMenuTargetElement = nativeContextMenuTarget,
): void => {
): void {
const contextMenu: ContextMenu = {
id: makeId('context-menu'),
target: {x: point.x, y: point.y, target},
@@ -67,22 +67,22 @@ export const openAtPoint = (
};
ContextMenuStore.open(contextMenu);
};
}
export const openForElement = (
export function openForElement(
element: HTMLElement,
render: RenderFn,
options?: {point?: {x: number; y: number}; config?: ContextMenuConfig},
): void => {
): void {
const point = options?.point ?? getViewportCenterForElement(element);
openAtPoint(point, render, options?.config, element);
};
}
export const openFromEvent = (
export function openFromEvent(
event: React.MouseEvent | MouseEvent,
render: RenderFn,
config?: ContextMenuConfig,
): void => {
): void {
event.preventDefault?.();
event.stopPropagation?.();
@@ -103,13 +103,13 @@ export const openFromEvent = (
: {x: 0, y: 0};
openAtPoint(point, render, config, anchor ?? nativeContextMenuTarget);
};
}
export const openFromElementBottomRight = (
export function openFromElementBottomRight(
event: React.MouseEvent | MouseEvent,
render: RenderFn,
config?: ContextMenuConfig,
): void => {
): void {
event.preventDefault?.();
event.stopPropagation?.();
@@ -128,9 +128,34 @@ export const openFromElementBottomRight = (
const point = {x: rect.right + scrollX, y: rect.bottom + scrollY + 4};
openAtPoint(point, render, {align: 'top-right', ...config}, anchor);
};
}
export const openNativeContextMenu = (render: RenderFn, config?: ContextMenu['config']): void => {
export function openFromElementTopLeft(
event: React.MouseEvent | MouseEvent,
render: RenderFn,
config?: ContextMenuConfig,
): void {
event.preventDefault?.();
event.stopPropagation?.();
const currentTarget = 'currentTarget' in event ? toHTMLElement(event.currentTarget) : null;
const target = 'target' in event ? toHTMLElement(event.target) : null;
const anchor = currentTarget ?? target;
if (!anchor) {
openFromEvent(event, render, config);
return;
}
const rect = anchor.getBoundingClientRect();
const scrollX = window.scrollX || window.pageXOffset || 0;
const scrollY = window.scrollY || window.pageYOffset || 0;
const point = {x: rect.left + scrollX, y: rect.top + scrollY};
openAtPoint(point, render, {align: 'bottom-left', ...config}, anchor);
}
export function openNativeContextMenu(render: RenderFn, config?: ContextMenu['config']): void {
const contextMenu: ContextMenu = {
id: makeId('native-context-menu'),
target: {
@@ -146,4 +171,4 @@ export const openNativeContextMenu = (render: RenderFn, config?: ContextMenu['co
};
ContextMenuStore.open(contextMenu);
};
}

View File

@@ -17,21 +17,24 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {ChannelTypes} from '~/Constants';
import {ComponentDispatch} from '~/lib/ComponentDispatch';
import {Logger} from '~/lib/Logger';
import {type Channel, ChannelRecord} from '~/records/ChannelRecord';
import {type UserPartial, UserRecord} from '~/records/UserRecord';
import DeveloperOptionsStore, {type DeveloperOptionsState} from '~/stores/DeveloperOptionsStore';
import MockIncomingCallStore from '~/stores/MockIncomingCallStore';
import UserStore from '~/stores/UserStore';
import {ComponentDispatch} from '@app/lib/ComponentDispatch';
import {Logger} from '@app/lib/Logger';
import {ChannelRecord} from '@app/records/ChannelRecord';
import {UserRecord} from '@app/records/UserRecord';
import DeveloperOptionsStore, {type DeveloperOptionsState} from '@app/stores/DeveloperOptionsStore';
import MockIncomingCallStore from '@app/stores/MockIncomingCallStore';
import UserStore from '@app/stores/UserStore';
import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';
import type {Channel} from '@fluxer/schema/src/domains/channel/ChannelSchemas';
import type {UserPartial} from '@fluxer/schema/src/domains/user/UserResponseSchemas';
import {generateSnowflake} from '@fluxer/snowflake/src/Snowflake';
const logger = new Logger('DeveloperOptions');
export const updateOption = <K extends keyof DeveloperOptionsState>(key: K, value: DeveloperOptionsState[K]): void => {
export function updateOption<K extends keyof DeveloperOptionsState>(key: K, value: DeveloperOptionsState[K]): void {
logger.debug(`Updating developer option: ${String(key)} = ${value}`);
DeveloperOptionsStore.updateOption(key, value);
};
}
export function setAttachmentMock(
attachmentId: string,
@@ -59,15 +62,15 @@ export function triggerMockIncomingCall(): void {
return;
}
const timestamp = Date.now() - 1420070400000;
const random = Math.floor(Math.random() * 4096);
const mockChannelId = ((timestamp << 22) | random).toString();
const mockChannelId = generateSnowflake().toString();
const initiatorPartial: UserPartial = {
id: currentUser.id,
username: currentUser.username,
discriminator: currentUser.discriminator,
global_name: currentUser.globalName,
avatar: currentUser.avatar ?? null,
avatar_color: currentUser.avatarColor ?? null,
flags: currentUser.flags ?? 0,
};

View File

@@ -17,24 +17,22 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Logger} from '~/lib/Logger';
import DimensionStore from '~/stores/DimensionStore';
import {Logger} from '@app/lib/Logger';
import DimensionStore from '@app/stores/DimensionStore';
const logger = new Logger('DimensionActions');
type GuildId = string;
export const updateChannelListScroll = (guildId: GuildId, scrollTop: number): void => {
export function updateChannelListScroll(guildId: string, scrollTop: number): void {
logger.debug(`Updating channel list scroll: guildId=${guildId}, scrollTop=${scrollTop}`);
DimensionStore.updateGuildDimensions(guildId, scrollTop, undefined);
};
}
export const clearChannelListScrollTo = (guildId: GuildId): void => {
export function clearChannelListScrollTo(guildId: string): void {
logger.debug(`Clearing channel list scroll target: guildId=${guildId}`);
DimensionStore.updateGuildDimensions(guildId, undefined, null);
};
}
export const updateGuildListScroll = (scrollTop: number): void => {
export function updateGuildListScroll(scrollTop: number): void {
logger.debug(`Updating guild list scroll: scrollTop=${scrollTop}`);
DimensionStore.updateGuildListDimensions(scrollTop);
};
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
const logger = new Logger('Discovery');
export interface DiscoveryGuild {
id: string;
name: string;
icon: string | null;
description: string | null;
category_id: number;
member_count: number;
online_count: number;
features: Array<string>;
verification_level: number;
}
interface DiscoverySearchResponse {
guilds: Array<DiscoveryGuild>;
total: number;
}
interface DiscoveryCategory {
id: number;
name: string;
}
export async function searchGuilds(params: {
query?: string;
category?: number;
sort_by?: string;
limit: number;
offset: number;
}): Promise<DiscoverySearchResponse> {
const query: Record<string, string> = {
limit: String(params.limit),
offset: String(params.offset),
};
if (params.query) {
query.query = params.query;
}
if (params.category !== undefined) {
query.category = String(params.category);
}
if (params.sort_by) {
query.sort_by = params.sort_by;
}
const response = await http.get<DiscoverySearchResponse>({
url: Endpoints.DISCOVERY_GUILDS,
query,
});
return response.body;
}
export async function getCategories(): Promise<Array<DiscoveryCategory>> {
const response = await http.get<Array<DiscoveryCategory>>({
url: Endpoints.DISCOVERY_CATEGORIES,
});
return response.body;
}
export async function joinGuild(guildId: string): Promise<void> {
await http.post({
url: Endpoints.DISCOVERY_JOIN(guildId),
});
logger.info('Joined guild via discovery', {guildId});
}

View File

@@ -17,17 +17,17 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Logger} from '~/lib/Logger';
import DraftStore from '~/stores/DraftStore';
import {Logger} from '@app/lib/Logger';
import DraftStore from '@app/stores/DraftStore';
const logger = new Logger('Draft');
export const createDraft = (channelId: string, content: string): void => {
export function createDraft(channelId: string, content: string): void {
logger.debug(`Creating draft for channel ${channelId}`);
DraftStore.createDraft(channelId, content);
};
}
export const deleteDraft = (channelId: string): void => {
export function deleteDraft(channelId: string): void {
logger.debug(`Deleting draft for channel ${channelId}`);
DraftStore.deleteDraft(channelId);
};
}

View File

@@ -17,12 +17,12 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Logger} from '~/lib/Logger';
import EmojiStore from '~/stores/EmojiStore';
import {Logger} from '@app/lib/Logger';
import EmojiStore from '@app/stores/EmojiStore';
const logger = new Logger('Emoji');
export const setSkinTone = (skinTone: string): void => {
export function setSkinTone(skinTone: string): void {
logger.debug(`Setting emoji skin tone: ${skinTone}`);
EmojiStore.setSkinTone(skinTone);
};
}

View File

@@ -17,21 +17,21 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import EmojiPickerStore from '~/stores/EmojiPickerStore';
import type {Emoji} from '~/stores/EmojiStore';
import EmojiPickerStore from '@app/stores/EmojiPickerStore';
import type {FlatEmoji} from '@app/types/EmojiTypes';
function getEmojiKey(emoji: Emoji): string {
function getEmojiKey(emoji: FlatEmoji): string {
if (emoji.id) {
return `custom:${emoji.guildId}:${emoji.id}`;
}
return `unicode:${emoji.uniqueName}`;
}
export function trackEmojiUsage(emoji: Emoji): void {
export function trackEmojiUsage(emoji: FlatEmoji): void {
EmojiPickerStore.trackEmojiUsage(getEmojiKey(emoji));
}
export function toggleFavorite(emoji: Emoji): void {
export function toggleFavorite(emoji: FlatEmoji): void {
EmojiPickerStore.toggleFavorite(getEmojiKey(emoji));
}

View File

@@ -17,28 +17,28 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {ExpressionPickerTabType} from '~/components/popouts/ExpressionPickerPopout';
import {Logger} from '~/lib/Logger';
import ExpressionPickerStore from '~/stores/ExpressionPickerStore';
import type {ExpressionPickerTabType} from '@app/components/popouts/ExpressionPickerPopout';
import {Logger} from '@app/lib/Logger';
import ExpressionPickerStore from '@app/stores/ExpressionPickerStore';
const logger = new Logger('ExpressionPicker');
export const open = (channelId: string, tab?: ExpressionPickerTabType): void => {
export function open(channelId: string, tab?: ExpressionPickerTabType): void {
logger.debug(`Opening expression picker for channel ${channelId}, tab: ${tab}`);
ExpressionPickerStore.open(channelId, tab);
};
}
export const close = (): void => {
export function close(): void {
logger.debug('Closing expression picker');
ExpressionPickerStore.close();
};
}
export const toggle = (channelId: string, tab: ExpressionPickerTabType): void => {
export function toggle(channelId: string, tab: ExpressionPickerTabType): void {
logger.debug(`Toggling expression picker for channel ${channelId}, tab: ${tab}`);
ExpressionPickerStore.toggle(channelId, tab);
};
}
export const setTab = (tab: ExpressionPickerTabType): void => {
export function setTab(tab: ExpressionPickerTabType): void {
logger.debug(`Setting expression picker tab to: ${tab}`);
ExpressionPickerStore.setTab(tab);
};
}

View File

@@ -17,30 +17,24 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import * as ToastActionCreators from '@app/actions/ToastActionCreators';
import {MaxFavoriteMemesModal} from '@app/components/alerts/MaxFavoriteMemesModal';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import type {FavoriteMeme} from '@app/records/FavoriteMemeRecord';
import FavoriteMemeStore from '@app/stores/FavoriteMemeStore';
import {getApiErrorCode} from '@app/utils/ApiErrorUtils';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import {ME} from '@fluxer/constants/src/AppConstants';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import * as ToastActionCreators from '~/actions/ToastActionCreators';
import {APIErrorCodes, ME} from '~/Constants';
import {MaxFavoriteMemesModal} from '~/components/alerts/MaxFavoriteMemesModal';
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {FavoriteMeme} from '~/records/FavoriteMemeRecord';
import FavoriteMemeStore from '~/stores/FavoriteMemeStore';
const logger = new Logger('FavoriteMemes');
const getApiErrorCode = (error: unknown): string | undefined => {
if (typeof error === 'object' && error !== null && 'code' in error) {
const {code} = error as {code?: unknown};
return typeof code === 'string' ? code : undefined;
}
return undefined;
};
export const createFavoriteMeme = async (
export async function createFavoriteMeme(
i18n: I18n,
{
channelId,
@@ -59,7 +53,7 @@ export const createFavoriteMeme = async (
altText?: string;
tags?: Array<string>;
},
): Promise<void> => {
): Promise<void> {
try {
await http.post<FavoriteMeme>(Endpoints.CHANNEL_MESSAGE_FAVORITE_MEMES(channelId, messageId), {
attachment_id: attachmentId,
@@ -84,31 +78,34 @@ export const createFavoriteMeme = async (
throw error;
}
};
}
export const createFavoriteMemeFromUrl = async (
export async function createFavoriteMemeFromUrl(
i18n: I18n,
{
url,
name,
altText,
tags,
tenorId,
klipySlug,
tenorSlugId,
}: {
url: string;
name: string;
altText?: string;
tags?: Array<string>;
tenorId?: string;
klipySlug?: string;
tenorSlugId?: string;
},
): Promise<void> => {
): Promise<void> {
try {
await http.post<FavoriteMeme>(Endpoints.USER_FAVORITE_MEMES(ME), {
url,
name,
alt_text: altText,
tags,
tenor_id: tenorId,
klipy_slug: klipySlug,
tenor_slug_id: tenorSlugId,
});
ToastActionCreators.createToast({
@@ -126,9 +123,9 @@ export const createFavoriteMemeFromUrl = async (
throw error;
}
};
}
export const updateFavoriteMeme = async (
export async function updateFavoriteMeme(
i18n: I18n,
{
memeId,
@@ -141,7 +138,7 @@ export const updateFavoriteMeme = async (
altText?: string | null;
tags?: Array<string>;
},
): Promise<void> => {
): Promise<void> {
try {
const response = await http.patch<FavoriteMeme>(Endpoints.USER_FAVORITE_MEME(ME, memeId), {
name,
@@ -160,9 +157,9 @@ export const updateFavoriteMeme = async (
logger.error(`Failed to update favorite meme ${memeId}:`, error);
throw error;
}
};
}
export const deleteFavoriteMeme = async (i18n: I18n, memeId: string): Promise<void> => {
export async function deleteFavoriteMeme(i18n: I18n, memeId: string): Promise<void> {
try {
await http.delete({url: Endpoints.USER_FAVORITE_MEME(ME, memeId)});
@@ -177,4 +174,4 @@ export const deleteFavoriteMeme = async (i18n: I18n, memeId: string): Promise<vo
logger.error(`Failed to delete favorite meme ${memeId}:`, error);
throw error;
}
};
}

View File

@@ -17,15 +17,15 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as AccessibilityActionCreators from '@app/actions/AccessibilityActionCreators';
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import {ConfirmModal} from '@app/components/modals/ConfirmModal';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
import {Trans} from '@lingui/react/macro';
import * as AccessibilityActionCreators from '~/actions/AccessibilityActionCreators';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import {ConfirmModal} from '~/components/modals/ConfirmModal';
export const confirmHideFavorites = (onConfirm: (() => void) | undefined, i18n: I18n): void => {
export function confirmHideFavorites(onConfirm: (() => void) | undefined, i18n: I18n): void {
ModalActionCreators.push(
modal(() => (
<ConfirmModal
@@ -48,4 +48,4 @@ export const confirmHideFavorites = (onConfirm: (() => void) | undefined, i18n:
/>
)),
);
};
}

View File

@@ -0,0 +1,174 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import RuntimeConfigStore, {type GifProvider} from '@app/stores/RuntimeConfigStore';
import * as LocaleUtils from '@app/utils/LocaleUtils';
const logger = new Logger('GIF');
const getLocale = (): string => LocaleUtils.getCurrentLocale();
export interface Gif {
id: string;
title: string;
url: string;
src: string;
proxy_src: string;
width: number;
height: number;
}
interface GifCategory {
name: string;
src: string;
proxy_src: string;
}
export interface GifFeatured {
categories: Array<GifCategory>;
gifs: Array<Gif>;
}
function getProvider(): GifProvider {
return RuntimeConfigStore.gifProvider;
}
function getProviderEndpoints(provider: GifProvider): {
search: string;
featured: string;
trending: string;
registerShare: string;
suggest: string;
} {
if (provider === 'tenor') {
return {
search: Endpoints.TENOR_SEARCH,
featured: Endpoints.TENOR_FEATURED,
trending: Endpoints.TENOR_TRENDING_GIFS,
registerShare: Endpoints.TENOR_REGISTER_SHARE,
suggest: Endpoints.TENOR_SUGGEST,
};
}
return {
search: Endpoints.KLIPY_SEARCH,
featured: Endpoints.KLIPY_FEATURED,
trending: Endpoints.KLIPY_TRENDING_GIFS,
registerShare: Endpoints.KLIPY_REGISTER_SHARE,
suggest: Endpoints.KLIPY_SUGGEST,
};
}
let featuredCache: Partial<Record<GifProvider, GifFeatured>> = {};
export async function search(q: string): Promise<Array<Gif>> {
const provider = getProvider();
const endpoints = getProviderEndpoints(provider);
try {
logger.debug({provider, q}, 'Searching for GIFs');
const response = await http.get<Array<Gif>>({
url: endpoints.search,
query: {q, locale: getLocale()},
});
return response.body;
} catch (error) {
logger.error({provider, q, error}, 'Failed to search for GIFs');
throw error;
}
}
export async function getFeatured(): Promise<GifFeatured> {
const provider = getProvider();
const endpoints = getProviderEndpoints(provider);
const cached = featuredCache[provider];
if (cached) {
logger.debug({provider}, 'Returning cached featured GIF content');
return cached;
}
try {
logger.debug({provider}, 'Fetching featured GIF content');
const response = await http.get<GifFeatured>({
url: endpoints.featured,
query: {locale: getLocale()},
});
const featured = response.body;
featuredCache[provider] = featured;
return featured;
} catch (error) {
logger.error({provider, error}, 'Failed to fetch featured GIF content');
throw error;
}
}
export async function getTrending(): Promise<Array<Gif>> {
const provider = getProvider();
const endpoints = getProviderEndpoints(provider);
try {
logger.debug({provider}, 'Fetching trending GIFs');
const response = await http.get<Array<Gif>>({
url: endpoints.trending,
query: {locale: getLocale()},
});
return response.body;
} catch (error) {
logger.error({provider, error}, 'Failed to fetch trending GIFs');
throw error;
}
}
export async function registerShare(id: string, q: string): Promise<void> {
const provider = getProvider();
const endpoints = getProviderEndpoints(provider);
try {
logger.debug({provider, id, q}, 'Registering GIF share');
await http.post({url: endpoints.registerShare, body: {id, q, locale: getLocale()}});
} catch (error) {
// Share registration is best-effort; it should never block sending a GIF.
logger.error({provider, id, error}, 'Failed to register GIF share');
}
}
export async function suggest(q: string): Promise<Array<string>> {
const provider = getProvider();
const endpoints = getProviderEndpoints(provider);
try {
logger.debug({provider, q}, 'Getting GIF search suggestions');
const response = await http.get<Array<string>>({
url: endpoints.suggest,
query: {q, locale: getLocale()},
});
return response.body;
} catch (error) {
logger.error({provider, q, error}, 'Failed to get GIF search suggestions');
throw error;
}
}
export function resetFeaturedCache(): void {
featuredCache = {};
}

View File

@@ -17,21 +17,23 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import * as ToastActionCreators from '@app/actions/ToastActionCreators';
import {GenericErrorModal} from '@app/components/alerts/GenericErrorModal';
import {GiftAcceptModal} from '@app/components/modals/GiftAcceptModal';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {HttpError} from '@app/lib/HttpError';
import {Logger} from '@app/lib/Logger';
import DeveloperOptionsStore from '@app/stores/DeveloperOptionsStore';
import GiftStore from '@app/stores/GiftStore';
import UserStore from '@app/stores/UserStore';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import {MS_PER_DAY} from '@fluxer/date_utils/src/DateConstants';
import type {UserPartial} from '@fluxer/schema/src/domains/user/UserResponseSchemas';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import * as ToastActionCreators from '~/actions/ToastActionCreators';
import {APIErrorCodes} from '~/Constants';
import {GenericErrorModal} from '~/components/alerts/GenericErrorModal';
import {GiftAcceptModal} from '~/components/modals/GiftAcceptModal';
import {Endpoints} from '~/Endpoints';
import http, {HttpError} from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {UserPartial} from '~/records/UserRecord';
import DeveloperOptionsStore from '~/stores/DeveloperOptionsStore';
import GiftStore from '~/stores/GiftStore';
import UserStore from '~/stores/UserStore';
interface ApiErrorResponse {
code?: string;
@@ -57,7 +59,7 @@ export interface GiftMetadata {
redeemed_by: UserPartial | null;
}
export const fetch = async (code: string): Promise<Gift> => {
export async function fetch(code: string): Promise<Gift> {
try {
const response = await http.get<Gift>({url: Endpoints.GIFT(code)});
const gift = response.body;
@@ -72,21 +74,21 @@ export const fetch = async (code: string): Promise<Gift> => {
throw error;
}
};
}
export const fetchWithCoalescing = async (code: string): Promise<Gift> => {
export async function fetchWithCoalescing(code: string): Promise<Gift> {
return GiftStore.fetchGift(code);
};
}
export const openAcceptModal = async (code: string): Promise<void> => {
export async function openAcceptModal(code: string): Promise<void> {
void fetchWithCoalescing(code).catch(() => {});
ModalActionCreators.pushWithKey(
modal(() => <GiftAcceptModal code={code} />),
`gift-accept-${code}`,
);
};
}
export const redeem = async (i18n: I18n, code: string): Promise<void> => {
export async function redeem(i18n: I18n, code: string): Promise<void> {
try {
await http.post({url: Endpoints.GIFT_REDEEM(code)});
logger.info('Gift redeemed', {code});
@@ -167,9 +169,9 @@ export const redeem = async (i18n: I18n, code: string): Promise<void> => {
throw error;
}
};
}
export const fetchUserGifts = async (): Promise<Array<GiftMetadata>> => {
export async function fetchUserGifts(): Promise<Array<GiftMetadata>> {
if (DeveloperOptionsStore.mockGiftInventory) {
const currentUser = UserStore.getCurrentUser();
const userPartial: UserPartial = currentUser
@@ -177,20 +179,24 @@ export const fetchUserGifts = async (): Promise<Array<GiftMetadata>> => {
id: currentUser.id,
username: currentUser.username,
discriminator: currentUser.discriminator,
global_name: currentUser.globalName,
avatar: currentUser.avatar,
avatar_color: currentUser.avatarColor ?? null,
flags: currentUser.flags,
}
: {
id: '000000000000000000',
username: 'MockUser',
discriminator: '0000',
global_name: null,
avatar: null,
avatar_color: null,
flags: 0,
};
const now = new Date();
const sevenDaysAgo = new Date(now.getTime() - 7 * 24 * 60 * 60 * 1000);
const twoDaysAgo = new Date(now.getTime() - 2 * 24 * 60 * 60 * 1000);
const sevenDaysAgo = new Date(now.getTime() - 7 * MS_PER_DAY);
const twoDaysAgo = new Date(now.getTime() - 2 * MS_PER_DAY);
const durationMonths = DeveloperOptionsStore.mockGiftDurationMonths ?? 12;
const isRedeemed = DeveloperOptionsStore.mockGiftRedeemed ?? false;
@@ -217,4 +223,4 @@ export const fetchUserGifts = async (): Promise<Array<GiftMetadata>> => {
logger.error('User gifts fetch failed', error);
throw error;
}
};
}

View File

@@ -17,39 +17,22 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {ChannelMoveOperation} from '~/components/layout/utils/channelMoveOperation';
import type {AuditLogActionType} from '~/constants/AuditLogActionType';
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {Guild} from '~/records/GuildRecord';
import type {GuildRole} from '~/records/GuildRoleRecord';
import type {Invite} from '~/records/MessageRecord';
import InviteStore from '~/stores/InviteStore';
import type {ChannelMoveOperation} from '@app/components/layout/utils/ChannelMoveOperation';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import InviteStore from '@app/stores/InviteStore';
import type {AuditLogActionType} from '@fluxer/constants/src/AuditLogActionType';
import type {
AuditLogWebhookResponse,
GuildAuditLogEntryResponse,
} from '@fluxer/schema/src/domains/guild/GuildAuditLogSchemas';
import type {Guild} from '@fluxer/schema/src/domains/guild/GuildResponseSchemas';
import type {GuildRole} from '@fluxer/schema/src/domains/guild/GuildRoleSchemas';
import type {Invite} from '@fluxer/schema/src/domains/invite/InviteSchemas';
import type {UserPartial} from '@fluxer/schema/src/domains/user/UserResponseSchemas';
const logger = new Logger('Guilds');
import type {UserPartial} from '~/records/UserRecord';
export interface AuditLogChangeEntry {
key?: string;
old_value?: unknown;
new_value?: unknown;
oldValue?: unknown;
newValue?: unknown;
}
export type GuildAuditLogChangePayload = Array<AuditLogChangeEntry> | null;
export interface GuildAuditLogEntry {
id: string;
action_type: number;
user_id: string | null;
target_id: string | null;
reason?: string;
options?: Record<string, unknown>;
changes?: GuildAuditLogChangePayload;
}
const logger = new Logger('GuildActionCreators');
export interface GuildAuditLogFetchParams {
userId?: string;
@@ -60,9 +43,9 @@ export interface GuildAuditLogFetchParams {
}
interface GuildAuditLogFetchResponse {
audit_log_entries: Array<GuildAuditLogEntry>;
audit_log_entries: Array<GuildAuditLogEntryResponse>;
users: Array<UserPartial>;
webhooks: Array<unknown>;
webhooks: Array<AuditLogWebhookResponse>;
}
export interface GuildBan {
@@ -79,19 +62,19 @@ export interface GuildBan {
expires_at: string | null;
}
export const create = async (params: Pick<Guild, 'name'> & {icon?: string | null}): Promise<Guild> => {
export async function create(params: Pick<Guild, 'name'> & {icon?: string | null}): Promise<Guild> {
try {
const response = await http.post<Guild>(Endpoints.GUILDS, params);
const guild = response.body;
logger.debug(`Created new guild: ${params.name}`);
logger.debug(`Created new guild: ${params['name']}`);
return guild;
} catch (error) {
logger.error('Failed to create guild:', error);
throw error;
}
};
}
export const update = async (
export async function update(
guildId: string,
params: Partial<
Pick<
@@ -108,12 +91,14 @@ export const update = async (
| 'system_channel_flags'
| 'features'
| 'default_message_notifications'
| 'message_history_cutoff'
| 'verification_level'
| 'mfa_level'
| 'nsfw_level'
| 'explicit_content_filter'
>
>,
): Promise<Guild> => {
): Promise<Guild> {
try {
const response = await http.patch<Guild>(Endpoints.GUILD(guildId), params);
const guild = response.body;
@@ -123,9 +108,9 @@ export const update = async (
logger.error(`Failed to update guild ${guildId}:`, error);
throw error;
}
};
}
export const moveChannel = async (guildId: string, operation: ChannelMoveOperation): Promise<void> => {
export async function moveChannel(guildId: string, operation: ChannelMoveOperation): Promise<void> {
try {
await http.patch({
url: Endpoints.GUILD_CHANNELS(guildId),
@@ -144,9 +129,9 @@ export const moveChannel = async (guildId: string, operation: ChannelMoveOperati
logger.error(`Failed to move channel ${operation.channelId} in guild ${guildId}:`, error);
throw error;
}
};
}
export const getVanityURL = async (guildId: string): Promise<{code: string | null; uses: number}> => {
export async function getVanityURL(guildId: string): Promise<{code: string | null; uses: number}> {
try {
const response = await http.get<{code: string | null; uses: number}>(Endpoints.GUILD_VANITY_URL(guildId));
const result = response.body;
@@ -156,9 +141,9 @@ export const getVanityURL = async (guildId: string): Promise<{code: string | nul
logger.error(`Failed to fetch vanity URL for guild ${guildId}:`, error);
throw error;
}
};
}
export const updateVanityURL = async (guildId: string, code: string | null): Promise<string> => {
export async function updateVanityURL(guildId: string, code: string | null): Promise<string> {
try {
const response = await http.patch<{code: string}>(Endpoints.GUILD_VANITY_URL(guildId), {code});
logger.debug(`Updated vanity URL for guild ${guildId} to ${code || 'none'}`);
@@ -167,9 +152,9 @@ export const updateVanityURL = async (guildId: string, code: string | null): Pro
logger.error(`Failed to update vanity URL for guild ${guildId}:`, error);
throw error;
}
};
}
export const createRole = async (guildId: string, name: string): Promise<void> => {
export async function createRole(guildId: string, name: string): Promise<void> {
try {
await http.post({url: Endpoints.GUILD_ROLES(guildId), body: {name}});
logger.debug(`Created role "${name}" in guild ${guildId}`);
@@ -177,9 +162,9 @@ export const createRole = async (guildId: string, name: string): Promise<void> =
logger.error(`Failed to create role in guild ${guildId}:`, error);
throw error;
}
};
}
export const updateRole = async (guildId: string, roleId: string, patch: Partial<GuildRole>): Promise<void> => {
export async function updateRole(guildId: string, roleId: string, patch: Partial<GuildRole>): Promise<void> {
try {
await http.patch({url: Endpoints.GUILD_ROLE(guildId, roleId), body: patch});
logger.debug(`Updated role ${roleId} in guild ${guildId}`);
@@ -187,9 +172,9 @@ export const updateRole = async (guildId: string, roleId: string, patch: Partial
logger.error(`Failed to update role ${roleId} in guild ${guildId}:`, error);
throw error;
}
};
}
export const deleteRole = async (guildId: string, roleId: string): Promise<void> => {
export async function deleteRole(guildId: string, roleId: string): Promise<void> {
try {
await http.delete({url: Endpoints.GUILD_ROLE(guildId, roleId)});
logger.debug(`Deleted role ${roleId} from guild ${guildId}`);
@@ -197,9 +182,9 @@ export const deleteRole = async (guildId: string, roleId: string): Promise<void>
logger.error(`Failed to delete role ${roleId} from guild ${guildId}:`, error);
throw error;
}
};
}
export const setRoleOrder = async (guildId: string, orderedRoleIds: Array<string>): Promise<void> => {
export async function setRoleOrder(guildId: string, orderedRoleIds: Array<string>): Promise<void> {
try {
const filteredIds = orderedRoleIds.filter((id) => id !== guildId);
const payload = filteredIds.map((id, index) => ({id, position: filteredIds.length - index}));
@@ -209,9 +194,9 @@ export const setRoleOrder = async (guildId: string, orderedRoleIds: Array<string
logger.error(`Failed to update role ordering in guild ${guildId}:`, error);
throw error;
}
};
}
export const setRoleHoistOrder = async (guildId: string, orderedRoleIds: Array<string>): Promise<void> => {
export async function setRoleHoistOrder(guildId: string, orderedRoleIds: Array<string>): Promise<void> {
try {
const filteredIds = orderedRoleIds.filter((id) => id !== guildId);
const payload = filteredIds.map((id, index) => ({id, hoist_position: filteredIds.length - index}));
@@ -221,9 +206,9 @@ export const setRoleHoistOrder = async (guildId: string, orderedRoleIds: Array<s
logger.error(`Failed to update role hoist ordering in guild ${guildId}:`, error);
throw error;
}
};
}
export const resetRoleHoistOrder = async (guildId: string): Promise<void> => {
export async function resetRoleHoistOrder(guildId: string): Promise<void> {
try {
await http.delete({url: Endpoints.GUILD_ROLE_HOIST_POSITIONS(guildId)});
logger.debug(`Reset role hoist ordering in guild ${guildId}`);
@@ -231,9 +216,9 @@ export const resetRoleHoistOrder = async (guildId: string): Promise<void> => {
logger.error(`Failed to reset role hoist ordering in guild ${guildId}:`, error);
throw error;
}
};
}
export const remove = async (guildId: string): Promise<void> => {
export async function remove(guildId: string): Promise<void> {
try {
await http.post({url: Endpoints.GUILD_DELETE(guildId), body: {}});
logger.debug(`Deleted guild ${guildId}`);
@@ -241,9 +226,9 @@ export const remove = async (guildId: string): Promise<void> => {
logger.error(`Failed to delete guild ${guildId}:`, error);
throw error;
}
};
}
export const leave = async (guildId: string): Promise<void> => {
export async function leave(guildId: string): Promise<void> {
try {
await http.delete({url: Endpoints.USER_GUILDS(guildId)});
logger.debug(`Left guild ${guildId}`);
@@ -251,9 +236,9 @@ export const leave = async (guildId: string): Promise<void> => {
logger.error(`Failed to leave guild ${guildId}:`, error);
throw error;
}
};
}
export const fetchGuildInvites = async (guildId: string): Promise<Array<Invite>> => {
export async function fetchGuildInvites(guildId: string): Promise<Array<Invite>> {
try {
InviteStore.handleGuildInvitesFetchPending(guildId);
const response = await http.get<Array<Invite>>(Endpoints.GUILD_INVITES(guildId));
@@ -265,9 +250,9 @@ export const fetchGuildInvites = async (guildId: string): Promise<Array<Invite>>
InviteStore.handleGuildInvitesFetchError(guildId);
throw error;
}
};
}
export const toggleInvitesDisabled = async (guildId: string, disabled: boolean): Promise<Guild> => {
export async function toggleInvitesDisabled(guildId: string, disabled: boolean): Promise<Guild> {
try {
const response = await http.patch<Guild>(Endpoints.GUILD(guildId), {
features: disabled ? ['INVITES_DISABLED'] : [],
@@ -279,9 +264,9 @@ export const toggleInvitesDisabled = async (guildId: string, disabled: boolean):
logger.error(`Failed to ${disabled ? 'disable' : 'enable'} invites for guild ${guildId}:`, error);
throw error;
}
};
}
export const toggleTextChannelFlexibleNames = async (guildId: string, enabled: boolean): Promise<Guild> => {
export async function toggleTextChannelFlexibleNames(guildId: string, enabled: boolean): Promise<Guild> {
try {
const response = await http.patch<Guild>(Endpoints.GUILD_TEXT_CHANNEL_FLEXIBLE_NAMES(guildId), {enabled});
const guild = response.body;
@@ -294,9 +279,9 @@ export const toggleTextChannelFlexibleNames = async (guildId: string, enabled: b
);
throw error;
}
};
}
export const toggleDetachedBanner = async (guildId: string, enabled: boolean): Promise<Guild> => {
export async function toggleDetachedBanner(guildId: string, enabled: boolean): Promise<Guild> {
try {
const response = await http.patch<Guild>(Endpoints.GUILD_DETACHED_BANNER(guildId), {enabled});
const guild = response.body;
@@ -306,24 +291,9 @@ export const toggleDetachedBanner = async (guildId: string, enabled: boolean): P
logger.error(`Failed to ${enabled ? 'enable' : 'disable'} detached banner for guild ${guildId}:`, error);
throw error;
}
};
}
export const toggleDisallowUnclaimedAccounts = async (guildId: string, enabled: boolean): Promise<Guild> => {
try {
const response = await http.patch<Guild>(Endpoints.GUILD_DISALLOW_UNCLAIMED_ACCOUNTS(guildId), {enabled});
const guild = response.body;
logger.debug(`${enabled ? 'Enabled' : 'Disabled'} disallow unclaimed accounts for guild ${guildId}`);
return guild;
} catch (error) {
logger.error(
`Failed to ${enabled ? 'enable' : 'disable'} disallow unclaimed accounts for guild ${guildId}:`,
error,
);
throw error;
}
};
export const transferOwnership = async (guildId: string, newOwnerId: string): Promise<Guild> => {
export async function transferOwnership(guildId: string, newOwnerId: string): Promise<Guild> {
try {
const response = await http.post<Guild>(Endpoints.GUILD_TRANSFER_OWNERSHIP(guildId), {
new_owner_id: newOwnerId,
@@ -335,15 +305,15 @@ export const transferOwnership = async (guildId: string, newOwnerId: string): Pr
logger.error(`Failed to transfer ownership of guild ${guildId}:`, error);
throw error;
}
};
}
export const banMember = async (
export async function banMember(
guildId: string,
userId: string,
deleteMessageDays?: number,
reason?: string,
banDurationSeconds?: number,
): Promise<void> => {
): Promise<void> {
try {
await http.put({
url: Endpoints.GUILD_BAN(guildId, userId),
@@ -358,9 +328,9 @@ export const banMember = async (
logger.error(`Failed to ban user ${userId} from guild ${guildId}:`, error);
throw error;
}
};
}
export const unbanMember = async (guildId: string, userId: string): Promise<void> => {
export async function unbanMember(guildId: string, userId: string): Promise<void> {
try {
await http.delete({url: Endpoints.GUILD_BAN(guildId, userId)});
logger.debug(`Unbanned user ${userId} from guild ${guildId}`);
@@ -368,9 +338,9 @@ export const unbanMember = async (guildId: string, userId: string): Promise<void
logger.error(`Failed to unban user ${userId} from guild ${guildId}:`, error);
throw error;
}
};
}
export const fetchBans = async (guildId: string): Promise<Array<GuildBan>> => {
export async function fetchBans(guildId: string): Promise<Array<GuildBan>> {
try {
const response = await http.get<Array<GuildBan>>(Endpoints.GUILD_BANS(guildId));
const bans = response.body;
@@ -380,12 +350,12 @@ export const fetchBans = async (guildId: string): Promise<Array<GuildBan>> => {
logger.error(`Failed to fetch bans for guild ${guildId}:`, error);
throw error;
}
};
}
export const fetchGuildAuditLogs = async (
export async function fetchGuildAuditLogs(
guildId: string,
params: GuildAuditLogFetchParams,
): Promise<GuildAuditLogFetchResponse> => {
): Promise<GuildAuditLogFetchResponse> {
try {
const query: Record<string, string | number> = {};
if (params.limit !== undefined) query.limit = params.limit;
@@ -406,4 +376,4 @@ export const fetchGuildAuditLogs = async (
logger.error(`Failed to fetch audit logs for guild ${guildId}:`, error);
throw error;
}
};
}

View File

@@ -17,23 +17,23 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {GuildEmojiWithUser} from '~/records/GuildEmojiRecord';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import type {GuildEmojiWithUser} from '@fluxer/schema/src/domains/guild/GuildEmojiSchemas';
const logger = new Logger('Emojis');
export const sanitizeEmojiName = (fileName: string): string => {
export function sanitizeEmojiName(fileName: string): string {
const name =
fileName
.split('.')
.shift()
?.replace(/[^a-zA-Z0-9_]/g, '') ?? '';
return name.padEnd(2, '_').slice(0, 32);
};
}
export const list = async (guildId: string): Promise<ReadonlyArray<GuildEmojiWithUser>> => {
export async function list(guildId: string): Promise<ReadonlyArray<GuildEmojiWithUser>> {
try {
const response = await http.get<ReadonlyArray<GuildEmojiWithUser>>({url: Endpoints.GUILD_EMOJIS(guildId)});
const emojis = response.body;
@@ -43,15 +43,18 @@ export const list = async (guildId: string): Promise<ReadonlyArray<GuildEmojiWit
logger.error(`Failed to list emojis for guild ${guildId}:`, error);
throw error;
}
};
}
export const bulkUpload = async (
export async function bulkUpload(
guildId: string,
emojis: Array<{name: string; image: string}>,
signal?: AbortSignal,
): Promise<{success: Array<any>; failed: Array<{name: string; error: string}>}> => {
): Promise<{success: Array<GuildEmojiWithUser>; failed: Array<{name: string; error: string}>}> {
try {
const response = await http.post<{success: Array<any>; failed: Array<{name: string; error: string}>}>({
const response = await http.post<{
success: Array<GuildEmojiWithUser>;
failed: Array<{name: string; error: string}>;
}>({
url: `${Endpoints.GUILD_EMOJIS(guildId)}/bulk`,
body: {emojis},
signal,
@@ -63,9 +66,9 @@ export const bulkUpload = async (
logger.error(`Failed to bulk upload emojis to guild ${guildId}:`, error);
throw error;
}
};
}
export const update = async (guildId: string, emojiId: string, data: {name: string}): Promise<void> => {
export async function update(guildId: string, emojiId: string, data: {name: string}): Promise<void> {
try {
await http.patch({url: Endpoints.GUILD_EMOJI(guildId, emojiId), body: data});
logger.debug(`Updated emoji ${emojiId} in guild ${guildId}`);
@@ -73,15 +76,17 @@ export const update = async (guildId: string, emojiId: string, data: {name: stri
logger.error(`Failed to update emoji ${emojiId} in guild ${guildId}:`, error);
throw error;
}
};
}
export const remove = async (guildId: string, emojiId: string, purge = false): Promise<void> => {
export async function remove(guildId: string, emojiId: string, purge = false): Promise<void> {
try {
const query = purge ? '?purge=true' : '';
await http.delete({url: `${Endpoints.GUILD_EMOJI(guildId, emojiId)}${query}`});
await http.delete({
url: Endpoints.GUILD_EMOJI(guildId, emojiId),
query: purge ? {purge: true} : undefined,
});
logger.debug(`Removed emoji ${emojiId} from guild ${guildId}`);
} catch (error) {
logger.error(`Failed to remove emoji ${emojiId} from guild ${guildId}:`, error);
throw error;
}
};
}

View File

@@ -17,28 +17,28 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {GuildMember} from '~/records/GuildMemberRecord';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import type {GuildMemberData} from '@fluxer/schema/src/domains/guild/GuildMemberSchemas';
const logger = new Logger('GuildMembers');
export const update = async (
export async function update(
guildId: string,
userId: string,
params: Partial<GuildMember> & {channel_id?: string | null; connection_id?: string},
): Promise<void> => {
params: Partial<GuildMemberData> & {channel_id?: string | null; connection_id?: string},
): Promise<void> {
try {
await http.patch({url: Endpoints.GUILD_MEMBER(guildId, userId), body: params});
logger.debug(`Updated member ${userId} in guild ${guildId}`, {connection_id: params.connection_id});
logger.debug(`Updated member ${userId} in guild ${guildId}`, {connection_id: params['connection_id']});
} catch (error) {
logger.error(`Failed to update member ${userId} in guild ${guildId}:`, error);
throw error;
}
};
}
export const addRole = async (guildId: string, userId: string, roleId: string): Promise<void> => {
export async function addRole(guildId: string, userId: string, roleId: string): Promise<void> {
try {
await http.put({url: Endpoints.GUILD_MEMBER_ROLE(guildId, userId, roleId)});
logger.debug(`Added role ${roleId} to member ${userId} in guild ${guildId}`);
@@ -46,9 +46,9 @@ export const addRole = async (guildId: string, userId: string, roleId: string):
logger.error(`Failed to add role ${roleId} to member ${userId} in guild ${guildId}:`, error);
throw error;
}
};
}
export const removeRole = async (guildId: string, userId: string, roleId: string): Promise<void> => {
export async function removeRole(guildId: string, userId: string, roleId: string): Promise<void> {
try {
await http.delete({url: Endpoints.GUILD_MEMBER_ROLE(guildId, userId, roleId)});
logger.debug(`Removed role ${roleId} from member ${userId} in guild ${guildId}`);
@@ -56,9 +56,9 @@ export const removeRole = async (guildId: string, userId: string, roleId: string
logger.error(`Failed to remove role ${roleId} from member ${userId} in guild ${guildId}:`, error);
throw error;
}
};
}
export const updateProfile = async (
export async function updateProfile(
guildId: string,
params: {
avatar?: string | null;
@@ -69,7 +69,7 @@ export const updateProfile = async (
nick?: string | null;
profile_flags?: number | null;
},
): Promise<void> => {
): Promise<void> {
try {
await http.patch({url: Endpoints.GUILD_MEMBER(guildId), body: params});
logger.debug(`Updated current user's per-guild profile in guild ${guildId}`);
@@ -77,9 +77,9 @@ export const updateProfile = async (
logger.error(`Failed to update current user's per-guild profile in guild ${guildId}:`, error);
throw error;
}
};
}
export const kick = async (guildId: string, userId: string): Promise<void> => {
export async function kick(guildId: string, userId: string): Promise<void> {
try {
await http.delete({url: Endpoints.GUILD_MEMBER(guildId, userId)});
logger.debug(`Kicked member ${userId} from guild ${guildId}`);
@@ -87,14 +87,14 @@ export const kick = async (guildId: string, userId: string): Promise<void> => {
logger.error(`Failed to kick member ${userId} from guild ${guildId}:`, error);
throw error;
}
};
}
export const timeout = async (
export async function timeout(
guildId: string,
userId: string,
communicationDisabledUntil: string | null,
timeoutReason?: string | null,
): Promise<void> => {
): Promise<void> {
try {
const body: Record<string, string | null> = {
communication_disabled_until: communicationDisabledUntil,
@@ -111,4 +111,4 @@ export const timeout = async (
logger.error(`Failed to update timeout for member ${userId} in guild ${guildId}:`, error);
throw error;
}
};
}

View File

@@ -17,8 +17,12 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import GuildNSFWAgreeStore from '~/stores/GuildNSFWAgreeStore';
import GuildNSFWAgreeStore from '@app/stores/GuildNSFWAgreeStore';
export function agreeToNSFWChannel(channelId: string): void {
export function agreeToChannel(channelId: string): void {
GuildNSFWAgreeStore.agreeToChannel(channelId);
}
export function agreeToGuild(guildId: string): void {
GuildNSFWAgreeStore.agreeToGuild(guildId);
}

View File

@@ -17,23 +17,23 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {GuildStickerWithUser} from '~/records/GuildStickerRecord';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import type {GuildStickerWithUser} from '@fluxer/schema/src/domains/guild/GuildEmojiSchemas';
const logger = new Logger('Stickers');
export const sanitizeStickerName = (fileName: string): string => {
export function sanitizeStickerName(fileName: string): string {
const name =
fileName
.split('.')
.shift()
?.replace(/[^a-zA-Z0-9_]/g, '') ?? '';
return name.padEnd(2, '_').slice(0, 30);
};
}
export const list = async (guildId: string): Promise<ReadonlyArray<GuildStickerWithUser>> => {
export async function list(guildId: string): Promise<ReadonlyArray<GuildStickerWithUser>> {
try {
const response = await http.get<ReadonlyArray<GuildStickerWithUser>>({url: Endpoints.GUILD_STICKERS(guildId)});
const stickers = response.body;
@@ -43,12 +43,12 @@ export const list = async (guildId: string): Promise<ReadonlyArray<GuildStickerW
logger.error(`Failed to list stickers for guild ${guildId}:`, error);
throw error;
}
};
}
export const create = async (
export async function create(
guildId: string,
sticker: {name: string; description: string; tags: Array<string>; image: string},
): Promise<void> => {
): Promise<void> {
try {
await http.post({url: Endpoints.GUILD_STICKERS(guildId), body: sticker});
logger.debug(`Created sticker ${sticker.name} in guild ${guildId}`);
@@ -56,13 +56,13 @@ export const create = async (
logger.error(`Failed to create sticker ${sticker.name} in guild ${guildId}:`, error);
throw error;
}
};
}
export const update = async (
export async function update(
guildId: string,
stickerId: string,
data: {name?: string; description?: string; tags?: Array<string>},
): Promise<void> => {
): Promise<void> {
try {
await http.patch({url: Endpoints.GUILD_STICKER(guildId, stickerId), body: data});
logger.debug(`Updated sticker ${stickerId} in guild ${guildId}`);
@@ -70,15 +70,17 @@ export const update = async (
logger.error(`Failed to update sticker ${stickerId} in guild ${guildId}:`, error);
throw error;
}
};
}
export const remove = async (guildId: string, stickerId: string, purge = false): Promise<void> => {
export async function remove(guildId: string, stickerId: string, purge = false): Promise<void> {
try {
const query = purge ? '?purge=true' : '';
await http.delete({url: `${Endpoints.GUILD_STICKER(guildId, stickerId)}${query}`});
await http.delete({
url: Endpoints.GUILD_STICKER(guildId, stickerId),
query: purge ? {purge: true} : undefined,
});
logger.debug(`Removed sticker ${stickerId} from guild ${guildId}`);
} catch (error) {
logger.error(`Failed to remove sticker ${stickerId} from guild ${guildId}:`, error);
throw error;
}
};
}

View File

@@ -17,12 +17,12 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import AutocompleteStore from '~/stores/AutocompleteStore';
import AutocompleteStore from '@app/stores/AutocompleteStore';
export const highlightChannel = (channelId: string): void => {
export function highlightChannel(channelId: string): void {
AutocompleteStore.highlightChannel(channelId);
};
}
export const clearChannelHighlight = (): void => {
export function clearChannelHighlight(): void {
AutocompleteStore.highlightChannelClear();
};
}

View File

@@ -17,18 +17,18 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
const logger = new Logger('IAR');
export const reportMessage = async (
export async function reportMessage(
channelId: string,
messageId: string,
category: string,
additionalInfo?: string,
): Promise<void> => {
): Promise<void> {
try {
logger.debug(`Reporting message ${messageId} in channel ${channelId}`);
await http.post({
@@ -45,14 +45,14 @@ export const reportMessage = async (
logger.error('Failed to submit message report:', error);
throw error;
}
};
}
export const reportUser = async (
export async function reportUser(
userId: string,
category: string,
additionalInfo?: string,
guildId?: string,
): Promise<void> => {
): Promise<void> {
try {
logger.debug(`Reporting user ${userId}${guildId ? ` in guild ${guildId}` : ''}`);
await http.post({
@@ -69,9 +69,9 @@ export const reportUser = async (
logger.error('Failed to submit user report:', error);
throw error;
}
};
}
export const reportGuild = async (guildId: string, category: string, additionalInfo?: string): Promise<void> => {
export async function reportGuild(guildId: string, category: string, additionalInfo?: string): Promise<void> {
try {
logger.debug(`Reporting guild ${guildId}`);
await http.post({
@@ -87,4 +87,4 @@ export const reportGuild = async (guildId: string, category: string, additionalI
logger.error('Failed to submit guild report:', error);
throw error;
}
};
}

View File

@@ -17,9 +17,9 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {InboxTab} from '~/stores/InboxStore';
import InboxStore from '~/stores/InboxStore';
import type {InboxTab} from '@app/stores/InboxStore';
import InboxStore from '@app/stores/InboxStore';
export const setTab = (tab: InboxTab): void => {
export function setTab(tab: InboxTab): void {
InboxStore.setTab(tab);
};
}

View File

@@ -17,47 +17,47 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import * as NavigationActionCreators from '@app/actions/NavigationActionCreators';
import * as ToastActionCreators from '@app/actions/ToastActionCreators';
import {FeatureTemporarilyDisabledModal} from '@app/components/alerts/FeatureTemporarilyDisabledModal';
import {GenericErrorModal} from '@app/components/alerts/GenericErrorModal';
import {GuildAtCapacityModal} from '@app/components/alerts/GuildAtCapacityModal';
import {InviteAcceptFailedModal} from '@app/components/alerts/InviteAcceptFailedModal';
import {InvitesDisabledModal} from '@app/components/alerts/InvitesDisabledModal';
import {MaxGuildsModal} from '@app/components/alerts/MaxGuildsModal';
import {TemporaryInviteRequiresPresenceModal} from '@app/components/alerts/TemporaryInviteRequiresPresenceModal';
import {UserBannedFromGuildModal} from '@app/components/alerts/UserBannedFromGuildModal';
import {UserIpBannedFromGuildModal} from '@app/components/alerts/UserIpBannedFromGuildModal';
import {InviteAcceptModal} from '@app/components/modals/InviteAcceptModal';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {HttpError} from '@app/lib/HttpError';
import {Logger} from '@app/lib/Logger';
import AuthenticationStore from '@app/stores/AuthenticationStore';
import GuildMemberStore from '@app/stores/GuildMemberStore';
import InviteStore from '@app/stores/InviteStore';
import {isGroupDmInvite, isGuildInvite, isPackInvite} from '@app/types/InviteTypes';
import {getApiErrorCode, getApiErrorMessage} from '@app/utils/ApiErrorUtils';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import {ME} from '@fluxer/constants/src/AppConstants';
import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';
import type {Invite} from '@fluxer/schema/src/domains/invite/InviteSchemas';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
import {Trans} from '@lingui/react/macro';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import * as ToastActionCreators from '~/actions/ToastActionCreators';
import {APIErrorCodes} from '~/Constants';
import {FeatureTemporarilyDisabledModal} from '~/components/alerts/FeatureTemporarilyDisabledModal';
import {GenericErrorModal} from '~/components/alerts/GenericErrorModal';
import {GuildAtCapacityModal} from '~/components/alerts/GuildAtCapacityModal';
import {InviteAcceptFailedModal} from '~/components/alerts/InviteAcceptFailedModal';
import {InvitesDisabledModal} from '~/components/alerts/InvitesDisabledModal';
import {MaxGuildsModal} from '~/components/alerts/MaxGuildsModal';
import {TemporaryInviteRequiresPresenceModal} from '~/components/alerts/TemporaryInviteRequiresPresenceModal';
import {UserBannedFromGuildModal} from '~/components/alerts/UserBannedFromGuildModal';
import {UserIpBannedFromGuildModal} from '~/components/alerts/UserIpBannedFromGuildModal';
import {InviteAcceptModal} from '~/components/modals/InviteAcceptModal';
import {Endpoints} from '~/Endpoints';
import http, {HttpError} from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import {Routes} from '~/Routes';
import type {Invite} from '~/records/MessageRecord';
import AuthenticationStore from '~/stores/AuthenticationStore';
import GuildMemberStore from '~/stores/GuildMemberStore';
import InviteStore from '~/stores/InviteStore';
import {isGroupDmInvite, isGuildInvite, isPackInvite} from '~/types/InviteTypes';
import * as RouterUtils from '~/utils/RouterUtils';
const logger = new Logger('Invites');
const extractErrorCode = (error: unknown): string | undefined => {
if (error instanceof HttpError) {
const body = error.body;
if (body && typeof body === 'object' && 'code' in body) {
const {code} = body as {code?: unknown};
return typeof code === 'string' ? code : undefined;
}
}
return undefined;
const isUnclaimedAccountInviteError = (code?: string): boolean => {
return code === APIErrorCodes.UNCLAIMED_ACCOUNT_CANNOT_JOIN_GROUP_DMS;
};
export const fetch = async (code: string): Promise<Invite> => {
const shouldOpenInviteGuildChannel = (channelType: number): boolean =>
channelType !== ChannelTypes.GUILD_CATEGORY && channelType !== ChannelTypes.GUILD_LINK;
export async function fetch(code: string): Promise<Invite> {
try {
logger.debug(`Fetching invite with code ${code}`);
const response = await http.get<Invite>(Endpoints.INVITE(code));
@@ -66,11 +66,11 @@ export const fetch = async (code: string): Promise<Invite> => {
logger.error(`Failed to fetch invite with code ${code}:`, error);
throw error;
}
};
}
export const fetchWithCoalescing = async (code: string): Promise<Invite> => {
export async function fetchWithCoalescing(code: string): Promise<Invite> {
return InviteStore.fetchInvite(code);
};
}
const accept = async (code: string): Promise<Invite> => {
try {
@@ -85,7 +85,7 @@ const accept = async (code: string): Promise<Invite> => {
export const acceptInvite = accept;
export const acceptAndTransitionToChannel = async (code: string, i18n: I18n): Promise<void> => {
export async function acceptAndTransitionToChannel(code: string, i18n: I18n): Promise<void> {
let invite: Invite | null = null;
try {
logger.debug(`Fetching invite details before accepting: ${code}`);
@@ -112,7 +112,7 @@ export const acceptAndTransitionToChannel = async (code: string, i18n: I18n): Pr
const channelId = invite.channel.id;
logger.debug(`Accepting group DM invite ${code} and opening channel ${channelId}`);
await accept(code);
RouterUtils.transitionTo(Routes.dmChannel(channelId));
NavigationActionCreators.selectChannel(ME, channelId);
return;
}
@@ -121,21 +121,31 @@ export const acceptAndTransitionToChannel = async (code: string, i18n: I18n): Pr
}
const channelId = invite.channel.id;
const inviteTargetAllowed = shouldOpenInviteGuildChannel(invite.channel.type);
const targetChannelId = inviteTargetAllowed ? channelId : undefined;
const currentUserId = AuthenticationStore.currentUserId;
const guildId = invite.guild.id;
const isMember = currentUserId ? GuildMemberStore.getMember(guildId, currentUserId) != null : false;
if (isMember) {
logger.debug(`User already in guild ${guildId}, transitioning to channel ${channelId}`);
RouterUtils.transitionTo(Routes.guildChannel(guildId, channelId));
logger.debug(
inviteTargetAllowed
? `User already in guild ${guildId}, transitioning to channel ${channelId}`
: `User already in guild ${guildId}, invite target is non-viewable, transitioning to guild root`,
);
NavigationActionCreators.selectChannel(guildId, targetChannelId);
return;
}
logger.debug(`User not in guild ${guildId}, accepting invite ${code}`);
await accept(code);
logger.debug(`Transitioning to channel ${channelId} in guild ${guildId}`);
RouterUtils.transitionTo(Routes.guildChannel(guildId, channelId));
logger.debug(
inviteTargetAllowed
? `Transitioning to channel ${channelId} in guild ${guildId}`
: `Invite target channel ${channelId} in guild ${guildId} is non-viewable, transitioning to guild root`,
);
NavigationActionCreators.selectChannel(guildId, targetChannelId);
} catch (error) {
const httpError = error instanceof HttpError ? error : null;
const errorCode = extractErrorCode(error);
const errorCode = getApiErrorCode(error);
logger.error(`Failed to accept invite and transition for code ${code}:`, error);
if (httpError?.status === 404 || errorCode === APIErrorCodes.UNKNOWN_INVITE) {
@@ -161,18 +171,7 @@ export const acceptAndTransitionToChannel = async (code: string, i18n: I18n): Pr
ModalActionCreators.push(modal(() => <UserBannedFromGuildModal />));
} else if (errorCode === APIErrorCodes.USER_IP_BANNED_FROM_GUILD) {
ModalActionCreators.push(modal(() => <UserIpBannedFromGuildModal />));
} else if (errorCode === APIErrorCodes.GUILD_DISALLOWS_UNCLAIMED_ACCOUNTS) {
ModalActionCreators.push(
modal(() => (
<GenericErrorModal
title={i18n._(msg`Cannot Join Community`)}
message={i18n._(
msg`This community requires you to verify your account before joining. Please set an email and password for your account.`,
)}
/>
)),
);
} else if (errorCode === APIErrorCodes.UNCLAIMED_ACCOUNT_RESTRICTED) {
} else if (isUnclaimedAccountInviteError(errorCode)) {
ModalActionCreators.push(
modal(() => (
<GenericErrorModal
@@ -189,15 +188,15 @@ export const acceptAndTransitionToChannel = async (code: string, i18n: I18n): Pr
throw error;
}
};
}
export const openAcceptModal = async (code: string): Promise<void> => {
export async function openAcceptModal(code: string): Promise<void> {
void fetchWithCoalescing(code).catch(() => {});
ModalActionCreators.pushWithKey(
modal(() => <InviteAcceptModal code={code} />),
`invite-accept-${code}`,
);
};
}
interface HandlePackInviteErrorParams {
invite: Invite | null;
@@ -215,11 +214,13 @@ interface PackLimitPayload {
const getPackLimitPayload = (httpError?: HttpError | null): PackLimitPayload | null => {
const body = httpError?.body;
if (!body || typeof body !== 'object') return null;
const data = (body as {data?: unknown}).data;
const record = body as Record<string, unknown>;
const data = record.data;
if (!data || typeof data !== 'object') return null;
const limit = (data as {limit?: unknown}).limit;
const packType = (data as {pack_type?: unknown}).pack_type;
const action = (data as {action?: unknown}).action;
const dataRecord = data as Record<string, unknown>;
const limit = dataRecord.limit;
const packType = dataRecord.pack_type;
const action = dataRecord.action;
return {
packType: packType === 'emoji' || packType === 'sticker' ? packType : undefined,
limit: typeof limit === 'number' ? limit : undefined,
@@ -301,7 +302,7 @@ const buildPackLimitStrings = (
}
};
export const handlePackInviteError = (params: HandlePackInviteErrorParams): boolean => {
export function handlePackInviteError(params: HandlePackInviteErrorParams): boolean {
const {invite, errorCode, httpError, i18n} = params;
if (!invite || !isPackInvite(invite)) {
return false;
@@ -321,18 +322,6 @@ export const handlePackInviteError = (params: HandlePackInviteErrorParams): bool
? i18n._(msg`Failed to install this emoji pack. Please try again later.`)
: i18n._(msg`Failed to install this sticker pack. Please try again later.`);
if (errorCode === APIErrorCodes.PREMIUM_REQUIRED) {
ModalActionCreators.push(
modal(() => (
<GenericErrorModal
title={i18n._(msg`Premium required`)}
message={i18n._(msg`Installing emoji and sticker packs requires a premium subscription.`)}
/>
)),
);
return true;
}
if (errorCode === APIErrorCodes.MISSING_ACCESS) {
ModalActionCreators.push(
modal(() => <GenericErrorModal title={cannotInstallTitle} message={cannotInstallMessage} />),
@@ -351,21 +340,18 @@ export const handlePackInviteError = (params: HandlePackInviteErrorParams): bool
return true;
}
const fallbackMessage =
httpError?.body && typeof httpError.body === 'object' && 'message' in httpError.body
? (httpError.body as {message?: unknown}).message?.toString()
: null;
const fallbackMessage = httpError ? getApiErrorMessage(httpError) : null;
ModalActionCreators.push(
modal(() => <GenericErrorModal title={defaultTitle} message={fallbackMessage || defaultMessage} />),
);
return true;
};
}
export const create = async (
export async function create(
channelId: string,
params?: {max_age?: number; max_uses?: number; temporary?: boolean},
): Promise<Invite> => {
): Promise<Invite> {
try {
logger.debug(`Creating invite for channel ${channelId}`);
const response = await http.post<Invite>(Endpoints.CHANNEL_INVITES(channelId), params ?? {});
@@ -374,9 +360,9 @@ export const create = async (
logger.error(`Failed to create invite for channel ${channelId}:`, error);
throw error;
}
};
}
export const list = async (channelId: string): Promise<Array<Invite>> => {
export async function list(channelId: string): Promise<Array<Invite>> {
try {
logger.debug(`Listing invites for channel ${channelId}`);
const response = await http.get<Array<Invite>>(Endpoints.CHANNEL_INVITES(channelId));
@@ -385,9 +371,9 @@ export const list = async (channelId: string): Promise<Array<Invite>> => {
logger.error(`Failed to list invites for channel ${channelId}:`, error);
throw error;
}
};
}
export const remove = async (code: string): Promise<void> => {
export async function remove(code: string): Promise<void> {
try {
logger.debug(`Deleting invite with code ${code}`);
await http.delete({url: Endpoints.INVITE(code)});
@@ -395,4 +381,4 @@ export const remove = async (code: string): Promise<void> => {
logger.error(`Failed to delete invite with code ${code}:`, error);
throw error;
}
};
}

View File

@@ -17,16 +17,16 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import * as LocaleUtils from '~/utils/LocaleUtils';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import * as LocaleUtils from '@app/utils/LocaleUtils';
const logger = new Logger('Tenor');
const logger = new Logger('KLIPY');
const getLocale = (): string => LocaleUtils.getCurrentLocale();
export interface TenorGif {
export interface KlipyGif {
id: string;
title: string;
url: string;
@@ -36,24 +36,24 @@ export interface TenorGif {
height: number;
}
interface TenorCategory {
interface KlipyCategory {
name: string;
src: string;
proxy_src: string;
}
export interface TenorFeatured {
categories: Array<TenorCategory>;
gifs: Array<TenorGif>;
export interface KlipyFeatured {
categories: Array<KlipyCategory>;
gifs: Array<KlipyGif>;
}
let tenorFeaturedCache: TenorFeatured | null = null;
let klipyFeaturedCache: KlipyFeatured | null = null;
export const search = async (q: string): Promise<Array<TenorGif>> => {
export async function search(q: string): Promise<Array<KlipyGif>> {
try {
logger.debug(`Searching for GIFs with query: "${q}"`);
const response = await http.get<Array<TenorGif>>({
url: Endpoints.TENOR_SEARCH,
const response = await http.get<Array<KlipyGif>>({
url: Endpoints.KLIPY_SEARCH,
query: {q, locale: getLocale()},
});
const gifs = response.body;
@@ -63,63 +63,63 @@ export const search = async (q: string): Promise<Array<TenorGif>> => {
logger.error(`Failed to search for GIFs with query "${q}":`, error);
throw error;
}
};
}
export const getFeatured = async (): Promise<TenorFeatured> => {
if (tenorFeaturedCache) {
logger.debug('Returning cached featured Tenor content');
return tenorFeaturedCache;
export async function getFeatured(): Promise<KlipyFeatured> {
if (klipyFeaturedCache) {
logger.debug('Returning cached featured KLIPY content');
return klipyFeaturedCache;
}
try {
logger.debug('Fetching featured Tenor content');
const response = await http.get<TenorFeatured>({
url: Endpoints.TENOR_FEATURED,
logger.debug('Fetching featured KLIPY content');
const response = await http.get<KlipyFeatured>({
url: Endpoints.KLIPY_FEATURED,
query: {locale: getLocale()},
});
const featured = response.body;
tenorFeaturedCache = featured;
klipyFeaturedCache = featured;
logger.debug(
`Fetched featured Tenor content: ${featured.categories.length} categories and ${featured.gifs.length} GIFs`,
`Fetched featured KLIPY content: ${featured.categories.length} categories and ${featured.gifs.length} GIFs`,
);
return featured;
} catch (error) {
logger.error('Failed to fetch featured Tenor content:', error);
logger.error('Failed to fetch featured KLIPY content:', error);
throw error;
}
};
}
export const getTrending = async (): Promise<Array<TenorGif>> => {
export async function getTrending(): Promise<Array<KlipyGif>> {
try {
logger.debug('Fetching trending Tenor GIFs');
const response = await http.get<Array<TenorGif>>({
url: Endpoints.TENOR_TRENDING_GIFS,
logger.debug('Fetching trending KLIPY GIFs');
const response = await http.get<Array<KlipyGif>>({
url: Endpoints.KLIPY_TRENDING_GIFS,
query: {locale: getLocale()},
});
const gifs = response.body;
logger.debug(`Fetched ${gifs.length} trending Tenor GIFs`);
logger.debug(`Fetched ${gifs.length} trending KLIPY GIFs`);
return gifs;
} catch (error) {
logger.error('Failed to fetch trending Tenor GIFs:', error);
logger.error('Failed to fetch trending KLIPY GIFs:', error);
throw error;
}
};
}
export const registerShare = async (id: string, q: string): Promise<void> => {
export async function registerShare(id: string, q: string): Promise<void> {
try {
logger.debug(`Registering GIF share: id=${id}, query="${q}"`);
await http.post({url: Endpoints.TENOR_REGISTER_SHARE, body: {id, q, locale: getLocale()}});
await http.post({url: Endpoints.KLIPY_REGISTER_SHARE, body: {id, q, locale: getLocale()}});
logger.debug(`Successfully registered GIF share for id=${id}`);
} catch (error) {
logger.error(`Failed to register GIF share for id=${id}:`, error);
}
};
}
export const suggest = async (q: string): Promise<Array<string>> => {
export async function suggest(q: string): Promise<Array<string>> {
try {
logger.debug(`Getting Tenor search suggestions for: "${q}"`);
logger.debug(`Getting KLIPY search suggestions for: "${q}"`);
const response = await http.get<Array<string>>({
url: Endpoints.TENOR_SUGGEST,
url: Endpoints.KLIPY_SUGGEST,
query: {q, locale: getLocale()},
});
const suggestions = response.body;
@@ -129,4 +129,4 @@ export const suggest = async (q: string): Promise<Array<string>> => {
logger.error(`Failed to get suggestions for query "${q}":`, error);
throw error;
}
};
}

View File

@@ -17,17 +17,17 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Logger} from '~/lib/Logger';
import MemberListStore from '~/stores/MemberListStore';
import MobileLayoutStore from '~/stores/MobileLayoutStore';
import {Logger} from '@app/lib/Logger';
import MemberListStore from '@app/stores/MemberListStore';
import MobileLayoutStore from '@app/stores/MobileLayoutStore';
const logger = new Logger('Layout');
export const updateMobileLayoutState = (navExpanded: boolean, chatExpanded: boolean): void => {
export function updateMobileLayoutState(navExpanded: boolean, chatExpanded: boolean): void {
logger.debug(`Updating mobile layout state: nav=${navExpanded}, chat=${chatExpanded}`);
MobileLayoutStore.updateState({navExpanded, chatExpanded});
};
}
export const toggleMembers = (_isOpen: boolean): void => {
export function toggleMembers(_isOpen: boolean): void {
MemberListStore.toggleMembers();
};
}

View File

@@ -17,8 +17,8 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {MessageRecord} from '~/records/MessageRecord';
import MediaViewerStore, {type MediaViewerItem} from '~/stores/MediaViewerStore';
import type {MessageRecord} from '@app/records/MessageRecord';
import MediaViewerStore, {type MediaViewerItem} from '@app/stores/MediaViewerStore';
export function openMediaViewer(
items: ReadonlyArray<MediaViewerItem>,

View File

@@ -17,45 +17,63 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import * as ReadStateActionCreators from '~/actions/ReadStateActionCreators';
import {APIErrorCodes, type JumpTypes, MAX_MESSAGES_PER_CHANNEL, MessageFlags} from '~/Constants';
import {FeatureTemporarilyDisabledModal} from '~/components/alerts/FeatureTemporarilyDisabledModal';
import {MessageDeleteFailedModal} from '~/components/alerts/MessageDeleteFailedModal';
import {MessageDeleteTooQuickModal} from '~/components/alerts/MessageDeleteTooQuickModal';
import {ConfirmModal} from '~/components/modals/ConfirmModal';
import {Endpoints} from '~/Endpoints';
import type {JumpOptions} from '~/lib/ChannelMessages';
import http, {HttpError} from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import MessageQueue from '~/lib/MessageQueue';
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import * as NavigationActionCreators from '@app/actions/NavigationActionCreators';
import * as ReadStateActionCreators from '@app/actions/ReadStateActionCreators';
import {FeatureTemporarilyDisabledModal} from '@app/components/alerts/FeatureTemporarilyDisabledModal';
import {MessageDeleteFailedModal} from '@app/components/alerts/MessageDeleteFailedModal';
import {MessageDeleteTooQuickModal} from '@app/components/alerts/MessageDeleteTooQuickModal';
import {ConfirmModal} from '@app/components/modals/ConfirmModal';
import {Endpoints} from '@app/Endpoints';
import type {JumpOptions} from '@app/lib/ChannelMessages';
import {ComponentDispatch} from '@app/lib/ComponentDispatch';
import http from '@app/lib/HttpClient';
import {HttpError} from '@app/lib/HttpError';
import {Logger} from '@app/lib/Logger';
import MessageQueue from '@app/lib/MessageQueue';
import type {MessageRecord} from '@app/records/MessageRecord';
import AuthenticationStore from '@app/stores/AuthenticationStore';
import ChannelStore from '@app/stores/ChannelStore';
import DeveloperOptionsStore from '@app/stores/DeveloperOptionsStore';
import GuildMemberStore from '@app/stores/GuildMemberStore';
import GuildNSFWAgreeStore from '@app/stores/GuildNSFWAgreeStore';
import MessageEditMobileStore from '@app/stores/MessageEditMobileStore';
import MessageEditStore from '@app/stores/MessageEditStore';
import MessageReferenceStore from '@app/stores/MessageReferenceStore';
import MessageReplyStore from '@app/stores/MessageReplyStore';
import MessageStore from '@app/stores/MessageStore';
import ReadStateStore from '@app/stores/ReadStateStore';
import {getApiErrorCode} from '@app/utils/ApiErrorUtils';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import {MessageFlags} from '@fluxer/constants/src/ChannelConstants';
import type {JumpType} from '@fluxer/constants/src/JumpConstants';
import {MAX_MESSAGES_PER_CHANNEL} from '@fluxer/constants/src/LimitConstants';
import type {MessageId} from '@fluxer/schema/src/branded/WireIds';
import type {
AllowedMentions,
Message,
MessageRecord,
MessageReference,
MessageStickerItem,
} from '~/records/MessageRecord';
import AuthenticationStore from '~/stores/AuthenticationStore';
import ChannelStore from '~/stores/ChannelStore';
import DeveloperOptionsStore from '~/stores/DeveloperOptionsStore';
import GuildMemberStore from '~/stores/GuildMemberStore';
import MessageEditMobileStore from '~/stores/MessageEditMobileStore';
import MessageEditStore from '~/stores/MessageEditStore';
import MessageReferenceStore from '~/stores/MessageReferenceStore';
import MessageReplyStore from '~/stores/MessageReplyStore';
import MessageStore from '~/stores/MessageStore';
import ReadStateStore from '~/stores/ReadStateStore';
import * as SnowflakeUtils from '~/utils/SnowflakeUtils';
} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';
import * as SnowflakeUtils from '@fluxer/snowflake/src/SnowflakeUtils';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
const logger = new Logger('MessageActionCreators');
const pendingDeletePromises = new Map<string, Promise<void>>();
const pendingFetchPromises = new Map<string, Promise<Array<Message>>>();
function shouldBlockMessageFetch(channelId: string): boolean {
const channel = ChannelStore.getChannel(channelId);
if (!channel || channel.isPrivate()) {
return false;
}
return GuildNSFWAgreeStore.shouldShowGate({channelId: channel.id, guildId: channel.guildId ?? null});
}
function makeFetchKey(
channelId: string,
before: string | null,
@@ -113,7 +131,9 @@ interface SendMessageParams {
tts?: boolean;
}
export const jumpToPresent = (channelId: string, limit = MAX_MESSAGES_PER_CHANNEL): void => {
export function jumpToPresent(channelId: string, limit = MAX_MESSAGES_PER_CHANNEL): void {
NavigationActionCreators.clearMessageIdForChannel(channelId);
logger.debug(`Jumping to present in channel ${channelId}`);
ReadStateActionCreators.clearStickyUnread(channelId);
@@ -126,26 +146,26 @@ export const jumpToPresent = (channelId: string, limit = MAX_MESSAGES_PER_CHANNE
} else {
fetchMessages(channelId, null, null, limit, jump);
}
};
}
export const jumpToMessage = (
export function jumpToMessage(
channelId: string,
messageId: string,
flash = true,
offset?: number,
returnTargetId?: string,
jumpType?: JumpTypes,
): void => {
jumpType?: JumpType,
): void {
logger.debug(`Jumping to message ${messageId} in channel ${channelId}`);
fetchMessages(channelId, null, null, MAX_MESSAGES_PER_CHANNEL, {
messageId,
messageId: messageId as MessageId,
flash,
offset,
returnMessageId: returnTargetId,
returnMessageId: returnTargetId as MessageId | null | undefined,
jumpType,
});
};
}
const tryFetchMessagesCached = (
channelId: string,
@@ -170,13 +190,13 @@ const tryFetchMessagesCached = (
return false;
};
export const fetchMessages = async (
export async function fetchMessages(
channelId: string,
before: string | null,
after: string | null,
limit: number,
jump?: JumpOptions,
): Promise<Array<Message>> => {
): Promise<Array<Message>> {
const key = makeFetchKey(channelId, before, after, limit, jump);
const inFlight = pendingFetchPromises.get(key);
if (inFlight) {
@@ -184,6 +204,12 @@ export const fetchMessages = async (
return inFlight;
}
if (shouldBlockMessageFetch(channelId)) {
logger.debug(`Skipping message fetch for gated channel ${channelId}`);
MessageStore.handleLoadMessagesBlocked({channelId});
return [];
}
if (tryFetchMessagesCached(channelId, before, after, limit, jump)) {
return [];
}
@@ -271,10 +297,10 @@ export const fetchMessages = async (
pendingFetchPromises.set(key, promise);
promise.finally(() => pendingFetchPromises.delete(key));
return promise;
};
}
export const send = async (channelId: string, params: SendMessageParams): Promise<Message> => {
const promise = new Promise<Message>((resolve, reject) => {
export function send(channelId: string, params: SendMessageParams): Promise<Message | null> {
return new Promise<Message | null>((resolve) => {
logger.debug(`Enqueueing message for channel ${channelId}`);
MessageQueue.enqueue(
@@ -296,28 +322,18 @@ export const send = async (channelId: string, params: SendMessageParams): Promis
logger.debug(`Message sent successfully in channel ${channelId}`);
resolve(result.body);
} else {
const reason = error ?? new Error('Message send failed');
logger.error(`Message send failed in channel ${channelId}`, reason);
reject(reason);
if (error) {
logger.debug(`Message send failed in channel ${channelId}`, error);
}
resolve(null);
}
},
);
});
}
promise.catch((error) => {
logger.error(`Unhandled message send rejection in channel ${channelId}`, error);
});
return promise;
};
export const edit = async (
channelId: string,
messageId: string,
content?: string,
flags?: number,
): Promise<Message> => {
const promise = new Promise<Message>((resolve, reject) => {
export function edit(channelId: string, messageId: string, content?: string, flags?: number): Promise<Message | null> {
return new Promise<Message | null>((resolve) => {
logger.debug(`Enqueueing edit for message ${messageId} in channel ${channelId}`);
MessageQueue.enqueue(
@@ -333,22 +349,17 @@ export const edit = async (
logger.debug(`Message edited successfully: ${messageId} in channel ${channelId}`);
resolve(result.body);
} else {
const reason = error ?? new Error('Message edit failed');
logger.error(`Message edit failed: ${messageId} in channel ${channelId}`, reason);
reject(reason);
if (error) {
logger.debug(`Message edit failed: ${messageId} in channel ${channelId}`, error);
}
resolve(null);
}
},
);
});
}
promise.catch((error) => {
logger.error(`Unhandled message edit rejection for ${messageId} in channel ${channelId}`, error);
});
return promise;
};
export const remove = async (channelId: string, messageId: string): Promise<void> => {
export async function remove(channelId: string, messageId: string): Promise<void> {
const pendingPromise = pendingDeletePromises.get(messageId);
if (pendingPromise) {
logger.debug(`Using in-flight delete request for message ${messageId}`);
@@ -364,9 +375,8 @@ export const remove = async (channelId: string, messageId: string): Promise<void
logger.error(`Failed to delete message ${messageId} in channel ${channelId}:`, error);
if (error instanceof HttpError) {
const {status, body} = error;
const errorCode =
typeof body === 'object' && body != null && 'code' in body ? (body as {code?: string}).code : undefined;
const {status} = error;
const errorCode = getApiErrorCode(error);
if (status === 429) {
ModalActionCreators.push(modal(() => <MessageDeleteTooQuickModal />));
@@ -389,14 +399,14 @@ export const remove = async (channelId: string, messageId: string): Promise<void
pendingDeletePromises.set(messageId, deletePromise);
return deletePromise;
};
}
interface ShowDeleteConfirmationOptions {
message: MessageRecord;
onDelete?: () => void;
}
export const showDeleteConfirmation = (i18n: I18n, {message, onDelete}: ShowDeleteConfirmationOptions): void => {
export function showDeleteConfirmation(i18n: I18n, {message, onDelete}: ShowDeleteConfirmationOptions): void {
ModalActionCreators.push(
modal(() => (
<ConfirmModal
@@ -411,92 +421,100 @@ export const showDeleteConfirmation = (i18n: I18n, {message, onDelete}: ShowDele
/>
)),
);
};
}
export const deleteLocal = (channelId: string, messageId: string): void => {
export function deleteLocal(channelId: string, messageId: string): void {
logger.debug(`Deleting message ${messageId} locally in channel ${channelId}`);
MessageStore.handleMessageDelete({id: messageId, channelId});
};
}
export const revealMessage = (channelId: string, messageId: string | null): void => {
export function revealMessage(channelId: string, messageId: string | null): void {
logger.debug(`Revealing message ${messageId} in channel ${channelId}`);
MessageStore.handleMessageReveal({channelId, messageId});
};
}
export const startReply = (channelId: string, messageId: string, mentioning: boolean): void => {
export function startReply(channelId: string, messageId: string, mentioning: boolean): void {
logger.debug(`Starting reply to message ${messageId} in channel ${channelId}, mentioning=${mentioning}`);
MessageReplyStore.startReply(channelId, messageId, mentioning);
};
ComponentDispatch.dispatch('FOCUS_TEXTAREA', {channelId});
}
export const stopReply = (channelId: string): void => {
export function stopReply(channelId: string): void {
logger.debug(`Stopping reply in channel ${channelId}`);
MessageReplyStore.stopReply(channelId);
};
}
export const setReplyMentioning = (channelId: string, mentioning: boolean): void => {
export function setReplyMentioning(channelId: string, mentioning: boolean): void {
logger.debug(`Setting reply mentioning in channel ${channelId}: ${mentioning}`);
MessageReplyStore.setMentioning(channelId, mentioning);
};
}
export const startEdit = (channelId: string, messageId: string, initialContent: string): void => {
export function startEdit(channelId: string, messageId: string, initialContent: string): void {
logger.debug(`Starting edit for message ${messageId} in channel ${channelId}`);
MessageEditStore.startEditing(channelId, messageId, initialContent);
};
const draftContent = MessageEditStore.getDraftContent(messageId);
const contentToUse = draftContent ?? initialContent;
MessageEditStore.startEditing(channelId, messageId, contentToUse);
}
export const stopEdit = (channelId: string): void => {
export function stopEdit(channelId: string): void {
logger.debug(`Stopping edit in channel ${channelId}`);
MessageEditStore.stopEditing(channelId);
};
}
export const startEditMobile = (channelId: string, messageId: string): void => {
export function startEditMobile(channelId: string, messageId: string): void {
logger.debug(`Starting mobile edit for message ${messageId} in channel ${channelId}`);
MessageEditMobileStore.startEditingMobile(channelId, messageId);
};
}
export const stopEditMobile = (channelId: string): void => {
export function stopEditMobile(channelId: string): void {
logger.debug(`Stopping mobile edit in channel ${channelId}`);
MessageEditMobileStore.stopEditingMobile(channelId);
};
}
export const createOptimistic = (channelId: string, message: Message): void => {
export function createOptimistic(channelId: string, message: Message): void {
logger.debug(`Creating optimistic message in channel ${channelId}`);
MessageStore.handleIncomingMessage({channelId, message});
};
}
export const deleteOptimistic = (channelId: string, messageId: string): void => {
export function deleteOptimistic(channelId: string, messageId: string): void {
logger.debug(`Deleting optimistic message ${messageId} in channel ${channelId}`);
MessageStore.handleMessageDelete({channelId, id: messageId});
};
}
export const sendError = (channelId: string, nonce: string): void => {
export function sendError(channelId: string, nonce: string): void {
logger.debug(`Message send error for nonce ${nonce} in channel ${channelId}`);
MessageStore.handleSendFailed({channelId, nonce});
};
}
export const editOptimistic = (
export function retryLocal(channelId: string, messageId: string): void {
logger.debug(`Retrying optimistic message ${messageId} in channel ${channelId}`);
MessageStore.handleSendRetry({channelId, messageId});
}
export function editOptimistic(
channelId: string,
messageId: string,
content: string,
): {originalContent: string; originalEditedTimestamp: string | null} | null => {
): {originalContent: string; originalEditedTimestamp: string | null} | null {
logger.debug(`Applying optimistic edit for message ${messageId} in channel ${channelId}`);
return MessageStore.handleOptimisticEdit({channelId, messageId, content});
};
}
export const editRollback = (
export function editRollback(
channelId: string,
messageId: string,
originalContent: string,
originalEditedTimestamp: string | null,
): void => {
): void {
logger.debug(`Rolling back edit for message ${messageId} in channel ${channelId}`);
MessageStore.handleEditRollback({channelId, messageId, originalContent, originalEditedTimestamp});
};
}
export const forward = async (
export async function forward(
channelIds: Array<string>,
messageReference: {message_id: string; channel_id: string; guild_id?: string | null},
optionalMessage?: string,
): Promise<void> => {
): Promise<void> {
logger.debug(`Forwarding message ${messageReference.message_id} to ${channelIds.length} channels`);
try {
@@ -527,13 +545,9 @@ export const forward = async (
logger.error('Failed to forward message:', error);
throw error;
}
};
}
export const toggleSuppressEmbeds = async (
channelId: string,
messageId: string,
currentFlags: number,
): Promise<void> => {
export async function toggleSuppressEmbeds(channelId: string, messageId: string, currentFlags: number): Promise<void> {
try {
const isSuppressed = (currentFlags & MessageFlags.SUPPRESS_EMBEDS) === MessageFlags.SUPPRESS_EMBEDS;
const newFlags = isSuppressed
@@ -552,9 +566,9 @@ export const toggleSuppressEmbeds = async (
logger.error('Failed to toggle suppress embeds:', error);
throw error;
}
};
}
export const deleteAttachment = async (channelId: string, messageId: string, attachmentId: string): Promise<void> => {
export async function deleteAttachment(channelId: string, messageId: string, attachmentId: string): Promise<void> {
try {
logger.debug(`Deleting attachment ${attachmentId} from message ${messageId}`);
@@ -567,4 +581,4 @@ export const deleteAttachment = async (channelId: string, messageId: string, att
logger.error('Failed to delete attachment:', error);
throw error;
}
};
}

View File

@@ -17,15 +17,15 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {BackupCode} from '~/records/UserRecord';
import SudoStore from '~/stores/SudoStore';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import SudoStore from '@app/stores/SudoStore';
import type {BackupCode} from '@fluxer/schema/src/domains/user/UserResponseSchemas';
const logger = new Logger('MFA');
export const enableMfaTotp = async (secret: string, code: string): Promise<Array<BackupCode>> => {
export async function enableMfaTotp(secret: string, code: string): Promise<Array<BackupCode>> {
try {
logger.debug('Enabling TOTP-based MFA');
const response = await http.post<{backup_codes: Array<BackupCode>}>({
@@ -40,9 +40,9 @@ export const enableMfaTotp = async (secret: string, code: string): Promise<Array
logger.error('Failed to enable TOTP-based MFA:', error);
throw error;
}
};
}
export const disableMfaTotp = async (code: string): Promise<void> => {
export async function disableMfaTotp(code: string): Promise<void> {
try {
logger.debug('Disabling TOTP-based MFA');
await http.post({url: Endpoints.USER_MFA_TOTP_DISABLE, body: {code}});
@@ -51,9 +51,9 @@ export const disableMfaTotp = async (code: string): Promise<void> => {
logger.error('Failed to disable TOTP-based MFA:', error);
throw error;
}
};
}
export const getBackupCodes = async (regenerate = false): Promise<Array<BackupCode>> => {
export async function getBackupCodes(regenerate = false): Promise<Array<BackupCode>> {
try {
logger.debug(`${regenerate ? 'Regenerating' : 'Fetching'} MFA backup codes`);
const response = await http.post<{backup_codes: Array<BackupCode>}>({
@@ -68,4 +68,4 @@ export const getBackupCodes = async (regenerate = false): Promise<Array<BackupCo
logger.error(`Failed to ${regenerate ? 'regenerate' : 'fetch'} MFA backup codes:`, error);
throw error;
}
};
}

View File

@@ -17,13 +17,14 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {ModalRender} from '@app/actions/ModalRender';
import {ChannelSettingsModal} from '@app/components/modals/ChannelSettingsModal';
import {GuildSettingsModal} from '@app/components/modals/GuildSettingsModal';
import {UserSettingsModal} from '@app/components/modals/UserSettingsModal';
import {Logger} from '@app/lib/Logger';
import ModalStore from '@app/stores/ModalStore';
import lodash from 'lodash';
import type React from 'react';
import {ChannelSettingsModal} from '~/components/modals/ChannelSettingsModal';
import {GuildSettingsModal} from '~/components/modals/GuildSettingsModal';
import {UserSettingsModal} from '~/components/modals/UserSettingsModal';
import {Logger} from '~/lib/Logger';
import ModalStore from '~/stores/ModalStore';
const logger = new Logger('Modal');
@@ -33,18 +34,11 @@ const isBackgroundModal = (element: React.ReactElement): boolean => {
return BACKGROUND_MODAL_TYPES.some((type) => element.type === type);
};
declare const ModalRenderBrand: unique symbol;
export interface ModalRender {
(): React.ReactElement;
[ModalRenderBrand]: true;
}
export function modal(render: () => React.ReactElement): ModalRender {
return render as ModalRender;
}
export const push = (modal: ModalRender): void => {
export function push(modal: ModalRender): void {
const renderedModal = modal();
const isBackground = isBackgroundModal(renderedModal);
@@ -64,9 +58,9 @@ export const push = (modal: ModalRender): void => {
const key = lodash.uniqueId('modal');
logger.debug(`Pushing modal: ${key} (background=${isBackground})`);
ModalStore.push(modal, key, {isBackground});
};
}
export const pushWithKey = (modal: ModalRender, key: string): void => {
export function pushWithKey(modal: ModalRender, key: string): void {
const renderedModal = modal();
const isBackground = isBackgroundModal(renderedModal);
@@ -91,24 +85,29 @@ export const pushWithKey = (modal: ModalRender, key: string): void => {
logger.debug(`Pushing modal with key: ${key} (background=${isBackground})`);
ModalStore.push(modal, key, {isBackground});
};
}
export const update = (key: string, updater: (currentModal: ModalRender) => ModalRender): void => {
export function update(key: string, updater: (currentModal: ModalRender) => ModalRender): void {
logger.debug(`Updating modal with key: ${key}`);
ModalStore.update(key, updater);
};
}
export const pop = (): void => {
export function pop(): void {
logger.debug('Popping most recent modal');
ModalStore.pop();
};
}
export const popWithKey = (key: string): void => {
export function popWithKey(key: string): void {
logger.debug(`Popping modal with key: ${key}`);
ModalStore.pop(key);
};
}
export const popAll = (): void => {
export function popByType<T>(component: React.ComponentType<T>): void {
logger.debug(`Popping modal by type: ${component.displayName ?? component.name ?? 'unknown'}`);
ModalStore.popByType(component);
}
export function popAll(): void {
logger.debug('Popping all modals');
ModalStore.popAll();
};
}

View File

@@ -0,0 +1,22 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type React from 'react';
export type ModalRender = () => React.ReactElement;

View File

@@ -17,32 +17,32 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import NagbarStore, {type NagbarToggleKey} from '~/stores/NagbarStore';
import NagbarStore, {type NagbarToggleKey} from '@app/stores/NagbarStore';
export const dismissNagbar = (nagbarType: NagbarToggleKey): void => {
export function dismissNagbar(nagbarType: NagbarToggleKey): void {
NagbarStore.dismiss(nagbarType);
};
}
export const dismissInvitesDisabledNagbar = (guildId: string): void => {
export function dismissInvitesDisabledNagbar(guildId: string): void {
NagbarStore.dismissInvitesDisabled(guildId);
};
}
export const resetNagbar = (nagbarType: NagbarToggleKey): void => {
export function resetNagbar(nagbarType: NagbarToggleKey): void {
NagbarStore.reset(nagbarType);
};
}
export const resetAllNagbars = (): void => {
export function resetAllNagbars(): void {
NagbarStore.resetAll();
};
}
export const setForceHideNagbar = (key: NagbarToggleKey, value: boolean): void => {
export function setForceHideNagbar(key: NagbarToggleKey, value: boolean): void {
NagbarStore.setFlag(key, value);
};
}
export const dismissPendingBulkDeletionNagbar = (scheduleKey: string): void => {
export function dismissPendingBulkDeletionNagbar(scheduleKey: string): void {
NagbarStore.dismissPendingBulkDeletion(scheduleKey);
};
}
export const clearPendingBulkDeletionNagbarDismissal = (scheduleKey: string): void => {
export function clearPendingBulkDeletionNagbarDismissal(scheduleKey: string): void {
NagbarStore.clearPendingBulkDeletionDismissed(scheduleKey);
};
}

View File

@@ -17,27 +17,66 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Logger} from '~/lib/Logger';
import MessageStore from '~/stores/MessageStore';
import NotificationStore from '~/stores/NotificationStore';
import SelectedChannelStore from '~/stores/SelectedChannelStore';
import SelectedGuildStore from '~/stores/SelectedGuildStore';
import {Logger} from '@app/lib/Logger';
import NavigationStore from '@app/stores/NavigationStore';
import {FAVORITES_GUILD_ID, ME} from '@fluxer/constants/src/AppConstants';
const logger = new Logger('Navigation');
export const selectChannel = (guildId?: string, channelId?: string | null, messageId?: string): void => {
type NavigationMode = 'push' | 'replace';
export function selectChannel(
guildId?: string,
channelId?: string | null,
messageId?: string,
mode: NavigationMode = 'push',
): void {
logger.debug(`Selecting channel: guildId=${guildId}, channelId=${channelId}, messageId=${messageId}`);
MessageStore.handleChannelSelect({guildId, channelId, messageId});
NotificationStore.handleChannelSelect({channelId});
SelectedChannelStore.selectChannel(guildId, channelId);
};
export const selectGuild = (guildId: string): void => {
if (!guildId || guildId === ME) {
NavigationStore.navigateToDM(channelId ?? undefined, messageId, mode);
} else if (guildId === FAVORITES_GUILD_ID || guildId === '@favorites') {
NavigationStore.navigateToFavorites(channelId ?? undefined, messageId, mode);
} else {
NavigationStore.navigateToGuild(guildId, channelId ?? undefined, messageId, mode);
}
}
export function selectGuild(guildId: string, channelId?: string, mode: NavigationMode = 'push'): void {
logger.debug(`Selecting guild: ${guildId}`);
SelectedGuildStore.selectGuild(guildId);
};
export const deselectGuild = (): void => {
if (guildId === ME) {
NavigationStore.navigateToDM(channelId, undefined, mode);
} else if (guildId === FAVORITES_GUILD_ID || guildId === '@favorites') {
NavigationStore.navigateToFavorites(channelId, undefined, mode);
} else {
NavigationStore.navigateToGuild(guildId, channelId, undefined, mode);
}
}
export function deselectGuild(): void {
logger.debug('Deselecting guild');
SelectedGuildStore.deselectGuild();
};
NavigationStore.navigateToDM();
}
export function navigateToMessage(
guildId: string | null | undefined,
channelId: string,
messageId: string,
mode: NavigationMode = 'push',
): void {
logger.debug(`Navigating to message: channel=${channelId}, message=${messageId}`);
if (!guildId || guildId === ME) {
NavigationStore.navigateToDM(channelId, messageId, mode);
} else if (guildId === FAVORITES_GUILD_ID || guildId === '@favorites') {
NavigationStore.navigateToFavorites(channelId, messageId, mode);
} else {
NavigationStore.navigateToGuild(guildId, channelId, messageId, mode);
}
}
export function clearMessageIdForChannel(channelId: string, mode: NavigationMode = 'replace'): void {
logger.debug(`Clearing messageId for channel: ${channelId}`);
NavigationStore.clearMessageIdForChannel(channelId, mode);
}

View File

@@ -17,18 +17,18 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import {ConfirmModal} from '@app/components/modals/ConfirmModal';
import {Logger} from '@app/lib/Logger';
import NotificationStore from '@app/stores/NotificationStore';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
import {Trans} from '@lingui/react/macro';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import {ConfirmModal} from '~/components/modals/ConfirmModal';
import {Logger} from '~/lib/Logger';
import NotificationStore from '~/stores/NotificationStore';
const logger = new Logger('Notification');
export const permissionDenied = (i18n: I18n, suppressModal = false): void => {
export function permissionDenied(i18n: I18n, suppressModal = false): void {
logger.debug('Notification permission denied');
NotificationStore.handleNotificationPermissionDenied();
@@ -53,13 +53,13 @@ export const permissionDenied = (i18n: I18n, suppressModal = false): void => {
/>
)),
);
};
}
export const permissionGranted = (): void => {
export function permissionGranted(): void {
logger.debug('Notification permission granted');
NotificationStore.handleNotificationPermissionGranted();
};
}
export const toggleUnreadMessageBadge = (enabled: boolean): void => {
export function toggleUnreadMessageBadge(enabled: boolean): void {
NotificationStore.handleNotificationSoundToggle(enabled);
};
}

View File

@@ -17,9 +17,9 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
const logger = new Logger('OAuth2AuthorizationActionCreators');
@@ -35,7 +35,7 @@ export interface OAuth2Authorization {
authorized_at: string;
}
export const listAuthorizations = async (): Promise<Array<OAuth2Authorization>> => {
export async function listAuthorizations(): Promise<Array<OAuth2Authorization>> {
try {
const response = await http.get<Array<OAuth2Authorization>>({url: Endpoints.OAUTH_AUTHORIZATIONS});
return response.body;
@@ -43,13 +43,13 @@ export const listAuthorizations = async (): Promise<Array<OAuth2Authorization>>
logger.error('Failed to list OAuth2 authorizations:', error);
throw error;
}
};
}
export const deauthorize = async (applicationId: string): Promise<void> => {
export async function deauthorize(applicationId: string): Promise<void> {
try {
await http.delete({url: Endpoints.OAUTH_AUTHORIZATION(applicationId)});
} catch (error) {
logger.error('Failed to deauthorize application:', error);
throw error;
}
};
}

View File

@@ -17,14 +17,14 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {PackDashboardResponse, PackSummary} from '~/types/PackTypes';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import type {PackDashboardResponse, PackSummaryResponse} from '@fluxer/schema/src/domains/pack/PackSchemas';
const logger = new Logger('Packs');
export const list = async (): Promise<PackDashboardResponse> => {
export async function list(): Promise<PackDashboardResponse> {
try {
logger.debug('Requesting pack dashboard');
const response = await http.get<PackDashboardResponse>({url: Endpoints.PACKS});
@@ -33,16 +33,16 @@ export const list = async (): Promise<PackDashboardResponse> => {
logger.error('Failed to fetch pack dashboard:', error);
throw error;
}
};
}
export const create = async (
export async function create(
type: 'emoji' | 'sticker',
name: string,
description?: string | null,
): Promise<PackSummary> => {
): Promise<PackSummaryResponse> {
try {
logger.debug(`Creating ${type} pack ${name}`);
const response = await http.post<PackSummary>({
const response = await http.post<PackSummaryResponse>({
url: Endpoints.PACK_CREATE(type),
body: {name, description: description ?? null},
});
@@ -51,23 +51,23 @@ export const create = async (
logger.error(`Failed to create ${type} pack:`, error);
throw error;
}
};
}
export const update = async (
export async function update(
packId: string,
data: {name?: string; description?: string | null},
): Promise<PackSummary> => {
): Promise<PackSummaryResponse> {
try {
logger.debug(`Updating pack ${packId}`);
const response = await http.patch<PackSummary>({url: Endpoints.PACK(packId), body: data});
const response = await http.patch<PackSummaryResponse>({url: Endpoints.PACK(packId), body: data});
return response.body;
} catch (error) {
logger.error(`Failed to update pack ${packId}:`, error);
throw error;
}
};
}
export const remove = async (packId: string): Promise<void> => {
export async function remove(packId: string): Promise<void> {
try {
logger.debug(`Deleting pack ${packId}`);
await http.delete({url: Endpoints.PACK(packId)});
@@ -75,9 +75,9 @@ export const remove = async (packId: string): Promise<void> => {
logger.error(`Failed to delete pack ${packId}:`, error);
throw error;
}
};
}
export const install = async (packId: string): Promise<void> => {
export async function install(packId: string): Promise<void> {
try {
logger.debug(`Installing pack ${packId}`);
await http.post({url: Endpoints.PACK_INSTALL(packId)});
@@ -85,9 +85,9 @@ export const install = async (packId: string): Promise<void> => {
logger.error(`Failed to install pack ${packId}:`, error);
throw error;
}
};
}
export const uninstall = async (packId: string): Promise<void> => {
export async function uninstall(packId: string): Promise<void> {
try {
logger.debug(`Uninstalling pack ${packId}`);
await http.delete({url: Endpoints.PACK_INSTALL(packId)});
@@ -95,4 +95,4 @@ export const uninstall = async (packId: string): Promise<void> => {
logger.error(`Failed to uninstall pack ${packId}:`, error);
throw error;
}
};
}

View File

@@ -17,10 +17,10 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {PackInviteMetadata} from '~/types/PackTypes';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import type {PackInviteMetadataResponse} from '@fluxer/schema/src/domains/invite/InviteSchemas';
const logger = new Logger('PackInvites');
@@ -31,10 +31,10 @@ export interface CreatePackInviteParams {
unique?: boolean;
}
export const createInvite = async (params: CreatePackInviteParams): Promise<PackInviteMetadata> => {
export async function createInvite(params: CreatePackInviteParams): Promise<PackInviteMetadataResponse> {
try {
logger.debug(`Creating invite for pack ${params.packId}`);
const response = await http.post<PackInviteMetadata>({
const response = await http.post<PackInviteMetadataResponse>({
url: Endpoints.PACK_INVITES(params.packId),
body: {
max_uses: params.maxUses ?? 0,
@@ -47,4 +47,4 @@ export const createInvite = async (params: CreatePackInviteParams): Promise<Pack
logger.error(`Failed to create invite for pack ${params.packId}:`, error);
throw error;
}
};
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import PiPStore, {type PiPContent, type PiPCorner} from '@app/stores/PiPStore';
export function openPiP(content: PiPContent): void {
PiPStore.open(content);
}
export function closePiP(): void {
PiPStore.close();
}
export function showFocusedTileMirror(content: PiPContent, corner: PiPCorner = 'top-right'): void {
PiPStore.showFocusedTileMirror(content, corner);
}
export function hideFocusedTileMirror(): void {
PiPStore.hideFocusedTileMirror();
}

View File

@@ -17,17 +17,17 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {Popout} from '~/components/uikit/Popout';
import PopoutStore from '~/stores/PopoutStore';
import type {Popout} from '@app/components/uikit/popout';
import PopoutStore from '@app/stores/PopoutStore';
export const open = (popout: Popout): void => {
export function open(popout: Popout): void {
PopoutStore.open(popout);
};
}
export const close = (key?: string | number): void => {
export function close(key?: string | number): void {
PopoutStore.close(key);
};
}
export const closeAll = (): void => {
export function closeAll(): void {
PopoutStore.closeAll();
};
}

View File

@@ -17,53 +17,30 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import type {PriceIdsResponse} from '@fluxer/schema/src/domains/premium/PremiumSchemas';
const logger = new Logger('Premium');
export interface VisionarySlots {
total: number;
remaining: number;
}
export type PriceIds = PriceIdsResponse;
export interface PriceIds {
monthly: string | null;
yearly: string | null;
visionary: string | null;
giftVisionary: string | null;
gift1Month: string | null;
gift1Year: string | null;
currency: 'USD' | 'EUR';
}
export const fetchVisionarySlots = async (): Promise<VisionarySlots> => {
export async function fetchPriceIds(countryCode?: string): Promise<PriceIds> {
try {
const response = await http.get<VisionarySlots>(Endpoints.PREMIUM_VISIONARY_SLOTS);
logger.debug('Visionary slots fetched', response.body);
return response.body;
} catch (error) {
logger.error('Visionary slots fetch failed', error);
throw error;
}
};
export const fetchPriceIds = async (countryCode?: string): Promise<PriceIds> => {
try {
const url = countryCode
? `${Endpoints.PREMIUM_PRICE_IDS}?country_code=${encodeURIComponent(countryCode)}`
: Endpoints.PREMIUM_PRICE_IDS;
const response = await http.get<PriceIds>(url);
const response = await http.get<PriceIds>({
url: Endpoints.PREMIUM_PRICE_IDS,
query: countryCode ? {country_code: countryCode} : undefined,
});
logger.debug('Price IDs fetched', response.body);
return response.body;
} catch (error) {
logger.error('Price IDs fetch failed', error);
throw error;
}
};
}
export const createCustomerPortalSession = async (): Promise<string> => {
export async function createCustomerPortalSession(): Promise<string> {
try {
const response = await http.post<{url: string}>(Endpoints.PREMIUM_CUSTOMER_PORTAL);
logger.info('Customer portal session created');
@@ -72,9 +49,9 @@ export const createCustomerPortalSession = async (): Promise<string> => {
logger.error('Customer portal session creation failed', error);
throw error;
}
};
}
export const createCheckoutSession = async (priceId: string, isGift: boolean = false): Promise<string> => {
export async function createCheckoutSession(priceId: string, isGift: boolean = false): Promise<string> {
try {
const url = isGift ? Endpoints.STRIPE_CHECKOUT_GIFT : Endpoints.STRIPE_CHECKOUT_SUBSCRIPTION;
const response = await http.post<{url: string}>(url, {price_id: priceId});
@@ -84,9 +61,9 @@ export const createCheckoutSession = async (priceId: string, isGift: boolean = f
logger.error('Checkout session creation failed', error);
throw error;
}
};
}
export const cancelSubscriptionAtPeriodEnd = async (): Promise<void> => {
export async function cancelSubscriptionAtPeriodEnd(): Promise<void> {
try {
await http.post({url: Endpoints.PREMIUM_CANCEL_SUBSCRIPTION});
logger.info('Subscription set to cancel at period end');
@@ -94,9 +71,9 @@ export const cancelSubscriptionAtPeriodEnd = async (): Promise<void> => {
logger.error('Failed to cancel subscription at period end', error);
throw error;
}
};
}
export const reactivateSubscription = async (): Promise<void> => {
export async function reactivateSubscription(): Promise<void> {
try {
await http.post({url: Endpoints.PREMIUM_REACTIVATE_SUBSCRIPTION});
logger.info('Subscription reactivated');
@@ -104,9 +81,9 @@ export const reactivateSubscription = async (): Promise<void> => {
logger.error('Failed to reactivate subscription', error);
throw error;
}
};
}
export const rejoinVisionaryGuild = async (): Promise<void> => {
export async function rejoinVisionaryGuild(): Promise<void> {
try {
await http.post({url: Endpoints.PREMIUM_VISIONARY_REJOIN});
logger.info('Visionary guild rejoin requested');
@@ -114,9 +91,9 @@ export const rejoinVisionaryGuild = async (): Promise<void> => {
logger.error('Failed to rejoin Visionary guild', error);
throw error;
}
};
}
export const rejoinOperatorGuild = async (): Promise<void> => {
export async function rejoinOperatorGuild(): Promise<void> {
try {
await http.post({url: Endpoints.PREMIUM_OPERATOR_REJOIN});
logger.info('Operator guild rejoin requested');
@@ -124,4 +101,4 @@ export const rejoinOperatorGuild = async (): Promise<void> => {
logger.error('Failed to rejoin Operator guild', error);
throw error;
}
};
}

View File

@@ -17,16 +17,16 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import {PremiumModal} from '~/components/modals/PremiumModal';
import RuntimeConfigStore from '~/stores/RuntimeConfigStore';
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import {PremiumModal} from '@app/components/modals/PremiumModal';
import RuntimeConfigStore from '@app/stores/RuntimeConfigStore';
interface OpenOptions {
defaultGiftMode?: boolean;
}
export const open = (optionsOrDefaultGiftMode: OpenOptions | boolean = {}): void => {
export function open(optionsOrDefaultGiftMode: OpenOptions | boolean = {}): void {
if (RuntimeConfigStore.isSelfHosted()) {
return;
}
@@ -37,4 +37,4 @@ export const open = (optionsOrDefaultGiftMode: OpenOptions | boolean = {}): void
: optionsOrDefaultGiftMode;
const {defaultGiftMode = false} = options;
ModalActionCreators.push(modal(() => <PremiumModal defaultGiftMode={defaultGiftMode} />));
};
}

View File

@@ -17,18 +17,18 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {ChannelTypes} from '~/Constants';
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import {Routes} from '~/Routes';
import type {Channel} from '~/records/ChannelRecord';
import ChannelStore from '~/stores/ChannelStore';
import * as RouterUtils from '~/utils/RouterUtils';
import * as NavigationActionCreators from '@app/actions/NavigationActionCreators';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import ChannelStore from '@app/stores/ChannelStore';
import {ME} from '@fluxer/constants/src/AppConstants';
import {ChannelTypes} from '@fluxer/constants/src/ChannelConstants';
import type {Channel} from '@fluxer/schema/src/domains/channel/ChannelSchemas';
const logger = new Logger('PrivateChannelActionCreators');
export const create = async (userId: string) => {
export async function create(userId: string) {
try {
const response = await http.post<Channel>({
url: Endpoints.USER_CHANNELS,
@@ -40,9 +40,9 @@ export const create = async (userId: string) => {
logger.error('Failed to create private channel:', error);
throw error;
}
};
}
export const createGroupDM = async (recipientIds: Array<string>) => {
export async function createGroupDM(recipientIds: Array<string>) {
try {
const response = await http.post<Channel>({
url: Endpoints.USER_CHANNELS,
@@ -54,9 +54,9 @@ export const createGroupDM = async (recipientIds: Array<string>) => {
logger.error('Failed to create group DM:', error);
throw error;
}
};
}
export const removeRecipient = async (channelId: string, userId: string) => {
export async function removeRecipient(channelId: string, userId: string) {
try {
await http.delete({
url: Endpoints.CHANNEL_RECIPIENT(channelId, userId),
@@ -65,9 +65,9 @@ export const removeRecipient = async (channelId: string, userId: string) => {
logger.error('Failed to remove recipient:', error);
throw error;
}
};
}
export const ensureDMChannel = async (userId: string): Promise<string> => {
export async function ensureDMChannel(userId: string): Promise<string> {
try {
const existingChannels = ChannelStore.dmChannels;
const existingChannel = existingChannels.find(
@@ -84,19 +84,19 @@ export const ensureDMChannel = async (userId: string): Promise<string> => {
logger.error('Failed to ensure DM channel:', error);
throw error;
}
};
}
export const openDMChannel = async (userId: string): Promise<void> => {
export async function openDMChannel(userId: string): Promise<void> {
try {
const channelId = await ensureDMChannel(userId);
RouterUtils.transitionTo(Routes.dmChannel(channelId));
NavigationActionCreators.selectChannel(ME, channelId);
} catch (error) {
logger.error('Failed to open DM channel:', error);
throw error;
}
};
}
export const pinDmChannel = async (channelId: string): Promise<void> => {
export async function pinDmChannel(channelId: string): Promise<void> {
try {
await http.put({
url: Endpoints.USER_CHANNEL_PIN(channelId),
@@ -105,9 +105,9 @@ export const pinDmChannel = async (channelId: string): Promise<void> => {
logger.error('Failed to pin DM channel:', error);
throw error;
}
};
}
export const unpinDmChannel = async (channelId: string): Promise<void> => {
export async function unpinDmChannel(channelId: string): Promise<void> {
try {
await http.delete({
url: Endpoints.USER_CHANNEL_PIN(channelId),
@@ -116,9 +116,9 @@ export const unpinDmChannel = async (channelId: string): Promise<void> => {
logger.error('Failed to unpin DM channel:', error);
throw error;
}
};
}
export const addRecipient = async (channelId: string, userId: string): Promise<void> => {
export async function addRecipient(channelId: string, userId: string): Promise<void> {
try {
await http.put({
url: Endpoints.CHANNEL_RECIPIENT(channelId, userId),
@@ -127,4 +127,4 @@ export const addRecipient = async (channelId: string, userId: string): Promise<v
logger.error('Failed to add recipient:', error);
throw error;
}
};
}

View File

@@ -17,109 +17,90 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import * as NavigationActionCreators from '~/actions/NavigationActionCreators';
import * as PrivateChannelActionCreators from '~/actions/PrivateChannelActionCreators';
import {FAVORITES_GUILD_ID, ME, QuickSwitcherResultTypes} from '~/Constants';
import {UserSettingsModal} from '~/components/modals/UserSettingsModal';
import {Routes} from '~/Routes';
import type {QuickSwitcherExecutableResult} from '~/stores/QuickSwitcherStore';
import QuickSwitcherStore from '~/stores/QuickSwitcherStore';
import SelectedChannelStore from '~/stores/SelectedChannelStore';
import {goToMessage, parseMessagePath} from '~/utils/MessageNavigator';
import * as RouterUtils from '~/utils/RouterUtils';
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import * as NavigationActionCreators from '@app/actions/NavigationActionCreators';
import * as PrivateChannelActionCreators from '@app/actions/PrivateChannelActionCreators';
import {UserSettingsModal} from '@app/components/modals/UserSettingsModal';
import {Routes} from '@app/Routes';
import type {QuickSwitcherExecutableResult} from '@app/stores/QuickSwitcherStore';
import QuickSwitcherStore from '@app/stores/QuickSwitcherStore';
import SelectedChannelStore from '@app/stores/SelectedChannelStore';
import {goToMessage, parseMessagePath} from '@app/utils/MessageNavigator';
import * as RouterUtils from '@app/utils/RouterUtils';
import {FAVORITES_GUILD_ID, ME} from '@fluxer/constants/src/AppConstants';
import {QuickSwitcherResultTypes} from '@fluxer/constants/src/QuickSwitcherConstants';
const QUICK_SWITCHER_MODAL_KEY = 'quick-switcher';
const QUICK_SWITCHER_MODAL_KEY = 'quick_switcher';
export const hide = (): void => {
export function hide(): void {
QuickSwitcherStore.hide();
};
}
export const search = (query: string): void => {
export function search(query: string): void {
QuickSwitcherStore.search(query);
};
}
export const select = (selectedIndex: number): void => {
export function select(selectedIndex: number): void {
QuickSwitcherStore.select(selectedIndex);
};
}
export const moveSelection = (direction: 'up' | 'down'): void => {
export function moveSelection(direction: 'up' | 'down'): void {
const nextIndex = QuickSwitcherStore.findNextSelectableIndex(direction);
select(nextIndex);
};
}
export const confirmSelection = async (): Promise<void> => {
export async function confirmSelection(): Promise<void> {
const result = QuickSwitcherStore.getSelectedResult();
if (!result) return;
await switchTo(result);
};
}
export const switchTo = async (result: QuickSwitcherExecutableResult): Promise<void> => {
export async function switchTo(result: QuickSwitcherExecutableResult): Promise<void> {
try {
switch (result.type) {
case QuickSwitcherResultTypes.USER: {
if (result.dmChannelId) {
RouterUtils.transitionTo(Routes.dmChannel(result.dmChannelId));
NavigationActionCreators.selectChannel(ME, result.dmChannelId);
} else {
await PrivateChannelActionCreators.openDMChannel(result.user.id);
}
break;
}
case QuickSwitcherResultTypes.GROUP_DM: {
RouterUtils.transitionTo(Routes.dmChannel(result.channel.id));
NavigationActionCreators.selectChannel(ME, result.channel.id);
break;
}
case QuickSwitcherResultTypes.TEXT_CHANNEL: {
if (result.viewContext === FAVORITES_GUILD_ID) {
NavigationActionCreators.selectChannel(FAVORITES_GUILD_ID, result.channel.id);
RouterUtils.transitionTo(Routes.favoritesChannel(result.channel.id));
} else if (result.guild) {
NavigationActionCreators.selectGuild(result.guild.id);
NavigationActionCreators.selectChannel(result.guild.id, result.channel.id);
RouterUtils.transitionTo(Routes.guildChannel(result.guild.id, result.channel.id));
} else {
RouterUtils.transitionTo(Routes.dmChannel(result.channel.id));
NavigationActionCreators.selectChannel(ME, result.channel.id);
}
break;
}
case QuickSwitcherResultTypes.VOICE_CHANNEL: {
if (result.viewContext === FAVORITES_GUILD_ID) {
NavigationActionCreators.selectChannel(FAVORITES_GUILD_ID, result.channel.id);
RouterUtils.transitionTo(Routes.favoritesChannel(result.channel.id));
} else if (result.guild) {
NavigationActionCreators.selectGuild(result.guild.id);
NavigationActionCreators.selectChannel(result.guild.id, result.channel.id);
RouterUtils.transitionTo(Routes.guildChannel(result.guild.id, result.channel.id));
}
break;
}
case QuickSwitcherResultTypes.GUILD: {
const channelId = SelectedChannelStore.selectedChannelIds.get(result.guild.id);
NavigationActionCreators.selectGuild(result.guild.id);
if (channelId) {
NavigationActionCreators.selectChannel(result.guild.id, channelId);
RouterUtils.transitionTo(Routes.guildChannel(result.guild.id, channelId));
} else {
RouterUtils.transitionTo(Routes.guildChannel(result.guild.id));
}
NavigationActionCreators.selectGuild(result.guild.id, channelId);
break;
}
case QuickSwitcherResultTypes.VIRTUAL_GUILD: {
if (result.virtualGuildType === 'favorites') {
const validChannelId = SelectedChannelStore.getValidatedFavoritesChannel();
if (validChannelId) {
RouterUtils.transitionTo(Routes.favoritesChannel(validChannelId));
} else {
RouterUtils.transitionTo(Routes.FAVORITES);
}
NavigationActionCreators.selectGuild(FAVORITES_GUILD_ID, validChannelId ?? undefined);
} else if (result.virtualGuildType === 'home') {
const dmChannelId = SelectedChannelStore.selectedChannelIds.get(ME);
if (dmChannelId) {
RouterUtils.transitionTo(Routes.dmChannel(dmChannelId));
} else {
RouterUtils.transitionTo(Routes.ME);
}
NavigationActionCreators.selectGuild(ME, dmChannelId);
}
break;
}
@@ -154,6 +135,8 @@ export const switchTo = async (result: QuickSwitcherExecutableResult): Promise<v
} finally {
hide();
}
};
}
export const getModalKey = (): string => QUICK_SWITCHER_MODAL_KEY;
export function getModalKey(): string {
return QUICK_SWITCHER_MODAL_KEY;
}

View File

@@ -17,31 +17,35 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import * as ToastActionCreators from '@app/actions/ToastActionCreators';
import {FeatureTemporarilyDisabledModal} from '@app/components/alerts/FeatureTemporarilyDisabledModal';
import {TooManyReactionsModal} from '@app/components/alerts/TooManyReactionsModal';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {HttpError} from '@app/lib/HttpError';
import {Logger} from '@app/lib/Logger';
import AuthenticationStore from '@app/stores/AuthenticationStore';
import GatewayConnectionStore from '@app/stores/gateway/GatewayConnectionStore';
import MessageReactionsStore from '@app/stores/MessageReactionsStore';
import MessageStore from '@app/stores/MessageStore';
import {getApiErrorCode, getApiErrorRetryAfter} from '@app/utils/ApiErrorUtils';
import type {ReactionEmoji} from '@app/utils/ReactionUtils';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import {ME} from '@fluxer/constants/src/AppConstants';
import type {UserPartial} from '@fluxer/schema/src/domains/user/UserResponseSchemas';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import * as ToastActionCreators from '~/actions/ToastActionCreators';
import {APIErrorCodes, ME} from '~/Constants';
import {FeatureTemporarilyDisabledModal} from '~/components/alerts/FeatureTemporarilyDisabledModal';
import {TooManyReactionsModal} from '~/components/alerts/TooManyReactionsModal';
import {Endpoints} from '~/Endpoints';
import http, {HttpError} from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {UserPartial} from '~/records/UserRecord';
import AuthenticationStore from '~/stores/AuthenticationStore';
import ConnectionStore from '~/stores/ConnectionStore';
import MessageReactionsStore from '~/stores/MessageReactionsStore';
import MessageStore from '~/stores/MessageStore';
import type {ReactionEmoji} from '~/utils/ReactionUtils';
const logger = new Logger('MessageReactions');
const MAX_RETRIES = 3;
const checkReactionResponse = (i18n: I18n, error: any, retry: () => void): boolean => {
const checkReactionResponse = (i18n: I18n, error: HttpError, retry: () => void): boolean => {
const errorCode = getApiErrorCode(error);
if (error.status === 403) {
const errorCode = error.body?.code as string;
if (errorCode === APIErrorCodes.FEATURE_TEMPORARILY_DISABLED) {
logger.debug('Feature temporarily disabled, not retrying');
ModalActionCreators.push(modal(() => <FeatureTemporarilyDisabledModal />));
@@ -58,14 +62,13 @@ const checkReactionResponse = (i18n: I18n, error: any, retry: () => void): boole
}
if (error.status === 429) {
const retryAfter = error.body?.retry_after || 1000;
const retryAfter = getApiErrorRetryAfter(error) || 1000;
logger.debug(`Rate limited, retrying after ${retryAfter}ms`);
setTimeout(retry, retryAfter);
return false;
}
if (error.status === 400) {
const errorCode = error.body?.code as string;
switch (errorCode) {
case APIErrorCodes.MAX_REACTIONS:
logger.debug(`Reaction limit reached: ${errorCode}`);
@@ -114,6 +117,10 @@ const optimisticUpdate = (
emoji,
optimistic: true,
});
} else if (type === 'MESSAGE_REACTION_REMOVE_ALL') {
MessageStore.handleRemoveAllReactions({channelId, messageId});
} else if (type === 'MESSAGE_REACTION_REMOVE_EMOJI') {
MessageStore.handleRemoveReactionEmoji({channelId, messageId, emoji});
}
logger.debug(
@@ -139,7 +146,7 @@ const makeUrl = ({
: Endpoints.CHANNEL_MESSAGE_REACTION(channelId, messageId, emojiCode);
};
const retryWithExponentialBackoff = async (func: () => Promise<any>, attempts = 0): Promise<any> => {
async function retryWithExponentialBackoff<T>(func: () => Promise<T>, attempts = 0): Promise<T> {
const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));
try {
@@ -160,12 +167,12 @@ const retryWithExponentialBackoff = async (func: () => Promise<any>, attempts =
logger.error(`Operation failed after ${MAX_RETRIES} attempts:`, error);
throw error;
}
};
}
const performReactionAction = (
i18n: I18n,
type: 'MESSAGE_REACTION_ADD' | 'MESSAGE_REACTION_REMOVE',
apiFunc: () => Promise<any>,
apiFunc: () => Promise<unknown>,
channelId: string,
messageId: string,
emoji: ReactionEmoji,
@@ -191,12 +198,12 @@ const performReactionAction = (
});
};
export const getReactions = async (
export async function getReactions(
channelId: string,
messageId: string,
emoji: ReactionEmoji,
limit?: number,
): Promise<Array<UserPartial>> => {
): Promise<Array<UserPartial>> {
MessageReactionsStore.handleFetchPending(messageId, emoji);
try {
@@ -205,7 +212,7 @@ export const getReactions = async (
);
const query: Record<string, number> = {};
if (limit !== undefined) query.limit = limit;
if (limit !== undefined) query['limit'] = limit;
const response = await http.get<Array<UserPartial>>({
url: makeUrl({channelId, messageId, emoji}),
@@ -221,39 +228,39 @@ export const getReactions = async (
MessageReactionsStore.handleFetchError(messageId, emoji);
throw error;
}
};
}
export const addReaction = (i18n: I18n, channelId: string, messageId: string, emoji: ReactionEmoji): void => {
export function addReaction(i18n: I18n, channelId: string, messageId: string, emoji: ReactionEmoji): void {
logger.debug(`Adding reaction ${emoji.name} to message ${messageId}`);
const apiFunc = () =>
http.put({
url: makeUrl({channelId, messageId, emoji, userId: ME}),
query: {session_id: ConnectionStore.sessionId ?? null},
query: {session_id: GatewayConnectionStore.sessionId ?? null},
});
performReactionAction(i18n, 'MESSAGE_REACTION_ADD', apiFunc, channelId, messageId, emoji);
};
}
export const removeReaction = (
export function removeReaction(
i18n: I18n,
channelId: string,
messageId: string,
emoji: ReactionEmoji,
userId?: string,
): void => {
): void {
logger.debug(`Removing reaction ${emoji.name} from message ${messageId}`);
const apiFunc = () =>
http.delete({
url: makeUrl({channelId, messageId, emoji, userId: userId || ME}),
query: {session_id: ConnectionStore.sessionId ?? null},
query: {session_id: GatewayConnectionStore.sessionId ?? null},
});
performReactionAction(i18n, 'MESSAGE_REACTION_REMOVE', apiFunc, channelId, messageId, emoji, userId);
};
}
export const removeAllReactions = (i18n: I18n, channelId: string, messageId: string): void => {
export function removeAllReactions(i18n: I18n, channelId: string, messageId: string): void {
logger.debug(`Removing all reactions from message ${messageId} in channel ${channelId}`);
const apiFunc = () =>
@@ -264,4 +271,19 @@ export const removeAllReactions = (i18n: I18n, channelId: string, messageId: str
retryWithExponentialBackoff(apiFunc).catch((error) => {
checkReactionResponse(i18n, error, () => removeAllReactions(i18n, channelId, messageId));
});
};
}
export function removeReactionEmoji(i18n: I18n, channelId: string, messageId: string, emoji: ReactionEmoji): void {
logger.debug(`Removing all ${emoji.name} reactions from message ${messageId} in channel ${channelId}`);
optimisticUpdate('MESSAGE_REACTION_REMOVE_EMOJI', channelId, messageId, emoji);
const apiFunc = () =>
http.delete({
url: makeUrl({channelId, messageId, emoji}),
});
retryWithExponentialBackoff(apiFunc).catch((error) => {
checkReactionResponse(i18n, error, () => removeReactionEmoji(i18n, channelId, messageId, emoji));
});
}

View File

@@ -17,30 +17,27 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import ChannelStore from '~/stores/ChannelStore';
import MessageStore from '~/stores/MessageStore';
import ReadStateStore from '~/stores/ReadStateStore';
import SnowflakeUtil from '~/utils/SnowflakeUtil';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import ChannelStore from '@app/stores/ChannelStore';
import MessageStore from '@app/stores/MessageStore';
import ReadStateStore from '@app/stores/ReadStateStore';
import {atPreviousMillisecond} from '@fluxer/snowflake/src/SnowflakeUtils';
const logger = new Logger('ReadStateActionCreators');
type ChannelId = string;
type MessageId = string;
export const ack = (channelId: ChannelId, immediate = false, force = false): void => {
export function ack(channelId: string, immediate = false, force = false): void {
logger.debug(`Acking channel ${channelId}, immediate=${immediate}, force=${force}`);
ReadStateStore.handleChannelAck({channelId, immediate, force});
};
}
export const ackWithStickyUnread = (channelId: ChannelId): void => {
export function ackWithStickyUnread(channelId: string): void {
logger.debug(`Acking channel ${channelId} with sticky unread preservation`);
ReadStateStore.handleChannelAckWithStickyUnread({channelId});
};
}
export const manualAck = async (channelId: ChannelId, messageId: MessageId): Promise<void> => {
export async function manualAck(channelId: string, messageId: string): Promise<void> {
try {
logger.debug(`Manual ack: ${messageId} in ${channelId}`);
const mentionCount = ReadStateStore.getManualAckMentionCount(channelId, messageId);
@@ -59,9 +56,9 @@ export const manualAck = async (channelId: ChannelId, messageId: MessageId): Pro
logger.error(`Failed to manual ack ${messageId}:`, error);
throw error;
}
};
}
export const markAsUnread = async (channelId: ChannelId, messageId: MessageId): Promise<void> => {
export async function markAsUnread(channelId: string, messageId: string): Promise<void> {
const messages = MessageStore.getMessages(channelId);
const messagesArray = messages.toArray();
const messageIndex = messagesArray.findIndex((m) => m.id === messageId);
@@ -73,8 +70,7 @@ export const markAsUnread = async (channelId: ChannelId, messageId: MessageId):
return;
}
const ackMessageId =
messageIndex > 0 ? messagesArray[messageIndex - 1].id : SnowflakeUtil.atPreviousMillisecond(messageId);
const ackMessageId = messageIndex > 0 ? messagesArray[messageIndex - 1].id : atPreviousMillisecond(messageId);
if (!ackMessageId || ackMessageId === '0') {
logger.debug('Unable to determine a previous message to ack; skipping mark-as-unread request');
@@ -83,20 +79,20 @@ export const markAsUnread = async (channelId: ChannelId, messageId: MessageId):
logger.debug(`Acking ${ackMessageId} to mark ${messageId} as unread`);
await manualAck(channelId, ackMessageId);
};
}
export const clearManualAck = (channelId: ChannelId): void => {
export function clearManualAck(channelId: string): void {
ReadStateStore.handleClearManualAck({channelId});
};
}
export const clearStickyUnread = (channelId: ChannelId): void => {
export function clearStickyUnread(channelId: string): void {
logger.debug(`Clearing sticky unread for ${channelId}`);
ReadStateStore.clearStickyUnread(channelId);
};
}
interface BulkAckEntry {
channelId: ChannelId;
messageId: MessageId;
channelId: string;
messageId: string;
}
const BULK_ACK_BATCH_SIZE = 100;
@@ -109,7 +105,7 @@ function chunkEntries<T>(entries: Array<T>, size: number): Array<Array<T>> {
return chunks;
}
function createBulkEntry(channelId: ChannelId): BulkAckEntry | null {
function createBulkEntry(channelId: string): BulkAckEntry | null {
const messageId =
ReadStateStore.lastMessageId(channelId) ?? ChannelStore.getChannel(channelId)?.lastMessageId ?? null;
@@ -144,7 +140,7 @@ function updateReadStatesLocally(entries: Array<BulkAckEntry>): void {
}
}
export async function bulkAckChannels(channelIds: Array<ChannelId>): Promise<void> {
export async function bulkAckChannels(channelIds: Array<string>): Promise<void> {
const entries = channelIds
.map((channelId) => createBulkEntry(channelId))
.filter((entry): entry is BulkAckEntry => entry != null);

View File

@@ -17,16 +17,17 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {Message} from '~/records/MessageRecord';
import type {MentionFilters} from '~/stores/RecentMentionsStore';
import RecentMentionsStore from '~/stores/RecentMentionsStore';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import type {MentionFilters} from '@app/stores/RecentMentionsStore';
import RecentMentionsStore from '@app/stores/RecentMentionsStore';
import {MAX_MESSAGES_PER_CHANNEL} from '@fluxer/constants/src/LimitConstants';
import type {Message} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';
const logger = new Logger('Mentions');
export const fetch = async (): Promise<Array<Message>> => {
export async function fetch(): Promise<Array<Message>> {
RecentMentionsStore.handleFetchPending();
try {
const filters = RecentMentionsStore.getFilters();
@@ -37,7 +38,7 @@ export const fetch = async (): Promise<Array<Message>> => {
everyone: filters.includeEveryone,
roles: filters.includeRoles,
guilds: filters.includeGuilds,
limit: 25,
limit: MAX_MESSAGES_PER_CHANNEL,
},
});
const data = response.body ?? [];
@@ -49,9 +50,9 @@ export const fetch = async (): Promise<Array<Message>> => {
logger.error('Failed to fetch recent mentions:', error);
throw error;
}
};
}
export const loadMore = async (): Promise<Array<Message>> => {
export async function loadMore(): Promise<Array<Message>> {
const recentMentions = RecentMentionsStore.recentMentions;
if (recentMentions.length === 0) {
return [];
@@ -69,7 +70,7 @@ export const loadMore = async (): Promise<Array<Message>> => {
everyone: filters.includeEveryone,
roles: filters.includeRoles,
guilds: filters.includeGuilds,
limit: 25,
limit: MAX_MESSAGES_PER_CHANNEL,
before: lastMessage.id,
},
});
@@ -82,13 +83,13 @@ export const loadMore = async (): Promise<Array<Message>> => {
logger.error('Failed to load more mentions:', error);
throw error;
}
};
}
export const updateFilters = (filters: Partial<MentionFilters>): void => {
export function updateFilters(filters: Partial<MentionFilters>): void {
RecentMentionsStore.updateFilters(filters);
};
}
export const remove = async (messageId: string): Promise<void> => {
export async function remove(messageId: string): Promise<void> {
try {
RecentMentionsStore.handleMessageDelete(messageId);
logger.debug(`Removing message ${messageId} from recent mentions`);
@@ -98,4 +99,4 @@ export const remove = async (messageId: string): Promise<void> => {
logger.error(`Failed to remove message ${messageId} from recent mentions:`, error);
throw error;
}
};
}

View File

@@ -17,63 +17,63 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {RelationshipTypes} from '~/Constants';
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import {RelationshipTypes} from '@fluxer/constants/src/UserConstants';
const logger = new Logger('RelationshipActionCreators');
export const sendFriendRequest = async (userId: string) => {
export async function sendFriendRequest(userId: string) {
try {
await http.post({url: Endpoints.USER_RELATIONSHIP(userId)});
} catch (error) {
logger.error('Failed to send friend request:', error);
throw error;
}
};
}
export const sendFriendRequestByTag = async (username: string, discriminator: string) => {
export async function sendFriendRequestByTag(username: string, discriminator: string) {
try {
await http.post({url: Endpoints.USER_RELATIONSHIPS, body: {username, discriminator}});
} catch (error) {
logger.error('Failed to send friend request by tag:', error);
throw error;
}
};
}
export const acceptFriendRequest = async (userId: string) => {
export async function acceptFriendRequest(userId: string) {
try {
await http.put({url: Endpoints.USER_RELATIONSHIP(userId)});
} catch (error) {
logger.error('Failed to accept friend request:', error);
throw error;
}
};
}
export const removeRelationship = async (userId: string) => {
export async function removeRelationship(userId: string) {
try {
await http.delete({url: Endpoints.USER_RELATIONSHIP(userId)});
} catch (error) {
logger.error('Failed to remove relationship:', error);
throw error;
}
};
}
export const blockUser = async (userId: string) => {
export async function blockUser(userId: string) {
try {
await http.put({url: Endpoints.USER_RELATIONSHIP(userId), body: {type: RelationshipTypes.BLOCKED}});
} catch (error) {
logger.error('Failed to block user:', error);
throw error;
}
};
}
export const updateFriendNickname = async (userId: string, nickname: string | null) => {
export async function updateFriendNickname(userId: string, nickname: string | null) {
try {
await http.patch({url: Endpoints.USER_RELATIONSHIP(userId), body: {nickname}});
} catch (error) {
logger.error('Failed to update friend nickname:', error);
throw error;
}
};
}

View File

@@ -17,25 +17,26 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import * as ToastActionCreators from '@app/actions/ToastActionCreators';
import {MaxBookmarksModal} from '@app/components/alerts/MaxBookmarksModal';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import {type SavedMessageEntry, SavedMessageEntryRecord} from '@app/records/SavedMessageEntryRecord';
import SavedMessagesStore from '@app/stores/SavedMessagesStore';
import {getApiErrorCode} from '@app/utils/ApiErrorUtils';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import * as ToastActionCreators from '~/actions/ToastActionCreators';
import {APIErrorCodes} from '~/Constants';
import {MaxBookmarksModal} from '~/components/alerts/MaxBookmarksModal';
import {Endpoints} from '~/Endpoints';
import http, {HttpError} from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import {SavedMessageEntryRecord, type SavedMessageEntryResponse} from '~/records/SavedMessageEntryRecord';
import SavedMessagesStore from '~/stores/SavedMessagesStore';
const logger = new Logger('SavedMessages');
export const fetch = async (): Promise<Array<SavedMessageEntryRecord>> => {
export async function fetch(): Promise<Array<SavedMessageEntryRecord>> {
try {
logger.debug('Fetching saved messages');
const response = await http.get<Array<SavedMessageEntryResponse>>({url: Endpoints.USER_SAVED_MESSAGES});
const response = await http.get<Array<SavedMessageEntry>>({url: Endpoints.USER_SAVED_MESSAGES});
const data = response.body ?? [];
const entries = data.map(SavedMessageEntryRecord.fromResponse);
SavedMessagesStore.fetchSuccess(entries);
@@ -46,9 +47,9 @@ export const fetch = async (): Promise<Array<SavedMessageEntryRecord>> => {
logger.error('Failed to fetch saved messages:', error);
throw error;
}
};
}
export const create = async (i18n: I18n, channelId: string, messageId: string): Promise<void> => {
export async function create(i18n: I18n, channelId: string, messageId: string): Promise<void> {
try {
logger.debug(`Saving message ${messageId} from channel ${channelId}`);
await http.post({url: Endpoints.USER_SAVED_MESSAGES, body: {channel_id: channelId, message_id: messageId}});
@@ -60,22 +61,16 @@ export const create = async (i18n: I18n, channelId: string, messageId: string):
} catch (error) {
logger.error(`Failed to save message ${messageId}:`, error);
if (
error instanceof HttpError &&
typeof error.body === 'object' &&
error.body != null &&
'code' in error.body &&
(error.body as {code?: string}).code === APIErrorCodes.MAX_BOOKMARKS
) {
if (getApiErrorCode(error) === APIErrorCodes.MAX_BOOKMARKS) {
ModalActionCreators.push(modal(() => <MaxBookmarksModal />));
return;
}
throw error;
}
};
}
export const remove = async (i18n: I18n, messageId: string): Promise<void> => {
export async function remove(i18n: I18n, messageId: string): Promise<void> {
try {
SavedMessagesStore.handleMessageDelete(messageId);
logger.debug(`Removing message ${messageId} from saved messages`);
@@ -89,4 +84,4 @@ export const remove = async (i18n: I18n, messageId: string): Promise<void> => {
logger.error(`Failed to remove message ${messageId} from saved messages:`, error);
throw error;
}
};
}

View File

@@ -17,46 +17,49 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
import * as DraftActionCreators from '~/actions/DraftActionCreators';
import * as MessageActionCreators from '~/actions/MessageActionCreators';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import * as SlowmodeActionCreators from '~/actions/SlowmodeActionCreators';
import * as ToastActionCreators from '~/actions/ToastActionCreators';
import {APIErrorCodes} from '~/Constants';
import {FeatureTemporarilyDisabledModal} from '~/components/alerts/FeatureTemporarilyDisabledModal';
import {FileSizeTooLargeModal} from '~/components/alerts/FileSizeTooLargeModal';
import {MessageSendFailedModal} from '~/components/alerts/MessageSendFailedModal';
import {MessageSendTooQuickModal} from '~/components/alerts/MessageSendTooQuickModal';
import {NSFWContentRejectedModal} from '~/components/alerts/NSFWContentRejectedModal';
import {SlowmodeRateLimitedModal} from '~/components/alerts/SlowmodeRateLimitedModal';
import {Endpoints} from '~/Endpoints';
import {CloudUpload} from '~/lib/CloudUpload';
import http, {type HttpError, type HttpResponse} from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {AllowedMentions} from '~/records/MessageRecord';
import {
type ScheduledAttachment,
type ScheduledMessagePayload,
ScheduledMessageRecord,
type ScheduledMessageResponse,
} from '~/records/ScheduledMessageRecord';
import ScheduledMessagesStore from '~/stores/ScheduledMessagesStore';
import {prepareAttachmentsForNonce} from '~/utils/MessageAttachmentUtils';
import * as DraftActionCreators from '@app/actions/DraftActionCreators';
import * as MessageActionCreators from '@app/actions/MessageActionCreators';
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import * as SlowmodeActionCreators from '@app/actions/SlowmodeActionCreators';
import * as ToastActionCreators from '@app/actions/ToastActionCreators';
import {FeatureTemporarilyDisabledModal} from '@app/components/alerts/FeatureTemporarilyDisabledModal';
import {FileSizeTooLargeModal} from '@app/components/alerts/FileSizeTooLargeModal';
import {MessageSendFailedModal} from '@app/components/alerts/MessageSendFailedModal';
import {MessageSendTooQuickModal} from '@app/components/alerts/MessageSendTooQuickModal';
import {NSFWContentRejectedModal} from '@app/components/alerts/NSFWContentRejectedModal';
import {SlowmodeRateLimitedModal} from '@app/components/alerts/SlowmodeRateLimitedModal';
import {Endpoints} from '@app/Endpoints';
import {CloudUpload} from '@app/lib/CloudUpload';
import http, {type HttpResponse} from '@app/lib/HttpClient';
import type {HttpError} from '@app/lib/HttpError';
import {Logger} from '@app/lib/Logger';
import type {
ScheduledAttachment,
ScheduledMessagePayload,
ScheduledMessageResponse,
} from '@app/records/ScheduledMessageRecord';
import {ScheduledMessageRecord} from '@app/records/ScheduledMessageRecord';
import ScheduledMessagesStore from '@app/stores/ScheduledMessagesStore';
import {prepareAttachmentsForNonce} from '@app/utils/MessageAttachmentUtils';
import {
type ApiAttachmentMetadata,
buildMessageCreateRequest,
type MessageCreateRequest,
type MessageReference,
type MessageStickerItem,
type NormalizedMessageContent,
normalizeMessageContent,
} from '~/utils/MessageRequestUtils';
import * as MessageSubmitUtils from '~/utils/MessageSubmitUtils';
import * as SnowflakeUtils from '~/utils/SnowflakeUtils';
import {TypingUtils} from '~/utils/TypingUtils';
} from '@app/utils/MessageRequestUtils';
import * as MessageSubmitUtils from '@app/utils/MessageSubmitUtils';
import {TypingUtils} from '@app/utils/TypingUtils';
import {APIErrorCodes} from '@fluxer/constants/src/ApiErrorCodes';
import type {
AllowedMentions,
MessageReference,
MessageStickerItem,
} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';
import * as SnowflakeUtils from '@fluxer/snowflake/src/SnowflakeUtils';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
const logger = new Logger('ScheduledMessages');
@@ -113,7 +116,7 @@ function mapScheduledAttachments(
}));
}
export const fetchScheduledMessages = async (): Promise<Array<ScheduledMessageRecord>> => {
export async function fetchScheduledMessages(): Promise<Array<ScheduledMessageRecord>> {
logger.debug('Fetching scheduled messages');
ScheduledMessagesStore.fetchStart();
@@ -131,9 +134,9 @@ export const fetchScheduledMessages = async (): Promise<Array<ScheduledMessageRe
logger.error('Failed to fetch scheduled messages:', error);
throw error;
}
};
}
export const scheduleMessage = async (i18n: I18n, params: ScheduleMessageParams): Promise<ScheduledMessageRecord> => {
export async function scheduleMessage(i18n: I18n, params: ScheduleMessageParams): Promise<ScheduledMessageRecord> {
logger.debug('Scheduling message', params);
const nonce = SnowflakeUtils.fromTimestamp(Date.now());
const normalized = normalizeMessageContent(params.content, params.favoriteMemeId);
@@ -207,12 +210,12 @@ export const scheduleMessage = async (i18n: I18n, params: ScheduleMessageParams)
);
throw error;
}
};
}
export const updateScheduledMessage = async (
export async function updateScheduledMessage(
i18n: I18n,
params: UpdateScheduledMessageParams,
): Promise<ScheduledMessageRecord> => {
): Promise<ScheduledMessageRecord> {
logger.debug('Updating scheduled message', params);
const requestBody: ScheduledMessageRequest = {
content: params.normalized.content,
@@ -257,9 +260,9 @@ export const updateScheduledMessage = async (
logger.error('Failed to update scheduled message', error);
throw error;
}
};
}
export const cancelScheduledMessage = async (i18n: I18n, scheduledMessageId: string): Promise<void> => {
export async function cancelScheduledMessage(i18n: I18n, scheduledMessageId: string): Promise<void> {
logger.debug('Canceling scheduled message', scheduledMessageId);
try {
await http.delete({url: Endpoints.USER_SCHEDULED_MESSAGE(scheduledMessageId)});
@@ -272,7 +275,7 @@ export const cancelScheduledMessage = async (i18n: I18n, scheduledMessageId: str
logger.error('Failed to cancel scheduled message', error);
throw error;
}
};
}
function restoreDraftAfterScheduleFailure(
channelId: string,

View File

@@ -17,8 +17,8 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import ChannelStickerStore from '~/stores/ChannelStickerStore';
import SlowmodeStore from '~/stores/SlowmodeStore';
import ChannelStickerStore from '@app/stores/ChannelStickerStore';
import SlowmodeStore from '@app/stores/SlowmodeStore';
export function recordMessageSend(channelId: string): void {
ChannelStickerStore.clearPendingStickerOnMessageSend(channelId);

View File

@@ -17,21 +17,21 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import SoundStore from '~/stores/SoundStore';
import type {SoundType} from '~/utils/SoundUtils';
import SoundStore from '@app/stores/SoundStore';
import type {SoundType} from '@app/utils/SoundUtils';
export const playSound = (sound: SoundType, loop = false): void => {
export function playSound(sound: SoundType, loop?: boolean): void {
SoundStore.playSound(sound, loop);
};
}
export const stopAllSounds = (): void => {
export function stopAllSounds(): void {
SoundStore.stopAllSounds();
};
}
export const updateSoundSettings = (settings: {
export function updateSoundSettings(settings: {
allSoundsDisabled?: boolean;
soundType?: SoundType;
enabled?: boolean;
}): void => {
}): void {
SoundStore.updateSettings(settings);
};
}

View File

@@ -17,8 +17,8 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {GuildStickerRecord} from '~/records/GuildStickerRecord';
import StickerPickerStore from '~/stores/StickerPickerStore';
import type {GuildStickerRecord} from '@app/records/GuildStickerRecord';
import StickerPickerStore from '@app/stores/StickerPickerStore';
function getStickerKey(sticker: GuildStickerRecord): string {
return `${sticker.guildId}:${sticker.id}`;

View File

@@ -17,11 +17,11 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ToastActionCreators from '@app/actions/ToastActionCreators';
import {Logger} from '@app/lib/Logger';
import {getElectronAPI, isDesktop} from '@app/utils/NativeUtils';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
import * as ToastActionCreators from '~/actions/ToastActionCreators';
import {Logger} from '~/lib/Logger';
import {getElectronAPI, isDesktop} from '~/utils/NativeUtils';
const logger = new Logger('Clipboard');
@@ -54,7 +54,7 @@ const writeWithFallback = async (text: string): Promise<void> => {
throw new Error('No clipboard API available');
};
export const copy = async (i18n: I18n, text: string, suppressToast = false): Promise<boolean> => {
export async function copy(i18n: I18n, text: string, suppressToast = false): Promise<boolean> {
try {
logger.debug('Copying text to clipboard');
if (!isDesktop()) {
@@ -73,4 +73,4 @@ export const copy = async (i18n: I18n, text: string, suppressToast = false): Pro
}
return false;
}
};
}

View File

@@ -17,24 +17,18 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as AccessibilityActionCreators from '@app/actions/AccessibilityActionCreators';
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import * as ToastActionCreators from '@app/actions/ToastActionCreators';
import {ThemeAcceptModal} from '@app/components/modals/ThemeAcceptModal';
import {Logger} from '@app/lib/Logger';
import type {I18n} from '@lingui/core';
import {msg} from '@lingui/core/macro';
import * as AccessibilityActionCreators from '~/actions/AccessibilityActionCreators';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import * as ToastActionCreators from '~/actions/ToastActionCreators';
import {ThemeAcceptModal} from '~/components/modals/ThemeAcceptModal';
import {Logger} from '~/lib/Logger';
import type {ThemeData} from '~/stores/ThemeStore';
import ThemeStore from '~/stores/ThemeStore';
const logger = new Logger('Themes');
export const fetchWithCoalescing = async (themeId: string): Promise<ThemeData> => {
return ThemeStore.fetchTheme(themeId);
};
export const applyTheme = (css: string, i18n: I18n): void => {
export function applyTheme(css: string, i18n: I18n): void {
try {
AccessibilityActionCreators.update({customThemeCss: css});
ToastActionCreators.success(i18n._(msg`Imported theme has been applied.`));
@@ -43,18 +37,16 @@ export const applyTheme = (css: string, i18n: I18n): void => {
ToastActionCreators.error(i18n._(msg`We couldn't apply this theme.`));
throw error;
}
};
}
export const openAcceptModal = (themeId: string | undefined, i18n: I18n): void => {
export function openAcceptModal(themeId: string | undefined, i18n: I18n): void {
if (!themeId) {
ToastActionCreators.error(i18n._(msg`This theme link is missing data.`));
return;
}
void fetchWithCoalescing(themeId).catch(() => {});
ModalActionCreators.pushWithKey(
modal(() => <ThemeAcceptModal themeId={themeId} />),
`theme-accept-${themeId}`,
);
};
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2026 Fluxer Contributors
*
* This file is part of Fluxer.
*
* Fluxer is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Fluxer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as UserSettingsActionCreators from '@app/actions/UserSettingsActionCreators';
import ThemeStore from '@app/stores/ThemeStore';
import type {ThemeType} from '@fluxer/constants/src/UserConstants';
import {ThemeTypes} from '@fluxer/constants/src/UserConstants';
export function updateThemePreference(theme: ThemeType): void {
if (theme === ThemeTypes.SYSTEM) {
ThemeStore.setSyncAcrossDevices(false);
ThemeStore.setTheme(theme);
return;
}
if (ThemeStore.syncAcrossDevices) {
void UserSettingsActionCreators.update({theme});
} else {
ThemeStore.setTheme(theme);
}
}
export function setSyncAcrossDevices(sync: boolean): void {
if (sync) {
ThemeStore.setSyncAcrossDevices(true);
} else {
ThemeStore.setSyncAcrossDevices(false);
}
}

View File

@@ -17,21 +17,21 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {ToastProps} from '~/components/uikit/Toast';
import ToastStore from '~/stores/ToastStore';
import type {ToastProps} from '@app/components/uikit/toast';
import ToastStore from '@app/stores/ToastStore';
export const createToast = (data: ToastProps): string => {
export function createToast(data: ToastProps): string {
return ToastStore.createToast(data);
};
}
export const destroyToast = (id: string): void => {
export function destroyToast(id: string): void {
ToastStore.destroyToast(id);
};
}
export const success = (message: string): string => {
export function success(message: string): string {
return ToastStore.success(message);
};
}
export const error = (message: string): string => {
export function error(message: string): string {
return ToastStore.error(message);
};
}

View File

@@ -17,12 +17,31 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Logger} from '~/lib/Logger';
import TrustedDomainStore from '~/stores/TrustedDomainStore';
import {Logger} from '@app/lib/Logger';
import TrustedDomainStore from '@app/stores/TrustedDomainStore';
const logger = new Logger('TrustedDomain');
export const addTrustedDomain = (domain: string): void => {
export async function addTrustedDomain(domain: string): Promise<void> {
logger.debug(`Adding trusted domain: ${domain}`);
TrustedDomainStore.addTrustedDomain(domain);
};
await TrustedDomainStore.addTrustedDomain(domain);
}
export async function removeTrustedDomain(domain: string): Promise<void> {
logger.debug(`Removing trusted domain: ${domain}`);
await TrustedDomainStore.removeTrustedDomain(domain);
}
export async function clearAllTrustedDomains(): Promise<void> {
logger.debug('Clearing all trusted domains');
await TrustedDomainStore.clearAllTrustedDomains();
}
export async function setTrustAllDomains(trustAll: boolean): Promise<void> {
logger.debug(`Setting trust all domains: ${trustAll}`);
await TrustedDomainStore.setTrustAllDomains(trustAll);
}
export function checkAndMigrateLegacyData(): void {
void TrustedDomainStore.checkAndMigrateLegacyData();
}

View File

@@ -17,14 +17,14 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import TypingStore from '~/stores/TypingStore';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import TypingStore from '@app/stores/TypingStore';
const logger = new Logger('Typing');
export const sendTyping = async (channelId: string): Promise<void> => {
export async function sendTyping(channelId: string): Promise<void> {
try {
logger.debug(`Sending typing indicator to channel ${channelId}`);
await http.post({url: Endpoints.CHANNEL_TYPING(channelId)});
@@ -32,14 +32,14 @@ export const sendTyping = async (channelId: string): Promise<void> => {
} catch (error) {
logger.error(`Failed to send typing indicator to channel ${channelId}:`, error);
}
};
}
export const startTyping = (channelId: string, userId: string): void => {
export function startTyping(channelId: string, userId: string): void {
logger.debug(`Starting typing indicator for user ${userId} in channel ${channelId}`);
TypingStore.startTyping(channelId, userId);
};
}
export const stopTyping = (channelId: string, userId: string): void => {
export function stopTyping(channelId: string, userId: string): void {
logger.debug(`Stopping typing indicator for user ${userId} in channel ${channelId}`);
TypingStore.stopTyping(channelId, userId);
};
}

View File

@@ -17,23 +17,23 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import UnsavedChangesStore from '~/stores/UnsavedChangesStore';
import UnsavedChangesStore from '@app/stores/UnsavedChangesStore';
export const setUnsavedChanges = (tabId: string, hasChanges: boolean): void => {
export function setUnsavedChanges(tabId: string, hasChanges: boolean): void {
UnsavedChangesStore.setUnsavedChanges(tabId, hasChanges);
};
}
export const triggerFlashEffect = (tabId: string): void => {
export function triggerFlashEffect(tabId: string): void {
UnsavedChangesStore.triggerFlash(tabId);
};
}
export const clearUnsavedChanges = (tabId: string): void => {
export function clearUnsavedChanges(tabId: string): void {
UnsavedChangesStore.clearUnsavedChanges(tabId);
};
}
export const setTabData = (
export function setTabData(
tabId: string,
data: {onReset?: () => void; onSave?: () => void; isSubmitting?: boolean},
): void => {
): void {
UnsavedChangesStore.setTabData(tabId, data);
};
}

View File

@@ -17,14 +17,16 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import MessageStore from '@app/stores/MessageStore';
import SudoStore from '@app/stores/SudoStore';
import type {SudoVerificationPayload} from '@app/types/Sudo';
import type {Message} from '@fluxer/schema/src/domains/message/MessageResponseSchemas';
import type {HarvestStatusResponse} from '@fluxer/schema/src/domains/user/UserHarvestSchemas';
import type {UserPrivate} from '@fluxer/schema/src/domains/user/UserResponseSchemas';
import type {PublicKeyCredentialCreationOptionsJSON, RegistrationResponseJSON} from '@simplewebauthn/browser';
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {Message} from '~/records/MessageRecord';
import type {UserPrivate} from '~/records/UserRecord';
import MessageStore from '~/stores/MessageStore';
import SudoStore from '~/stores/SudoStore';
const logger = new Logger('User');
@@ -66,9 +68,20 @@ interface EmailChangeVerifyNewResponse {
email_token: string;
}
export const update = async (
interface PasswordChangeStartResponse {
ticket: string;
code_expires_at: string;
resend_available_at: string | null;
}
interface PasswordChangeVerifyResponse {
verification_proof: string;
}
export async function update(
user: Partial<UserPrivate> & {
avatar?: string | null;
password?: string;
new_password?: string;
premium_badge_hidden?: boolean;
premium_badge_masked?: boolean;
@@ -79,7 +92,7 @@ export const update = async (
has_unread_gift_inventory?: boolean;
email_token?: string;
},
): Promise<UserPrivate & {token?: string}> => {
): Promise<UserPrivate & {token?: string}> {
try {
logger.debug('Updating current user profile');
const response = await http.patch<UserPrivate & {token?: string}>(Endpoints.USER_ME, user);
@@ -97,15 +110,15 @@ export const update = async (
logger.error('Failed to update user profile:', error);
throw error;
}
};
}
export const checkFluxerTagAvailability = async ({
export async function checkFluxerTagAvailability({
username,
discriminator,
}: {
username: string;
discriminator: string;
}): Promise<boolean> => {
}): Promise<boolean> {
try {
logger.debug(`Checking availability for FluxerTag ${username}#${discriminator}`);
const response = await http.get<FluxerTagAvailabilityResponse>({
@@ -117,9 +130,9 @@ export const checkFluxerTagAvailability = async ({
logger.error('Failed to check FluxerTag availability:', error);
throw error;
}
};
}
export const sendPhoneVerification = async (phone: string): Promise<void> => {
export async function sendPhoneVerification(phone: string): Promise<void> {
try {
logger.debug('Sending phone verification code');
await http.post({url: Endpoints.USER_PHONE_SEND_VERIFICATION, body: {phone}});
@@ -128,9 +141,9 @@ export const sendPhoneVerification = async (phone: string): Promise<void> => {
logger.error('Failed to send phone verification code', error);
throw error;
}
};
}
export const verifyPhone = async (phone: string, code: string): Promise<PhoneTokenResponse> => {
export async function verifyPhone(phone: string, code: string): Promise<PhoneTokenResponse> {
try {
logger.debug('Verifying phone code');
const response = await http.post<PhoneTokenResponse>(Endpoints.USER_PHONE_VERIFY, {phone, code});
@@ -140,9 +153,9 @@ export const verifyPhone = async (phone: string, code: string): Promise<PhoneTok
logger.error('Failed to verify phone code', error);
throw error;
}
};
}
export const addPhone = async (phoneToken: string): Promise<void> => {
export async function addPhone(phoneToken: string): Promise<void> {
try {
logger.debug('Adding phone to account');
await http.post({url: Endpoints.USER_PHONE, body: {phone_token: phoneToken}});
@@ -151,9 +164,9 @@ export const addPhone = async (phoneToken: string): Promise<void> => {
logger.error('Failed to add phone to account', error);
throw error;
}
};
}
export const startEmailChange = async (): Promise<EmailChangeStartResponse> => {
export async function startEmailChange(): Promise<EmailChangeStartResponse> {
try {
logger.debug('Starting email change flow');
const response = await http.post<EmailChangeStartResponse>({
@@ -165,9 +178,9 @@ export const startEmailChange = async (): Promise<EmailChangeStartResponse> => {
logger.error('Failed to start email change', error);
throw error;
}
};
}
export const resendEmailChangeOriginal = async (ticket: string): Promise<void> => {
export async function resendEmailChangeOriginal(ticket: string): Promise<void> {
try {
logger.debug('Resending email change original code');
await http.post({
@@ -178,12 +191,12 @@ export const resendEmailChangeOriginal = async (ticket: string): Promise<void> =
logger.error('Failed to resend original email code', error);
throw error;
}
};
}
export const verifyEmailChangeOriginal = async (
export async function verifyEmailChangeOriginal(
ticket: string,
code: string,
): Promise<EmailChangeVerifyOriginalResponse> => {
): Promise<EmailChangeVerifyOriginalResponse> {
try {
logger.debug('Verifying original email code');
const response = await http.post<EmailChangeVerifyOriginalResponse>({
@@ -195,13 +208,13 @@ export const verifyEmailChangeOriginal = async (
logger.error('Failed to verify original email code', error);
throw error;
}
};
}
export const requestEmailChangeNew = async (
export async function requestEmailChangeNew(
ticket: string,
newEmail: string,
originalProof: string,
): Promise<EmailChangeRequestNewResponse> => {
): Promise<EmailChangeRequestNewResponse> {
try {
logger.debug('Requesting new email code');
const response = await http.post<EmailChangeRequestNewResponse>({
@@ -213,9 +226,9 @@ export const requestEmailChangeNew = async (
logger.error('Failed to request new email code', error);
throw error;
}
};
}
export const resendEmailChangeNew = async (ticket: string): Promise<void> => {
export async function resendEmailChangeNew(ticket: string): Promise<void> {
try {
logger.debug('Resending new email code');
await http.post({
@@ -226,13 +239,13 @@ export const resendEmailChangeNew = async (ticket: string): Promise<void> => {
logger.error('Failed to resend new email code', error);
throw error;
}
};
}
export const verifyEmailChangeNew = async (
export async function verifyEmailChangeNew(
ticket: string,
code: string,
originalProof: string,
): Promise<EmailChangeVerifyNewResponse> => {
): Promise<EmailChangeVerifyNewResponse> {
try {
logger.debug('Verifying new email code');
const response = await http.post<EmailChangeVerifyNewResponse>({
@@ -244,9 +257,113 @@ export const verifyEmailChangeNew = async (
logger.error('Failed to verify new email code', error);
throw error;
}
};
}
export const removePhone = async (): Promise<void> => {
export async function requestBouncedEmailChangeNew(newEmail: string): Promise<EmailChangeRequestNewResponse> {
try {
logger.debug('Requesting bounced email replacement code');
const response = await http.post<EmailChangeRequestNewResponse>({
url: Endpoints.USER_EMAIL_CHANGE_BOUNCED_REQUEST_NEW,
body: {new_email: newEmail},
});
return response.body;
} catch (error) {
logger.error('Failed to request bounced email replacement code', error);
throw error;
}
}
export async function resendBouncedEmailChangeNew(ticket: string): Promise<void> {
try {
logger.debug('Resending bounced email replacement code');
await http.post({
url: Endpoints.USER_EMAIL_CHANGE_BOUNCED_RESEND_NEW,
body: {ticket},
});
} catch (error) {
logger.error('Failed to resend bounced email replacement code', error);
throw error;
}
}
export async function verifyBouncedEmailChangeNew(ticket: string, code: string): Promise<UserPrivate> {
try {
logger.debug('Verifying bounced email replacement code');
const response = await http.post<UserPrivate>({
url: Endpoints.USER_EMAIL_CHANGE_BOUNCED_VERIFY_NEW,
body: {ticket, code},
});
return response.body;
} catch (error) {
logger.error('Failed to verify bounced email replacement code', error);
throw error;
}
}
export async function startPasswordChange(): Promise<PasswordChangeStartResponse> {
try {
logger.debug('Starting password change flow');
const response = await http.post<PasswordChangeStartResponse>({
url: Endpoints.USER_PASSWORD_CHANGE_START,
body: {},
});
return response.body;
} catch (error) {
logger.error('Failed to start password change', error);
throw error;
}
}
export async function resendPasswordChangeCode(ticket: string): Promise<void> {
try {
logger.debug('Resending password change code');
await http.post({
url: Endpoints.USER_PASSWORD_CHANGE_RESEND,
body: {ticket},
});
} catch (error) {
logger.error('Failed to resend password change code', error);
throw error;
}
}
export async function verifyPasswordChangeCode(ticket: string, code: string): Promise<PasswordChangeVerifyResponse> {
try {
logger.debug('Verifying password change code');
const response = await http.post<PasswordChangeVerifyResponse>({
url: Endpoints.USER_PASSWORD_CHANGE_VERIFY,
body: {ticket, code},
});
return response.body;
} catch (error) {
logger.error('Failed to verify password change code', error);
throw error;
}
}
export async function completePasswordChange(
ticket: string,
verificationProof: string,
newPassword: string,
): Promise<void> {
try {
logger.debug('Completing password change');
await http.post({
url: Endpoints.USER_PASSWORD_CHANGE_COMPLETE,
body: {
ticket,
verification_proof: verificationProof,
new_password: newPassword,
},
});
logger.info('Password changed successfully');
} catch (error) {
logger.error('Failed to complete password change', error);
throw error;
}
}
export async function removePhone(): Promise<void> {
try {
logger.debug('Removing phone from account');
await http.delete({url: Endpoints.USER_PHONE, body: {}});
@@ -255,9 +372,9 @@ export const removePhone = async (): Promise<void> => {
logger.error('Failed to remove phone from account', error);
throw error;
}
};
}
export const enableSmsMfa = async (): Promise<void> => {
export async function enableSmsMfa(): Promise<void> {
try {
logger.debug('Enabling SMS MFA');
await http.post({url: Endpoints.USER_MFA_SMS_ENABLE, body: {}});
@@ -267,9 +384,9 @@ export const enableSmsMfa = async (): Promise<void> => {
logger.error('Failed to enable SMS MFA', error);
throw error;
}
};
}
export const disableSmsMfa = async (): Promise<void> => {
export async function disableSmsMfa(): Promise<void> {
try {
logger.debug('Disabling SMS MFA');
await http.post({url: Endpoints.USER_MFA_SMS_DISABLE, body: {}});
@@ -278,9 +395,9 @@ export const disableSmsMfa = async (): Promise<void> => {
logger.error('Failed to disable SMS MFA', error);
throw error;
}
};
}
export const listWebAuthnCredentials = async (): Promise<Array<WebAuthnCredential>> => {
export async function listWebAuthnCredentials(): Promise<Array<WebAuthnCredential>> {
try {
logger.debug('Fetching WebAuthn credentials');
const response = await http.get<Array<WebAuthnCredential>>({url: Endpoints.USER_MFA_WEBAUTHN_CREDENTIALS});
@@ -291,9 +408,9 @@ export const listWebAuthnCredentials = async (): Promise<Array<WebAuthnCredentia
logger.error('Failed to fetch WebAuthn credentials', error);
throw error;
}
};
}
export const getWebAuthnRegistrationOptions = async (): Promise<PublicKeyCredentialCreationOptionsJSON> => {
export async function getWebAuthnRegistrationOptions(): Promise<PublicKeyCredentialCreationOptionsJSON> {
try {
logger.debug('Getting WebAuthn registration options');
const response = await http.post<PublicKeyCredentialCreationOptionsJSON>({
@@ -307,13 +424,13 @@ export const getWebAuthnRegistrationOptions = async (): Promise<PublicKeyCredent
logger.error('Failed to get WebAuthn registration options', error);
throw error;
}
};
}
export const registerWebAuthnCredential = async (
export async function registerWebAuthnCredential(
response: RegistrationResponseJSON,
challenge: string,
name: string,
): Promise<void> => {
): Promise<void> {
try {
logger.debug('Registering WebAuthn credential');
await http.post({url: Endpoints.USER_MFA_WEBAUTHN_CREDENTIALS, body: {response, challenge, name}});
@@ -323,9 +440,9 @@ export const registerWebAuthnCredential = async (
logger.error('Failed to register WebAuthn credential', error);
throw error;
}
};
}
export const renameWebAuthnCredential = async (credentialId: string, name: string): Promise<void> => {
export async function renameWebAuthnCredential(credentialId: string, name: string): Promise<void> {
try {
logger.debug('Renaming WebAuthn credential');
await http.patch({url: Endpoints.USER_MFA_WEBAUTHN_CREDENTIAL(credentialId), body: {name}});
@@ -334,9 +451,9 @@ export const renameWebAuthnCredential = async (credentialId: string, name: strin
logger.error('Failed to rename WebAuthn credential', error);
throw error;
}
};
}
export const deleteWebAuthnCredential = async (credentialId: string): Promise<void> => {
export async function deleteWebAuthnCredential(credentialId: string): Promise<void> {
try {
logger.debug('Deleting WebAuthn credential');
await http.delete({url: Endpoints.USER_MFA_WEBAUTHN_CREDENTIAL(credentialId), body: {}});
@@ -345,9 +462,9 @@ export const deleteWebAuthnCredential = async (credentialId: string): Promise<vo
logger.error('Failed to delete WebAuthn credential', error);
throw error;
}
};
}
export const disableAccount = async (): Promise<void> => {
export async function disableAccount(): Promise<void> {
try {
logger.debug('Disabling account');
await http.post({url: Endpoints.USER_DISABLE, body: {}});
@@ -356,9 +473,9 @@ export const disableAccount = async (): Promise<void> => {
logger.error('Failed to disable account', error);
throw error;
}
};
}
export const deleteAccount = async (): Promise<void> => {
export async function deleteAccount(): Promise<void> {
try {
logger.debug('Deleting account');
await http.post({url: Endpoints.USER_DELETE, body: {}});
@@ -367,9 +484,20 @@ export const deleteAccount = async (): Promise<void> => {
logger.error('Failed to delete account', error);
throw error;
}
};
}
export const bulkDeleteAllMessages = async (): Promise<void> => {
export async function forgetAuthorizedIps(sudoPayload: SudoVerificationPayload): Promise<void> {
try {
logger.debug('Forgetting authorised IPs');
await http.delete({url: Endpoints.USER_AUTHORIZED_IPS, body: sudoPayload});
logger.info('Authorised IPs cleared');
} catch (error) {
logger.error('Failed to forget authorised IPs', error);
throw error;
}
}
export async function bulkDeleteAllMessages(): Promise<void> {
try {
logger.debug('Requesting bulk deletion of all messages');
await http.post({url: Endpoints.USER_BULK_DELETE_MESSAGES, body: {}});
@@ -378,9 +506,9 @@ export const bulkDeleteAllMessages = async (): Promise<void> => {
logger.error('Failed to queue bulk message deletion', error);
throw error;
}
};
}
export const cancelBulkDeleteAllMessages = async (): Promise<void> => {
export async function cancelBulkDeleteAllMessages(): Promise<void> {
try {
logger.debug('Cancelling bulk deletion of all messages');
await http.delete({url: Endpoints.USER_BULK_DELETE_MESSAGES, body: {}});
@@ -389,9 +517,9 @@ export const cancelBulkDeleteAllMessages = async (): Promise<void> => {
logger.error('Failed to cancel bulk message deletion', error);
throw error;
}
};
}
export const testBulkDeleteAllMessages = async (): Promise<void> => {
export async function testBulkDeleteAllMessages(): Promise<void> {
try {
logger.debug('Requesting test bulk deletion of all messages (15s delay)');
await http.post({url: Endpoints.USER_BULK_DELETE_MESSAGES_TEST});
@@ -400,9 +528,20 @@ export const testBulkDeleteAllMessages = async (): Promise<void> => {
logger.error('Failed to queue test bulk message deletion', error);
throw error;
}
};
}
export const requestDataHarvest = async (): Promise<{harvestId: string}> => {
export async function resetPremiumState(): Promise<void> {
try {
logger.debug('Resetting premium state for current user');
await http.post({url: Endpoints.USER_PREMIUM_RESET});
logger.info('Reset premium state for current user');
} catch (error) {
logger.error('Failed to reset premium state', error);
throw error;
}
}
export async function requestDataHarvest(): Promise<{harvestId: string}> {
try {
logger.debug('Requesting data harvest');
const response = await http.post<{harvest_id: string}>({url: Endpoints.USER_HARVEST});
@@ -412,33 +551,33 @@ export const requestDataHarvest = async (): Promise<{harvestId: string}> => {
logger.error('Failed to request data harvest', error);
throw error;
}
};
}
export const getLatestHarvest = async (): Promise<any> => {
export async function getLatestHarvest(): Promise<HarvestStatusResponse | null> {
try {
logger.debug('Fetching latest harvest');
const response = await http.get<any>({url: Endpoints.USER_HARVEST_LATEST});
const response = await http.get<HarvestStatusResponse | null>({url: Endpoints.USER_HARVEST_LATEST});
return response.body;
} catch (error) {
logger.error('Failed to fetch latest harvest', error);
throw error;
}
};
}
export const getHarvestStatus = async (harvestId: string): Promise<any> => {
export async function getHarvestStatus(harvestId: string): Promise<HarvestStatusResponse> {
try {
logger.debug('Fetching harvest status', {harvestId});
const response = await http.get<any>({url: Endpoints.USER_HARVEST_STATUS(harvestId)});
const response = await http.get<HarvestStatusResponse>({url: Endpoints.USER_HARVEST_STATUS(harvestId)});
return response.body;
} catch (error) {
logger.error('Failed to fetch harvest status', error);
throw error;
}
};
}
export type PreloadedDirectMessages = Record<string, Message>;
export const preloadDMMessages = async (channelIds: Array<string>): Promise<PreloadedDirectMessages> => {
export async function preloadDMMessages(channelIds: Array<string>): Promise<PreloadedDirectMessages> {
try {
logger.debug('Preloading DM messages', {channelCount: channelIds.length});
const response = await http.post<PreloadedDirectMessages>(Endpoints.USER_PRELOAD_MESSAGES, {
@@ -453,4 +592,4 @@ export const preloadDMMessages = async (channelIds: Array<string>): Promise<Prel
logger.error('Failed to preload DM messages', error);
throw error;
}
};
}

View File

@@ -17,14 +17,15 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {ME, MessageNotifications} from '~/Constants';
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {UserGuildSettingsPartial} from '~/records/UserGuildSettingsRecord';
import GuildStore from '~/stores/GuildStore';
import type {ChannelOverride, GatewayGuildSettings} from '~/stores/UserGuildSettingsStore';
import UserGuildSettingsStore from '~/stores/UserGuildSettingsStore';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import type {UserGuildSettingsPartial} from '@app/records/UserGuildSettingsRecord';
import GuildStore from '@app/stores/GuildStore';
import type {ChannelOverride, GatewayGuildSettings} from '@app/stores/UserGuildSettingsStore';
import UserGuildSettingsStore from '@app/stores/UserGuildSettingsStore';
import {ME} from '@fluxer/constants/src/AppConstants';
import {MessageNotifications} from '@fluxer/constants/src/NotificationConstants';
const logger = new Logger('UserGuildSettingsActionCreators');
@@ -108,28 +109,28 @@ const scheduleUpdate = (guildId: string | null, updates: UserGuildSettingsPartia
logger.debug(`Scheduled coalesced settings update for guild ${key} in 3 seconds`);
};
export const updateGuildSettings = (
export function updateGuildSettings(
guildId: string | null,
updates: UserGuildSettingsPartial,
options?: PersistenceOptions,
): void => {
): void {
UserGuildSettingsStore.getSettings(guildId);
UserGuildSettingsStore.updateGuildSettings(guildId, updates as Partial<GatewayGuildSettings>);
scheduleUpdate(guildId, updates, options);
};
}
export const toggleHideMutedChannels = (guildId: string | null): void => {
export function toggleHideMutedChannels(guildId: string | null): void {
const currentSettings = UserGuildSettingsStore.getSettings(guildId);
const newValue = !currentSettings.hide_muted_channels;
updateGuildSettings(guildId, {hide_muted_channels: newValue});
};
}
export const updateChannelOverride = (
export function updateChannelOverride(
guildId: string | null,
channelId: string,
override: Partial<ChannelOverride> | null,
options?: PersistenceOptions,
): void => {
): void {
const currentSettings = UserGuildSettingsStore.getSettings(guildId);
const currentOverride = UserGuildSettingsStore.getChannelOverride(guildId, channelId);
@@ -146,7 +147,7 @@ export const updateChannelOverride = (
};
}
const newChannelOverrides = {...(currentSettings.channel_overrides ?? {})};
const newChannelOverrides: Record<string, ChannelOverride> = {...(currentSettings.channel_overrides ?? {})};
if (newOverride == null) {
delete newChannelOverrides[channelId];
@@ -167,32 +168,32 @@ export const updateChannelOverride = (
},
options,
);
};
}
export const toggleChannelCollapsed = (guildId: string | null, channelId: string): void => {
export function toggleChannelCollapsed(guildId: string | null, channelId: string): void {
const isCollapsed = UserGuildSettingsStore.isChannelCollapsed(guildId, channelId);
updateChannelOverride(guildId, channelId, {collapsed: !isCollapsed});
};
}
export const updateMessageNotifications = (
export function updateMessageNotifications(
guildId: string | null,
level: number,
channelId?: string,
options?: PersistenceOptions,
): void => {
): void {
if (channelId) {
updateChannelOverride(guildId, channelId, {message_notifications: level}, options);
} else {
updateGuildSettings(guildId, {message_notifications: level}, options);
}
};
}
export const toggleChannelMuted = (guildId: string | null, channelId: string, options?: PersistenceOptions): void => {
export function toggleChannelMuted(guildId: string | null, channelId: string, options?: PersistenceOptions): void {
const isMuted = UserGuildSettingsStore.isChannelMuted(guildId, channelId);
updateChannelOverride(guildId, channelId, {muted: !isMuted}, options);
};
}
export const toggleAllCategoriesCollapsed = (guildId: string | null, categoryIds: Array<string>): void => {
export function toggleAllCategoriesCollapsed(guildId: string | null, categoryIds: Array<string>): void {
if (categoryIds.length === 0) return;
const allCollapsed = categoryIds.every((categoryId) =>
@@ -211,7 +212,7 @@ export const toggleAllCategoriesCollapsed = (guildId: string | null, categoryIds
channel_overrides: (() => {
const currentSettings = UserGuildSettingsStore.getSettings(guildId);
const newChannelOverrides = {...(currentSettings.channel_overrides ?? {})};
const newChannelOverrides: Record<string, ChannelOverride> = {...(currentSettings.channel_overrides ?? {})};
for (const categoryId of categoryIds) {
const currentOverride = UserGuildSettingsStore.getChannelOverride(guildId, categoryId);
if (newCollapsedState) {
@@ -230,9 +231,9 @@ export const toggleAllCategoriesCollapsed = (guildId: string | null, categoryIds
return Object.keys(newChannelOverrides).length > 0 ? newChannelOverrides : null;
})(),
});
};
}
export const repairGuildNotificationInheritance = (): void => {
export function repairGuildNotificationInheritance(): void {
const guildIds = UserGuildSettingsStore.getGuildIds();
if (guildIds.length === 0) return;
@@ -248,4 +249,4 @@ export const repairGuildNotificationInheritance = (): void => {
updateGuildSettings(guildId, {message_notifications: MessageNotifications.INHERIT});
}
};
}

View File

@@ -17,13 +17,13 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
const logger = new Logger('Notes');
export const update = async (userId: string, note: string | null): Promise<void> => {
export async function update(userId: string, note: string | null): Promise<void> {
try {
await http.put({url: Endpoints.USER_NOTE(userId), body: {note}});
logger.debug(`Updated note for user ${userId} to ${note ? 'new value' : 'null'}`);
@@ -31,4 +31,4 @@ export const update = async (userId: string, note: string | null): Promise<void>
logger.error(`Failed to update note for user ${userId}:`, error);
throw error;
}
};
}

View File

@@ -17,19 +17,19 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import {ME} from '~/Constants';
import {UserProfileModal} from '~/components/modals/UserProfileModal';
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import {type Profile, ProfileRecord} from '~/records/ProfileRecord';
import AuthenticationStore from '~/stores/AuthenticationStore';
import MobileLayoutStore from '~/stores/MobileLayoutStore';
import UserProfileMobileStore from '~/stores/UserProfileMobileStore';
import UserProfileStore from '~/stores/UserProfileStore';
import UserStore from '~/stores/UserStore';
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import {UserProfileModal} from '@app/components/modals/UserProfileModal';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import {type Profile, ProfileRecord} from '@app/records/ProfileRecord';
import AuthenticationStore from '@app/stores/AuthenticationStore';
import MobileLayoutStore from '@app/stores/MobileLayoutStore';
import UserProfileMobileStore from '@app/stores/UserProfileMobileStore';
import UserProfileStore from '@app/stores/UserProfileStore';
import UserStore from '@app/stores/UserStore';
import {ME} from '@fluxer/constants/src/AppConstants';
const logger = new Logger('UserProfiles');
@@ -39,7 +39,7 @@ function buildKey(userId: string, guildId?: string): string {
return `${userId}:${guildId ?? ME}`;
}
export const fetch = async (userId: string, guildId?: string, force = false): Promise<ProfileRecord> => {
export async function fetch(userId: string, guildId?: string, force = false): Promise<ProfileRecord> {
try {
const key = buildKey(userId, guildId);
@@ -98,9 +98,9 @@ export const fetch = async (userId: string, guildId?: string, force = false): Pr
logger.error(`Failed to fetch profile for user ${userId}${guildId ? ` in guild ${guildId}` : ''}:`, error);
throw error;
}
};
}
export const invalidate = (userId: string, guildId?: string): void => {
export function invalidate(userId: string, guildId?: string): void {
const scope = guildId ? ` in guild ${guildId}` : '';
logger.debug(`Invalidating cached profile for user ${userId}${scope}`);
try {
@@ -109,9 +109,9 @@ export const invalidate = (userId: string, guildId?: string): void => {
} catch (err) {
logger.warn('Failed to invalidate cached profile:', err);
}
};
}
export const clearCurrentUserProfiles = (): void => {
export function clearCurrentUserProfiles(): void {
logger.debug('Clearing cached profiles for current user');
try {
UserProfileStore.handleProfilesClear();
@@ -126,9 +126,9 @@ export const clearCurrentUserProfiles = (): void => {
} catch (err) {
logger.warn('Failed to clear current user profiles:', err);
}
};
}
export const openUserProfile = (userId: string, guildId?: string, autoFocusNote?: boolean): void => {
export function openUserProfile(userId: string, guildId?: string, autoFocusNote?: boolean): void {
if (MobileLayoutStore.enabled) {
UserProfileMobileStore.open(userId, guildId, autoFocusNote);
} else {
@@ -136,4 +136,4 @@ export const openUserProfile = (userId: string, guildId?: string, autoFocusNote?
modal(() => <UserProfileModal userId={userId} guildId={guildId} autoFocusNote={autoFocusNote} />),
);
}
};
}

View File

@@ -17,9 +17,9 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {UserSettings} from '~/stores/UserSettingsStore';
import UserSettingsStore from '~/stores/UserSettingsStore';
import type {UserSettings} from '@app/stores/UserSettingsStore';
import UserSettingsStore from '@app/stores/UserSettingsStore';
export const update = async (settings: Partial<UserSettings>): Promise<void> => {
export async function update(settings: Partial<UserSettings>): Promise<void> {
await UserSettingsStore.saveSettings(settings);
};
}

View File

@@ -17,17 +17,17 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import type {LayoutMode} from '~/stores/VoiceCallLayoutStore';
import VoiceCallLayoutStore from '~/stores/VoiceCallLayoutStore';
import type {LayoutMode, PinnedParticipantSource} from '@app/stores/VoiceCallLayoutStore';
import VoiceCallLayoutStore from '@app/stores/VoiceCallLayoutStore';
export const setLayoutMode = (mode: LayoutMode): void => {
export function setLayoutMode(mode: LayoutMode): void {
VoiceCallLayoutStore.setLayoutMode(mode);
};
}
export const setPinnedParticipant = (identity: string | null): void => {
VoiceCallLayoutStore.setPinnedParticipant(identity);
};
export function setPinnedParticipant(identity: string | null, source?: PinnedParticipantSource): void {
VoiceCallLayoutStore.setPinnedParticipant(identity, source);
}
export const markUserOverride = (): void => {
export function markUserOverride(): void {
VoiceCallLayoutStore.markUserOverride();
};
}

View File

@@ -17,9 +17,10 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import VoiceSettingsStore from '~/stores/VoiceSettingsStore';
import VoiceSettingsStore from '@app/stores/VoiceSettingsStore';
import MediaEngineStore from '@app/stores/voice/MediaEngineFacade';
export const update = (
export function update(
settings: Partial<{
inputDeviceId: string;
outputDeviceId: string;
@@ -36,8 +37,20 @@ export const update = (
backgroundImages: Array<{id: string; createdAt: number}>;
showGridView: boolean;
showMyOwnCamera: boolean;
showMyOwnScreenShare: boolean;
showNonVideoParticipants: boolean;
showParticipantsCarousel: boolean;
showVoiceConnectionAvatarStack: boolean;
showVoiceConnectionId: boolean;
pauseOwnScreenSharePreviewOnUnfocus: boolean;
disablePictureInPicturePopout: boolean;
}>,
): void => {
): void {
VoiceSettingsStore.updateSettings(settings);
};
if (settings.outputVolume !== undefined) {
MediaEngineStore.applyAllLocalAudioPreferences();
}
if (settings.inputVolume !== undefined) {
MediaEngineStore.applyLocalInputVolume();
}
}

View File

@@ -17,27 +17,27 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import * as SoundActionCreators from '@app/actions/SoundActionCreators';
import {MicrophonePermissionDeniedModal} from '@app/components/alerts/MicrophonePermissionDeniedModal';
import {Logger} from '@app/lib/Logger';
import ChannelStore from '@app/stores/ChannelStore';
import GatewayConnectionStore from '@app/stores/gateway/GatewayConnectionStore';
import LocalVoiceStateStore from '@app/stores/LocalVoiceStateStore';
import MediaPermissionStore from '@app/stores/MediaPermissionStore';
import ParticipantVolumeStore from '@app/stores/ParticipantVolumeStore';
import VoiceSettingsStore from '@app/stores/VoiceSettingsStore';
import MediaEngineStore from '@app/stores/voice/MediaEngineFacade';
import VoiceDevicePermissionStore from '@app/stores/voice/VoiceDevicePermissionStore';
import {ensureNativePermission} from '@app/utils/NativePermissions';
import {isDesktop} from '@app/utils/NativeUtils';
import {SoundType} from '@app/utils/SoundUtils';
import type {LocalTrackPublication, RemoteParticipant, Room} from 'livekit-client';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import * as SoundActionCreators from '~/actions/SoundActionCreators';
import {MicrophonePermissionDeniedModal} from '~/components/alerts/MicrophonePermissionDeniedModal';
import {Logger} from '~/lib/Logger';
import ChannelStore from '~/stores/ChannelStore';
import ConnectionStore from '~/stores/ConnectionStore';
import LocalVoiceStateStore from '~/stores/LocalVoiceStateStore';
import MediaPermissionStore from '~/stores/MediaPermissionStore';
import ParticipantVolumeStore from '~/stores/ParticipantVolumeStore';
import VoiceSettingsStore from '~/stores/VoiceSettingsStore';
import MediaEngineStore from '~/stores/voice/MediaEngineFacade';
import VoiceDevicePermissionStore from '~/stores/voice/VoiceDevicePermissionStore';
import {ensureNativePermission} from '~/utils/NativePermissions';
import {isDesktop} from '~/utils/NativeUtils';
import {SoundType} from '~/utils/SoundUtils';
const logger = new Logger('VoiceStateActionCreators');
export const toggleSelfDeaf = async (_guildId: string | null = null): Promise<void> => {
export async function toggleSelfDeaf(_guildId: string | null = null): Promise<void> {
const connectedGuildId = MediaEngineStore.guildId;
const connectedChannelId = MediaEngineStore.channelId;
@@ -80,22 +80,42 @@ export const toggleSelfDeaf = async (_guildId: string | null = null): Promise<vo
const room = MediaEngineStore.room;
if (room?.localParticipant) {
room.localParticipant.audioTrackPublications.forEach((publication: LocalTrackPublication) => {
const track = publication.track;
if (!track) return;
const operation = newMuteState ? track.mute() : track.unmute();
operation.catch((error) =>
logger.error(newMuteState ? 'Failed to mute local track' : 'Failed to unmute local track', {error}),
);
});
const hasAudioTracks = room.localParticipant.audioTrackPublications.size > 0;
if (!newMuteState && !hasAudioTracks) {
logger.info('No audio tracks found when undeafening/unmuting, enabling microphone');
const permissionGranted = await requestMicrophoneInVoiceChannel(room, connectedChannelId);
if (!permissionGranted) {
logger.warn('Failed to enable microphone, reverting to muted state');
LocalVoiceStateStore.updateSelfMute(true);
MediaEngineStore.syncLocalVoiceStateWithServer({self_mute: true, self_deaf: newDeafState});
if (!newDeafState) {
SoundActionCreators.playSound(SoundType.Undeaf);
}
return;
}
logger.info('Microphone enabled, explicitly unmuting newly created publications');
room.localParticipant.audioTrackPublications.forEach((publication: LocalTrackPublication) => {
publication.unmute().catch((error) => logger.error('Failed to unmute newly created publication', {error}));
});
} else {
room.localParticipant.audioTrackPublications.forEach((publication: LocalTrackPublication) => {
const operation = newMuteState ? publication.mute() : publication.unmute();
operation.catch((error) =>
logger.error(newMuteState ? 'Failed to mute publication' : 'Failed to unmute publication', {error}),
);
});
}
room.remoteParticipants.forEach((participant: RemoteParticipant) => {
ParticipantVolumeStore.applySettingsToParticipant(participant, newDeafState);
});
logger.debug('Applied mute/deafen state to LiveKit tracks immediately', {
logger.debug('Applied mute/deafen state to LiveKit tracks', {
newDeafState,
newMuteState,
hadAudioTracks: hasAudioTracks,
localTrackCount: room.localParticipant.audioTrackPublications.size,
remoteParticipantCount: room.remoteParticipants.size,
});
@@ -111,7 +131,7 @@ export const toggleSelfDeaf = async (_guildId: string | null = null): Promise<vo
self_mute: newMuteState,
self_deaf: newDeafState,
});
};
}
const showMicrophonePermissionDeniedModal = () => {
ModalActionCreators.push(modal(() => <MicrophonePermissionDeniedModal />));
@@ -217,7 +237,7 @@ const requestMicrophoneDirectly = async (): Promise<boolean> => {
}
};
export const toggleSelfMute = async (_guildId: string | null = null): Promise<void> => {
export async function toggleSelfMute(_guildId: string | null = null): Promise<void> {
const room = MediaEngineStore.room;
const connectedChannelId = MediaEngineStore.channelId;
@@ -285,18 +305,35 @@ export const toggleSelfMute = async (_guildId: string | null = null): Promise<vo
logger.debug('Voice state updated', {newMute, newDeaf});
if (room?.localParticipant) {
room.localParticipant.audioTrackPublications.forEach((publication: LocalTrackPublication) => {
const track = publication.track;
if (!track) return;
const operation = newMute ? track.mute() : track.unmute();
operation.catch((error) =>
logger.error(newMute ? 'Failed to mute local track' : 'Failed to unmute local track', {error}),
);
});
const hasAudioTracks = room.localParticipant.audioTrackPublications.size > 0;
logger.debug('Applied mute state to LiveKit tracks immediately', {
if (!newMute && !hasAudioTracks) {
logger.info('No audio tracks found when unmuting, enabling microphone');
const permissionGranted = await requestMicrophoneInVoiceChannel(room, connectedChannelId);
if (!permissionGranted) {
logger.warn('Failed to enable microphone, reverting to muted state');
LocalVoiceStateStore.updateSelfMute(true);
MediaEngineStore.syncLocalVoiceStateWithServer({self_mute: true, self_deaf: newDeaf});
return;
}
logger.info('Microphone enabled, explicitly unmuting newly created publications');
room.localParticipant.audioTrackPublications.forEach((publication: LocalTrackPublication) => {
publication.unmute().catch((error) => logger.error('Failed to unmute newly created publication', {error}));
});
} else {
room.localParticipant.audioTrackPublications.forEach((publication: LocalTrackPublication) => {
const operation = newMute ? publication.mute() : publication.unmute();
operation.catch((error) =>
logger.error(newMute ? 'Failed to mute publication' : 'Failed to unmute publication', {error}),
);
});
}
logger.debug('Applied mute state to LiveKit tracks', {
newMute,
newDeaf,
hadAudioTracks: hasAudioTracks,
localTrackCount: room.localParticipant.audioTrackPublications.size,
});
}
@@ -313,7 +350,7 @@ export const toggleSelfMute = async (_guildId: string | null = null): Promise<vo
self_deaf: newDeaf,
});
}
};
}
type VoiceStateProperty = 'self_mute' | 'self_deaf' | 'self_video' | 'self_stream';
@@ -325,7 +362,7 @@ const updateConnectionProperty = async (
const voiceState = MediaEngineStore.getVoiceStateByConnectionId(connectionId);
if (!voiceState) return;
const socket = ConnectionStore.socket;
const socket = GatewayConnectionStore.socket;
if (!socket) return;
socket.updateVoiceState({
@@ -344,7 +381,7 @@ const updateConnectionsProperty = async (
property: VoiceStateProperty,
value: boolean,
): Promise<void> => {
const socket = ConnectionStore.socket;
const socket = GatewayConnectionStore.socket;
if (!socket) return;
for (const connectionId of connectionIds) {
@@ -363,46 +400,46 @@ const updateConnectionsProperty = async (
}
};
export const toggleSelfMuteForConnection = async (connectionId: string): Promise<void> => {
export async function toggleSelfMuteForConnection(connectionId: string): Promise<void> {
const voiceState = MediaEngineStore.getVoiceStateByConnectionId(connectionId);
if (!voiceState) return;
const target = !voiceState.self_mute;
await updateConnectionProperty(connectionId, 'self_mute', target);
if (target) SoundActionCreators.playSound(SoundType.Mute);
else SoundActionCreators.playSound(SoundType.Unmute);
};
}
export const toggleSelfDeafenForConnection = async (connectionId: string): Promise<void> => {
export async function toggleSelfDeafenForConnection(connectionId: string): Promise<void> {
const voiceState = MediaEngineStore.getVoiceStateByConnectionId(connectionId);
if (!voiceState) return;
const target = !voiceState.self_deaf;
await updateConnectionProperty(connectionId, 'self_deaf', target);
if (target) SoundActionCreators.playSound(SoundType.Deaf);
else SoundActionCreators.playSound(SoundType.Undeaf);
};
}
export const turnOffCameraForConnection = async (connectionId: string): Promise<void> => {
export async function turnOffCameraForConnection(connectionId: string): Promise<void> {
await updateConnectionProperty(connectionId, 'self_video', false);
};
}
export const turnOffStreamForConnection = async (connectionId: string): Promise<void> => {
export async function turnOffStreamForConnection(connectionId: string): Promise<void> {
await updateConnectionProperty(connectionId, 'self_stream', false);
};
}
export const bulkMuteConnections = async (connectionIds: Array<string>, mute: boolean = true): Promise<void> => {
export async function bulkMuteConnections(connectionIds: Array<string>, mute: boolean = true): Promise<void> {
await updateConnectionsProperty(connectionIds, 'self_mute', mute);
};
}
export const bulkDeafenConnections = async (connectionIds: Array<string>, deafen: boolean = true): Promise<void> => {
export async function bulkDeafenConnections(connectionIds: Array<string>, deafen: boolean = true): Promise<void> {
await updateConnectionsProperty(connectionIds, 'self_deaf', deafen);
};
}
export const bulkTurnOffCameras = async (connectionIds: Array<string>): Promise<void> => {
export async function bulkTurnOffCameras(connectionIds: Array<string>): Promise<void> {
await updateConnectionsProperty(connectionIds, 'self_video', false);
};
}
export const bulkDisconnect = async (connectionIds: Array<string>): Promise<void> => {
const socket = ConnectionStore.socket;
export async function bulkDisconnect(connectionIds: Array<string>): Promise<void> {
const socket = GatewayConnectionStore.socket;
if (!socket) return;
for (const connectionId of connectionIds) {
@@ -419,16 +456,22 @@ export const bulkDisconnect = async (connectionIds: Array<string>): Promise<void
self_stream: false,
});
}
};
}
export const bulkMoveConnections = async (connectionIds: Array<string>, targetChannelId: string): Promise<void> => {
const socket = ConnectionStore.socket;
export async function bulkMoveConnections(connectionIds: Array<string>, targetChannelId: string): Promise<void> {
const socket = GatewayConnectionStore.socket;
if (!socket) return;
const localConnectionId = MediaEngineStore.connectionId;
for (const connectionId of connectionIds) {
const voiceState = MediaEngineStore.getVoiceStateByConnectionId(connectionId);
if (!voiceState) continue;
if (localConnectionId && connectionId === localConnectionId) {
await MediaEngineStore.connectToVoiceChannel(voiceState.guild_id ?? null, targetChannelId);
continue;
}
socket.updateVoiceState({
guild_id: voiceState.guild_id,
channel_id: targetChannelId,
@@ -439,4 +482,4 @@ export const bulkMoveConnections = async (connectionIds: Array<string>, targetCh
self_stream: voiceState.self_stream,
});
}
};
}

View File

@@ -17,11 +17,11 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {Endpoints} from '~/Endpoints';
import http from '~/lib/HttpClient';
import {Logger} from '~/lib/Logger';
import type {Webhook} from '~/records/WebhookRecord';
import WebhookStore from '~/stores/WebhookStore';
import {Endpoints} from '@app/Endpoints';
import http from '@app/lib/HttpClient';
import {Logger} from '@app/lib/Logger';
import WebhookStore from '@app/stores/WebhookStore';
import type {Webhook} from '@fluxer/schema/src/domains/webhook/WebhookSchemas';
const logger = new Logger('WebhookActionCreators');
@@ -37,7 +37,7 @@ export interface UpdateWebhookParams {
avatar?: string | null;
}
export const fetchGuildWebhooks = async (guildId: string): Promise<Array<Webhook>> => {
export async function fetchGuildWebhooks(guildId: string): Promise<Array<Webhook>> {
WebhookStore.handleGuildWebhooksFetchPending(guildId);
try {
@@ -52,15 +52,15 @@ export const fetchGuildWebhooks = async (guildId: string): Promise<Array<Webhook
WebhookStore.handleGuildWebhooksFetchError(guildId);
throw error;
}
};
}
export const fetchChannelWebhooks = async ({
export async function fetchChannelWebhooks({
guildId,
channelId,
}: {
guildId: string;
channelId: string;
}): Promise<Array<Webhook>> => {
}): Promise<Array<Webhook>> {
WebhookStore.handleChannelWebhooksFetchPending(channelId);
try {
@@ -75,9 +75,9 @@ export const fetchChannelWebhooks = async ({
WebhookStore.handleChannelWebhooksFetchError(channelId);
throw error;
}
};
}
export const createWebhook = async ({channelId, name, avatar}: CreateWebhookParams): Promise<Webhook> => {
export async function createWebhook({channelId, name, avatar}: CreateWebhookParams): Promise<Webhook> {
try {
const response = await http.post<Webhook>(Endpoints.CHANNEL_WEBHOOKS(channelId), {name, avatar: avatar ?? null});
const data = response.body;
@@ -89,9 +89,9 @@ export const createWebhook = async ({channelId, name, avatar}: CreateWebhookPara
logger.error(`Failed to create webhook for channel ${channelId}:`, error);
throw error;
}
};
}
export const deleteWebhook = async (webhookId: string): Promise<void> => {
export async function deleteWebhook(webhookId: string): Promise<void> {
const existing = WebhookStore.getWebhook(webhookId);
try {
@@ -104,9 +104,9 @@ export const deleteWebhook = async (webhookId: string): Promise<void> => {
logger.error(`Failed to delete webhook ${webhookId}:`, error);
throw error;
}
};
}
export const moveWebhook = async (webhookId: string, newChannelId: string): Promise<Webhook> => {
export async function moveWebhook(webhookId: string, newChannelId: string): Promise<Webhook> {
const existing = WebhookStore.getWebhook(webhookId);
if (!existing) {
throw new Error(`Webhook ${webhookId} not found`);
@@ -124,7 +124,7 @@ export const moveWebhook = async (webhookId: string, newChannelId: string): Prom
logger.error(`Failed to move webhook ${webhookId} to channel ${newChannelId}:`, error);
throw error;
}
};
}
const updateWebhook = async ({webhookId, name, avatar}: UpdateWebhookParams): Promise<Webhook> => {
try {
@@ -140,7 +140,7 @@ const updateWebhook = async ({webhookId, name, avatar}: UpdateWebhookParams): Pr
}
};
export const updateWebhooks = async (updates: Array<UpdateWebhookParams>): Promise<Array<Webhook>> => {
export async function updateWebhooks(updates: Array<UpdateWebhookParams>): Promise<Array<Webhook>> {
const results: Array<Webhook> = [];
for (const update of updates) {
@@ -153,4 +153,4 @@ export const updateWebhooks = async (updates: Array<UpdateWebhookParams>): Promi
}
return results;
};
}

View File

@@ -17,12 +17,12 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import GuildReadStateStore from '~/stores/GuildReadStateStore';
import IdleStore from '~/stores/IdleStore';
import NotificationStore from '~/stores/NotificationStore';
import WindowStore from '~/stores/WindowStore';
import GuildReadStateStore from '@app/stores/GuildReadStateStore';
import IdleStore from '@app/stores/IdleStore';
import NotificationStore from '@app/stores/NotificationStore';
import WindowStore from '@app/stores/WindowStore';
export const focus = (focused: boolean): void => {
export function focused(focused: boolean): void {
WindowStore.setFocused(focused);
GuildReadStateStore.handleWindowFocus();
NotificationStore.handleWindowFocus({focused});
@@ -30,12 +30,12 @@ export const focus = (focused: boolean): void => {
if (focused) {
IdleStore.recordActivity();
}
};
}
export const resized = (): void => {
export function resized(): void {
WindowStore.updateWindowSize();
};
}
export const visibilityChanged = (visible: boolean): void => {
export function visibilityChanged(visible: boolean): void {
WindowStore.setVisible(visible);
};
}

View File

@@ -17,10 +17,10 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import HttpClient from '~/lib/HttpClient';
import SessionManager from '~/lib/SessionManager';
import SudoPromptStore from '~/stores/SudoPromptStore';
import SudoStore from '~/stores/SudoStore';
import HttpClient from '@app/lib/HttpClient';
import SessionManager from '@app/lib/SessionManager';
import SudoPromptStore from '@app/stores/SudoPromptStore';
import SudoStore from '@app/stores/SudoStore';
export function setupHttpClient(): void {
HttpClient.setAuthTokenProvider(() => SessionManager.token);

View File

@@ -17,29 +17,21 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {updateDocumentTitleBadge} from '@app/hooks/useFluxerDocumentTitle';
import {Logger} from '@app/lib/Logger';
import GuildReadStateStore from '@app/stores/GuildReadStateStore';
import NotificationStore from '@app/stores/NotificationStore';
import RelationshipStore from '@app/stores/RelationshipStore';
import {getElectronAPI} from '@app/utils/NativeUtils';
import {RelationshipTypes} from '@fluxer/constants/src/UserConstants';
import Favico from 'favico.js';
import {observer} from 'mobx-react-lite';
import type React from 'react';
import {useEffect} from 'react';
import {RelationshipTypes} from '~/Constants';
import {updateDocumentTitleBadge} from '~/hooks/useFluxerDocumentTitle';
import {Logger} from '~/lib/Logger';
import GuildReadStateStore from '~/stores/GuildReadStateStore';
import NotificationStore from '~/stores/NotificationStore';
import RelationshipStore from '~/stores/RelationshipStore';
import {getElectronAPI} from '~/utils/NativeUtils';
declare global {
interface Navigator {
setAppBadge?: (contents?: number) => Promise<void>;
clearAppBadge?: () => Promise<void>;
}
}
const logger = new Logger('AppBadge');
const UNREAD_INDICATOR = -1;
type BadgeValue = number;
let favico: Favico | null = null;
@@ -55,9 +47,9 @@ const initFavico = (): Favico | null => {
}
};
const setElectronBadge = (badge: BadgeValue): void => {
const setElectronBadge = (badge: number): void => {
const electronApi = getElectronAPI();
if (!electronApi) return;
if (!electronApi?.setBadgeCount) return;
const electronBadge = badge > 0 ? badge : 0;
try {
@@ -67,7 +59,7 @@ const setElectronBadge = (badge: BadgeValue): void => {
}
};
const setFaviconBadge = (badge: BadgeValue): void => {
const setFaviconBadge = (badge: number): void => {
const fav = initFavico();
if (!fav) return;
@@ -82,7 +74,7 @@ const setFaviconBadge = (badge: BadgeValue): void => {
}
};
const setPwaBadge = (badge: BadgeValue): void => {
const setPwaBadge = (badge: number): void => {
if (!navigator.setAppBadge || !navigator.clearAppBadge) {
return;
}
@@ -100,7 +92,7 @@ const setPwaBadge = (badge: BadgeValue): void => {
}
};
const setBadge = (badge: BadgeValue): void => {
const setBadge = (badge: number): void => {
setElectronBadge(badge);
setFaviconBadge(badge);
setPwaBadge(badge);
@@ -119,7 +111,7 @@ export const AppBadge: React.FC = observer(() => {
const totalCount = mentionCount + pendingCount;
let badge: BadgeValue = 0;
let badge: number = 0;
if (totalCount > 0) {
badge = totalCount;
} else if (hasUnread && unreadMessageBadgeEnabled) {

View File

@@ -17,24 +17,27 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import styles from '@app/components/ErrorFallback.module.css';
import {FluxerIcon} from '@app/components/icons/FluxerIcon';
import {Button} from '@app/components/uikit/button/Button';
import AppStorage from '@app/lib/AppStorage';
import {Trans} from '@lingui/react/macro';
import React from 'react';
import {FluxerIcon} from '~/components/icons/FluxerIcon';
import {Button} from '~/components/uikit/Button/Button';
import AppStorage from '~/lib/AppStorage';
import styles from './ErrorFallback.module.css';
import type React from 'react';
import {useCallback} from 'react';
interface BootstrapErrorScreenProps {
error?: Error;
}
const PRESERVED_RESET_STORAGE_KEYS = ['DraftStore'] as const;
export const BootstrapErrorScreen: React.FC<BootstrapErrorScreenProps> = ({error}) => {
const handleRetry = React.useCallback(() => {
const handleRetry = useCallback(() => {
window.location.reload();
}, []);
const handleReset = React.useCallback(() => {
AppStorage.clear();
const handleReset = useCallback(() => {
AppStorage.clearExcept(PRESERVED_RESET_STORAGE_KEYS);
window.location.reload();
}, []);

View File

@@ -17,29 +17,47 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import errorFallbackStyles from '@app/components/ErrorFallback.module.css';
import {FluxerIcon} from '@app/components/icons/FluxerIcon';
import {NativeTitlebar} from '@app/components/layout/NativeTitlebar';
import {Button} from '@app/components/uikit/button/Button';
import {useNativePlatform} from '@app/hooks/useNativePlatform';
import AppStorage from '@app/lib/AppStorage';
import {Logger} from '@app/lib/Logger';
import {ensureLatestAssets} from '@app/lib/Versioning';
import GatewayConnectionStore from '@app/stores/gateway/GatewayConnectionStore';
import LayerManager from '@app/stores/LayerManager';
import MediaEngineStore from '@app/stores/voice/MediaEngineFacade';
import {Trans} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
import React from 'react';
import errorFallbackStyles from '~/components/ErrorFallback.module.css';
import {FluxerIcon} from '~/components/icons/FluxerIcon';
import {NativeTitlebar} from '~/components/layout/NativeTitlebar';
import {Button} from '~/components/uikit/Button/Button';
import {useNativePlatform} from '~/hooks/useNativePlatform';
import AppStorage from '~/lib/AppStorage';
import {ensureLatestAssets} from '~/lib/versioning';
import type React from 'react';
import {useCallback, useEffect, useState} from 'react';
interface ErrorFallbackProps {
error?: Error;
reset?: () => void;
}
const logger = new Logger('ErrorFallback');
const PRESERVED_RESET_STORAGE_KEYS = ['DraftStore'] as const;
export const ErrorFallback: React.FC<ErrorFallbackProps> = observer(() => {
const {platform, isNative, isMacOS} = useNativePlatform();
const [updateAvailable, setUpdateAvailable] = React.useState(false);
const [isUpdating, setIsUpdating] = React.useState(false);
const [checkingForUpdates, setCheckingForUpdates] = React.useState(true);
const [updateAvailable, setUpdateAvailable] = useState(false);
const [isUpdating, setIsUpdating] = useState(false);
const [checkingForUpdates, setCheckingForUpdates] = useState(true);
React.useEffect(() => {
useEffect(() => {
try {
GatewayConnectionStore.logout();
LayerManager.closeAll();
MediaEngineStore.cleanup();
} catch (error) {
logger.error('Failed to clean up runtime state on crash screen', error);
}
}, []);
useEffect(() => {
let isMounted = true;
const run = async () => {
@@ -49,7 +67,7 @@ export const ErrorFallback: React.FC<ErrorFallbackProps> = observer(() => {
setUpdateAvailable(updateFound);
}
} catch (error) {
console.error('[ErrorFallback] Failed to check for updates:', error);
logger.error('Failed to check for updates:', error);
} finally {
if (isMounted) {
setCheckingForUpdates(false);
@@ -64,7 +82,7 @@ export const ErrorFallback: React.FC<ErrorFallbackProps> = observer(() => {
};
}, []);
const handleUpdate = React.useCallback(async () => {
const handleUpdate = useCallback(async () => {
setIsUpdating(true);
try {
const {updateFound} = await ensureLatestAssets({force: true});
@@ -73,7 +91,7 @@ export const ErrorFallback: React.FC<ErrorFallbackProps> = observer(() => {
window.location.reload();
}
} catch (error) {
console.error('[ErrorFallback] Failed to apply update:', error);
logger.error('Failed to apply update:', error);
setIsUpdating(false);
}
}, []);
@@ -99,19 +117,14 @@ export const ErrorFallback: React.FC<ErrorFallbackProps> = observer(() => {
<div className={errorFallbackStyles.errorFallbackActions}>
<Button
onClick={updateAvailable ? handleUpdate : () => location.reload()}
disabled={checkingForUpdates || isUpdating}
disabled={checkingForUpdates}
submitting={isUpdating}
>
{isUpdating ? (
<Trans>Updating...</Trans>
) : checkingForUpdates || updateAvailable ? (
<Trans>Update app</Trans>
) : (
<Trans>Reload app</Trans>
)}
{checkingForUpdates || updateAvailable ? <Trans>Update app</Trans> : <Trans>Reload app</Trans>}
</Button>
<Button
onClick={() => {
AppStorage.clear();
AppStorage.clearExcept(PRESERVED_RESET_STORAGE_KEYS);
location.reload();
}}
variant="danger-primary"

View File

@@ -17,9 +17,7 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import React from 'react';
export const LONG_PRESS_DURATION_MS = 500;
import React, {useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react';
const LONG_PRESS_MOVEMENT_THRESHOLD = 10;
@@ -31,6 +29,8 @@ const MAX_VELOCITY_SAMPLE_AGE = 100;
const PRESS_HIGHLIGHT_DELAY_MS = 100;
const LONG_PRESS_DURATION_MS = 500;
const HAS_POINTER_EVENTS = 'PointerEvent' in window;
interface VelocitySample {
@@ -54,19 +54,19 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
{delay = LONG_PRESS_DURATION_MS, onLongPress, disabled, pressedClassName, onPressStateChange, ...rest},
forwardedRef,
) => {
const innerRef = React.useRef<HTMLDivElement | null>(null);
const longPressTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
const highlightTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
const pressStartPos = React.useRef<{x: number; y: number} | null>(null);
const pointerIdRef = React.useRef<number | null>(null);
const storedEvent = React.useRef<LongPressEvent | null>(null);
const velocitySamples = React.useRef<Array<VelocitySample>>([]);
const isPressIntent = React.useRef(false);
const [isPressed, setIsPressed] = React.useState(false);
const innerRef = useRef<HTMLDivElement | null>(null);
const longPressTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
const highlightTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
const pressStartPos = useRef<{x: number; y: number} | null>(null);
const pointerIdRef = useRef<number | null>(null);
const storedEvent = useRef<LongPressEvent | null>(null);
const velocitySamples = useRef<Array<VelocitySample>>([]);
const isPressIntent = useRef(false);
const [isPressed, setIsPressed] = useState(false);
React.useImperativeHandle(forwardedRef, () => innerRef.current as HTMLDivElement);
useImperativeHandle(forwardedRef, () => innerRef.current as HTMLDivElement);
const setPressed = React.useCallback(
const setPressed = useCallback(
(pressed: boolean) => {
setIsPressed(pressed);
onPressStateChange?.(pressed);
@@ -74,7 +74,7 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
[onPressStateChange],
);
const calculateVelocity = React.useCallback((): number => {
const calculateVelocity = useCallback((): number => {
const samples = velocitySamples.current;
if (samples.length < MIN_VELOCITY_SAMPLES) return 0;
@@ -94,7 +94,7 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
return distance / dt;
}, []);
const clearTimer = React.useCallback(() => {
const clearTimer = useCallback(() => {
if (longPressTimer.current) {
clearTimeout(longPressTimer.current);
longPressTimer.current = null;
@@ -129,7 +129,7 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
...restWithoutPointer
} = rest;
const startLongPressTimer = React.useCallback(
const startLongPressTimer = useCallback(
(event: LongPressEvent, x: number, y: number, pointerId?: number, capturePointer = false) => {
if (disabled || !onLongPress) return;
clearTimer();
@@ -163,7 +163,7 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
[clearTimer, delay, disabled, onLongPress, setPressed],
);
const handlePointerDown = React.useCallback(
const handlePointerDown = useCallback(
(event: React.PointerEvent<HTMLDivElement>) => {
userOnPointerDown?.(event);
if (disabled || !onLongPress || event.button !== 0) return;
@@ -173,7 +173,7 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
[disabled, onLongPress, startLongPressTimer, userOnPointerDown],
);
const handlePointerMove = React.useCallback(
const handlePointerMove = useCallback(
(event: React.PointerEvent<HTMLDivElement>) => {
userOnPointerMove?.(event);
if (pointerIdRef.current !== event.pointerId) return;
@@ -201,7 +201,7 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
[clearTimer, calculateVelocity, userOnPointerMove],
);
const handlePointerUp = React.useCallback(
const handlePointerUp = useCallback(
(event: React.PointerEvent<HTMLDivElement>) => {
if (pointerIdRef.current === event.pointerId) {
clearTimer();
@@ -211,7 +211,7 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
[clearTimer, userOnPointerUp],
);
const handlePointerCancel = React.useCallback(
const handlePointerCancel = useCallback(
(event: React.PointerEvent<HTMLDivElement>) => {
if (pointerIdRef.current === event.pointerId) {
clearTimer();
@@ -221,7 +221,7 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
[clearTimer, userOnPointerCancel],
);
const handleTouchStart = React.useCallback(
const handleTouchStart = useCallback(
(event: React.TouchEvent<HTMLDivElement>) => {
userOnTouchStart?.(event);
if (disabled || !onLongPress) return;
@@ -232,7 +232,7 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
[disabled, onLongPress, startLongPressTimer, userOnTouchStart],
);
const handleTouchMove = React.useCallback(
const handleTouchMove = useCallback(
(event: React.TouchEvent<HTMLDivElement>) => {
userOnTouchMove?.(event);
if (!pressStartPos.current) return;
@@ -260,7 +260,7 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
[clearTimer, calculateVelocity, userOnTouchMove],
);
const handleTouchEnd = React.useCallback(
const handleTouchEnd = useCallback(
(event: React.TouchEvent<HTMLDivElement>) => {
clearTimer();
userOnTouchEnd?.(event);
@@ -268,7 +268,7 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
[clearTimer, userOnTouchEnd],
);
const handleTouchCancel = React.useCallback(
const handleTouchCancel = useCallback(
(event: React.TouchEvent<HTMLDivElement>) => {
clearTimer();
userOnTouchCancel?.(event);
@@ -276,7 +276,7 @@ export const LongPressable = React.forwardRef<HTMLDivElement, LongPressableProps
[clearTimer, userOnTouchCancel],
);
React.useEffect(() => {
useEffect(() => {
const handleScroll = () => {
if (isPressIntent.current) {
clearTimer();

View File

@@ -17,14 +17,14 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import styles from '@app/components/ErrorFallback.module.css';
import {FluxerIcon} from '@app/components/icons/FluxerIcon';
import {Button} from '@app/components/uikit/button/Button';
import {Trans} from '@lingui/react/macro';
import React from 'react';
import {FluxerIcon} from '~/components/icons/FluxerIcon';
import {Button} from '~/components/uikit/Button/Button';
import styles from './ErrorFallback.module.css';
import {useCallback} from 'react';
export const NetworkErrorScreen: React.FC = () => {
const handleRetry = React.useCallback(() => {
export const NetworkErrorScreen = () => {
const handleRetry = useCallback(() => {
window.location.reload();
}, []);

View File

@@ -17,17 +17,19 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import styles from '@app/components/accounts/AccountListItem.module.css';
import {MockAvatar} from '@app/components/uikit/MockAvatar';
import type {Account} from '@app/lib/SessionManager';
import RuntimeConfigStore, {describeApiEndpoint} from '@app/stores/RuntimeConfigStore';
import * as AvatarUtils from '@app/utils/AvatarUtils';
import {getCurrentLocale} from '@app/utils/LocaleUtils';
import {formatLastActive} from '@fluxer/date_utils/src/DateFormatting';
import {Trans, useLingui} from '@lingui/react/macro';
import clsx from 'clsx';
import type {ReactNode} from 'react';
import {MockAvatar} from '~/components/uikit/MockAvatar';
import type {AccountSummary} from '~/stores/AccountManager';
import RuntimeConfigStore, {describeApiEndpoint} from '~/stores/RuntimeConfigStore';
import * as AvatarUtils from '~/utils/AvatarUtils';
import styles from './AccountListItem.module.css';
export interface AccountListItemProps {
account: AccountSummary;
interface AccountListItemProps {
account: Account;
disabled?: boolean;
isCurrent?: boolean;
onClick?: () => void;
@@ -37,7 +39,7 @@ export interface AccountListItemProps {
meta?: ReactNode;
}
export const getAccountAvatarUrl = (account: AccountSummary): string | undefined => {
export const getAccountAvatarUrl = (account: Account): string | undefined => {
const avatar = account.userData?.avatar ?? null;
try {
const mediaEndpoint = account.instance?.mediaEndpoint ?? RuntimeConfigStore.getSnapshot().mediaEndpoint;
@@ -50,11 +52,6 @@ export const getAccountAvatarUrl = (account: AccountSummary): string | undefined
}
};
export const formatLastActive = (timestamp: number): string => {
const formatter = new Intl.DateTimeFormat(undefined, {dateStyle: 'medium', timeStyle: 'short'});
return formatter.format(new Date(timestamp));
};
export const AccountListItem = ({
account,
disabled = false,
@@ -75,7 +72,7 @@ export const AccountListItem = ({
isCurrent ? (
(account.userData?.email ?? t`Email unavailable`)
) : (
<Trans>Last active {formatLastActive(account.lastActive)}</Trans>
<Trans>Last active {formatLastActive(account.lastActive, getCurrentLocale())}</Trans>
)
) : (
(account.userData?.email ?? t`Email unavailable`)

View File

@@ -127,6 +127,11 @@ button.clickable:active {
background: var(--background-modifier-hover);
}
.menuButtonActive {
color: var(--text-primary);
background: var(--background-modifier-hover);
}
.menuIcon {
width: 20px;
height: 20px;

View File

@@ -17,21 +17,26 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {getAccountAvatarUrl} from '@app/components/accounts/AccountListItem';
import styles from '@app/components/accounts/AccountRow.module.css';
import FocusRing from '@app/components/uikit/focus_ring/FocusRing';
import {MockAvatar} from '@app/components/uikit/MockAvatar';
import {Tooltip} from '@app/components/uikit/tooltip/Tooltip';
import {useContextMenuHoverState} from '@app/hooks/useContextMenuHoverState';
import {Logger} from '@app/lib/Logger';
import type {Account} from '@app/lib/SessionManager';
import {Trans, useLingui} from '@lingui/react/macro';
import {CaretRightIcon, CheckIcon, DotsThreeIcon, GlobeIcon} from '@phosphor-icons/react';
import clsx from 'clsx';
import {observer} from 'mobx-react-lite';
import React from 'react';
import FocusRing from '~/components/uikit/FocusRing/FocusRing';
import {MockAvatar} from '~/components/uikit/MockAvatar';
import {Tooltip} from '~/components/uikit/Tooltip';
import type {AccountSummary} from '~/stores/AccountManager';
import {getAccountAvatarUrl} from './AccountListItem';
import styles from './AccountRow.module.css';
import type React from 'react';
import {useCallback, useRef} from 'react';
const STANDARD_INSTANCES = new Set(['web.fluxer.app', 'web.canary.fluxer.app']);
function getInstanceHost(account: AccountSummary): string | null {
const logger = new Logger('AccountRow');
function getInstanceHost(account: Account): string | null {
const endpoint = account.instance?.apiEndpoint;
if (!endpoint) {
return null;
@@ -40,19 +45,19 @@ function getInstanceHost(account: AccountSummary): string | null {
try {
return new URL(endpoint).hostname;
} catch (error) {
console.error('Failed to parse instance host:', error);
logger.error('Failed to parse instance host:', error);
return null;
}
}
function getInstanceEndpoint(account: AccountSummary): string | null {
function getInstanceEndpoint(account: Account): string | null {
return account.instance?.apiEndpoint ?? null;
}
type AccountRowVariant = 'default' | 'manage' | 'compact';
interface AccountRowProps {
account: AccountSummary;
account: Account;
variant?: AccountRowVariant;
isCurrent?: boolean;
isExpired?: boolean;
@@ -84,8 +89,10 @@ export const AccountRow = observer(
const instanceHost = showInstance ? getInstanceHost(account) : null;
const instanceEndpoint = showInstance ? getInstanceEndpoint(account) : null;
const shouldShowInstance = typeof instanceHost === 'string' && !STANDARD_INSTANCES.has(instanceHost);
const menuButtonRef = useRef<HTMLButtonElement | null>(null);
const isContextMenuOpen = useContextMenuHoverState(menuButtonRef, Boolean(onMenuClick));
const handleMenuClick = React.useCallback(
const handleMenuClick = useCallback(
(event: React.MouseEvent<HTMLButtonElement>) => {
event.stopPropagation();
event.preventDefault();
@@ -175,7 +182,13 @@ export const AccountRow = observer(
) : null}
{onMenuClick && variant !== 'compact' && !showCaretIndicator ? (
<FocusRing offset={-2}>
<button type="button" className={styles.menuButton} onClick={handleMenuClick} aria-label={t`More`}>
<button
ref={menuButtonRef}
type="button"
className={clsx(styles.menuButton, isContextMenuOpen && styles.menuButtonActive)}
onClick={handleMenuClick}
aria-label={t`More`}
>
<DotsThreeIcon size={20} weight="bold" className={styles.menuIcon} />
</button>
</FocusRing>

View File

@@ -17,25 +17,28 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import * as ContextMenuActionCreators from '@app/actions/ContextMenuActionCreators';
import * as ModalActionCreators from '@app/actions/ModalActionCreators';
import {modal} from '@app/actions/ModalActionCreators';
import * as ToastActionCreators from '@app/actions/ToastActionCreators';
import {AccountRow} from '@app/components/accounts/AccountRow';
import styles from '@app/components/accounts/AccountSelector.module.css';
import {ConfirmModal} from '@app/components/modals/ConfirmModal';
import {Button} from '@app/components/uikit/button/Button';
import {MenuGroup} from '@app/components/uikit/context_menu/MenuGroup';
import {MenuItem} from '@app/components/uikit/context_menu/MenuItem';
import {Scroller} from '@app/components/uikit/Scroller';
import {Logger} from '@app/lib/Logger';
import type {Account} from '@app/lib/SessionManager';
import AccountManager from '@app/stores/AccountManager';
import {Trans, useLingui} from '@lingui/react/macro';
import {PlusIcon, SignOutIcon} from '@phosphor-icons/react';
import {observer} from 'mobx-react-lite';
import React from 'react';
import * as ContextMenuActionCreators from '~/actions/ContextMenuActionCreators';
import * as ModalActionCreators from '~/actions/ModalActionCreators';
import {modal} from '~/actions/ModalActionCreators';
import * as ToastActionCreators from '~/actions/ToastActionCreators';
import {ConfirmModal} from '~/components/modals/ConfirmModal';
import {Button} from '~/components/uikit/Button/Button';
import {MenuGroup} from '~/components/uikit/ContextMenu/MenuGroup';
import {MenuItem} from '~/components/uikit/ContextMenu/MenuItem';
import {Scroller} from '~/components/uikit/Scroller';
import AccountManager, {type AccountSummary} from '~/stores/AccountManager';
import {AccountRow} from './AccountRow';
import styles from './AccountSelector.module.css';
import type React from 'react';
import {useCallback} from 'react';
interface AccountSelectorProps {
accounts: Array<AccountSummary>;
accounts: Array<Account>;
currentAccountId?: string | null;
title?: React.ReactNode;
description?: React.ReactNode;
@@ -44,11 +47,13 @@ interface AccountSelectorProps {
showInstance?: boolean;
clickableRows?: boolean;
addButtonLabel?: React.ReactNode;
onSelectAccount: (account: AccountSummary) => void;
onSelectAccount: (account: Account) => void;
onAddAccount?: () => void;
scrollerKey?: string;
}
const logger = new Logger('AccountSelector');
export const AccountSelector = observer(
({
accounts,
@@ -69,8 +74,8 @@ export const AccountSelector = observer(
const defaultDescription = <Trans>Select an account to continue, or add a different one.</Trans>;
const hasMultipleAccounts = accounts.length > 1;
const openSignOutConfirm = React.useCallback(
(account: AccountSummary) => {
const openSignOutConfirm = useCallback(
(account: Account) => {
const displayName = account.userData?.username ?? account.userId;
ModalActionCreators.push(
@@ -90,7 +95,7 @@ export const AccountSelector = observer(
try {
await AccountManager.removeStoredAccount(account.userId);
} catch (error) {
console.error('Failed to remove account', error);
logger.error('Failed to remove account', error);
ToastActionCreators.error(t`We couldn't remove that account. Please try again.`);
}
}}
@@ -101,8 +106,8 @@ export const AccountSelector = observer(
[hasMultipleAccounts, t],
);
const openMenu = React.useCallback(
(account: AccountSummary) => (event: React.MouseEvent<HTMLButtonElement>) => {
const openMenu = useCallback(
(account: Account) => (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
event.stopPropagation();
ContextMenuActionCreators.openFromEvent(event, (props) => (

View File

@@ -17,17 +17,18 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {AccountRow} from '@app/components/accounts/AccountRow';
import styles from '@app/components/accounts/AccountSwitcherModal.module.css';
import * as Modal from '@app/components/modals/Modal';
import {Button} from '@app/components/uikit/button/Button';
import {Scroller} from '@app/components/uikit/Scroller';
import {Spinner} from '@app/components/uikit/Spinner';
import {openAccountContextMenu, useAccountSwitcherLogic} from '@app/utils/accounts/AccountSwitcherModalUtils';
import {Trans} from '@lingui/react/macro';
import {PlusIcon} from '@phosphor-icons/react';
import {observer} from 'mobx-react-lite';
import React from 'react';
import * as Modal from '~/components/modals/Modal';
import {Button} from '~/components/uikit/Button/Button';
import {Scroller} from '~/components/uikit/Scroller';
import {Spinner} from '~/components/uikit/Spinner';
import {openAccountContextMenu, useAccountSwitcherLogic} from '~/utils/accounts/AccountSwitcherModalUtils';
import {AccountRow} from './AccountRow';
import styles from './AccountSwitcherModal.module.css';
import type React from 'react';
import {useCallback} from 'react';
const AccountSwitcherModal = observer(() => {
const {
@@ -38,12 +39,12 @@ const AccountSwitcherModal = observer(() => {
handleReLogin,
handleAddAccount,
handleLogout,
handleRemoveAccount,
handleLogoutStoredAccount,
} = useAccountSwitcherLogic();
const hasMultipleAccounts = accounts.length > 1;
const openMenu = React.useCallback(
const openMenu = useCallback(
(account: (typeof accounts)[number]) => (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
event.stopPropagation();
@@ -55,7 +56,7 @@ const AccountSwitcherModal = observer(() => {
onSwitch: handleSwitchAccount,
onReLogin: handleReLogin,
onLogout: handleLogout,
onRemoveAccount: handleRemoveAccount,
onLogoutStoredAccount: handleLogoutStoredAccount,
});
},
[
@@ -64,7 +65,7 @@ const AccountSwitcherModal = observer(() => {
handleSwitchAccount,
handleReLogin,
handleLogout,
handleRemoveAccount,
handleLogoutStoredAccount,
],
);

View File

@@ -17,9 +17,9 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {GenericErrorModal} from '@app/components/alerts/GenericErrorModal';
import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
import {GenericErrorModal} from './GenericErrorModal';
export const CallNotRingableModal = observer(() => {
const {t} = useLingui();

View File

@@ -17,11 +17,11 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {ConfirmModal} from '@app/components/modals/ConfirmModal';
import {openNativePermissionSettings} from '@app/utils/NativePermissions';
import {isDesktop, isNativeMacOS} from '@app/utils/NativeUtils';
import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
import {ConfirmModal} from '~/components/modals/ConfirmModal';
import {openNativePermissionSettings} from '~/utils/NativePermissions';
import {isDesktop, isNativeMacOS} from '~/utils/NativeUtils';
export const CameraPermissionDeniedModal = observer(() => {
const {t} = useLingui();

View File

@@ -17,16 +17,16 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {GenericErrorModal} from '@app/components/alerts/GenericErrorModal';
import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
import {GenericErrorModal} from './GenericErrorModal';
export const ChannelPermissionsUpdateFailedModal = observer(() => {
const {t} = useLingui();
return (
<GenericErrorModal
title={t`Failed to update channel permissions`}
title={t`Failed to Update Channel Permissions`}
message={t`We couldn't save your channel permission changes at this time.`}
/>
);

View File

@@ -17,14 +17,14 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {GenericErrorModal} from '@app/components/alerts/GenericErrorModal';
import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
import {GenericErrorModal} from './GenericErrorModal';
export const DMCloseFailedModal = observer(() => {
const {t} = useLingui();
return (
<GenericErrorModal title={t`Failed to close DM`} message={t`We couldn't close the direct message at this time.`} />
<GenericErrorModal title={t`Failed to Close DM`} message={t`We couldn't close the direct message at this time.`} />
);
});

View File

@@ -17,9 +17,9 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {ConfirmModal} from '@app/components/modals/ConfirmModal';
import {useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
import {ConfirmModal} from '~/components/modals/ConfirmModal';
export const FeatureTemporarilyDisabledModal = observer(() => {
const {t} = useLingui();

View File

@@ -17,22 +17,54 @@
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
*/
import {useLingui} from '@lingui/react/macro';
import * as PremiumModalActionCreators from '@app/actions/PremiumModalActionCreators';
import {ConfirmModal} from '@app/components/modals/ConfirmModal';
import UserStore from '@app/stores/UserStore';
import {formatFileSize} from '@app/utils/FileUtils';
import {Limits} from '@app/utils/limits/UserLimits';
import {shouldShowPremiumFeatures} from '@app/utils/PremiumUtils';
import {ATTACHMENT_MAX_SIZE_PREMIUM} from '@fluxer/constants/src/LimitConstants';
import {Trans, useLingui} from '@lingui/react/macro';
import {observer} from 'mobx-react-lite';
import * as PremiumModalActionCreators from '~/actions/PremiumModalActionCreators';
import {ConfirmModal} from '~/components/modals/ConfirmModal';
import UserStore from '~/stores/UserStore';
import {useCallback} from 'react';
export const FileSizeTooLargeModal = observer(() => {
interface FileSizeTooLargeModalProps {
oversizedFileCount?: number;
}
export const FileSizeTooLargeModal = observer(({oversizedFileCount}: FileSizeTooLargeModalProps) => {
const {t} = useLingui();
const user = UserStore.currentUser;
const hasPremium = user?.isPremium() ?? false;
const showPremium = shouldShowPremiumFeatures();
const maxAttachmentFileSize = user?.maxAttachmentFileSize ?? 25 * 1024 * 1024;
const premiumMaxAttachmentFileSize = Limits.getPremiumValue('max_attachment_file_size', ATTACHMENT_MAX_SIZE_PREMIUM);
const canUpgradeAttachmentLimit = maxAttachmentFileSize < premiumMaxAttachmentFileSize;
const maxSizeFormatted = formatFileSize(maxAttachmentFileSize);
const hasKnownOversizedFileCount = oversizedFileCount != null;
const hasMultipleOversizedFiles = (oversizedFileCount ?? 0) > 1;
const handleGetPlutoniumClick = useCallback(() => {
window.setTimeout(() => {
PremiumModalActionCreators.open();
}, 0);
}, []);
if (hasPremium) {
const baseDescription = hasKnownOversizedFileCount
? hasMultipleOversizedFiles
? t`Some files you're trying to upload exceed the maximum size limit of ${maxSizeFormatted} per file.`
: t`The file you're trying to upload exceeds the maximum size limit of ${maxSizeFormatted}.`
: t`One or more files you're trying to upload exceed the maximum size limit of ${maxSizeFormatted} per file.`;
if (!showPremium || !canUpgradeAttachmentLimit) {
return (
<ConfirmModal
title={t`File size too large`}
description={t`The file you're trying to upload exceeds the maximum size limit of 500 MB for Plutonium subscribers.`}
description={
!showPremium ? (
<Trans>{baseDescription} This limit is configured by your instance administrator.</Trans>
) : (
baseDescription
)
}
primaryText={t`Understood`}
onPrimary={() => {}}
/>
@@ -41,11 +73,17 @@ export const FileSizeTooLargeModal = observer(() => {
return (
<ConfirmModal
title={t`File Size Limit Exceeded`}
description={t`The file you're trying to upload exceeds the maximum size limit of 25 MB for non-subscribers. With Plutonium, you can upload files up to 500 MB, use animated avatars and banners, write longer bios, and unlock many other premium features.`}
title={t`File size limit exceeded`}
description={
<Trans>
{baseDescription} With Plutonium, your per-file upload limit increases to{' '}
{formatFileSize(premiumMaxAttachmentFileSize)}, plus animated avatars, longer messages, and many other premium
features.
</Trans>
}
primaryText={t`Get Plutonium`}
primaryVariant="primary"
onPrimary={() => PremiumModalActionCreators.open()}
onPrimary={handleGetPlutoniumClick}
secondaryText={t`Cancel`}
/>
);

Some files were not shown because too many files have changed in this diff Show More